Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jmcagent): add API handlers for JMC agent plugin #731

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b0e248f
Adding agent plugin template management handlers
Josh-Matsuoka Sep 21, 2021
6c64b76
Adding probe directory creation to the launch script
Josh-Matsuoka Sep 21, 2021
929313e
Resolving merge conflicts
Josh-Matsuoka Sep 21, 2021
ac6af63
Fixing missing lisence header, adding resourceActions
Josh-Matsuoka Sep 23, 2021
f664838
Adding Tests, moving handlers to beta handlers, cleanup
Josh-Matsuoka Oct 5, 2021
fce1b09
Adding agent handlers, adjusting run script
Josh-Matsuoka Oct 19, 2021
0f6fec6
Cleanup, adding tests
Josh-Matsuoka Nov 2, 2021
d2ee20d
Fixing HttpApiBetaModule
Josh-Matsuoka Nov 2, 2021
4d1faca
Cleanup, enforcing file upload name for ProbeTemplateUploadHandler
Josh-Matsuoka Nov 9, 2021
aec0f82
Rebasing after core changes, cleanup
Josh-Matsuoka Nov 15, 2021
1daed60
Syncing with upstream
Josh-Matsuoka Nov 15, 2021
e871588
Resolving merge conflicts
Josh-Matsuoka Nov 17, 2021
55ad6a4
bumping core pom version
Josh-Matsuoka Nov 17, 2021
1118788
Merge remote-tracking branch 'upstream/main' into agent-plugin-agent-…
Josh-Matsuoka Nov 24, 2021
b175f8f
Fixing run script and integration test setup
Josh-Matsuoka Dec 6, 2021
8c89ff6
fixing core version
Josh-Matsuoka Dec 7, 2021
07c60a2
fixing spotbugs issues
Josh-Matsuoka Dec 7, 2021
b26043c
running spotless
Josh-Matsuoka Dec 8, 2021
706b2fc
Merge remote-tracking branch 'upstream/main' into agent-plugin-agent-…
Josh-Matsuoka Dec 8, 2021
b6e956e
running spotless
Josh-Matsuoka Dec 10, 2021
21d704c
Merge branch 'main' into agent-plugin-agent-handlers
andrewazores Dec 10, 2021
6ec17c3
Merge branch 'main' into agent-plugin-agent-handlers
andrewazores Dec 10, 2021
bc7b487
Fixing pom.xml and template module sanity checks
Josh-Matsuoka Dec 10, 2021
4341e57
Merge remote-tracking branch 'upstream/main' into agent-plugin-agent-…
Josh-Matsuoka Dec 10, 2021
18a7942
Merge branch 'agent-plugin-agent-handlers' of github.com:Josh-Matsuok…
Josh-Matsuoka Dec 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ podman run \
--pod cryostat \
--mount type=tmpfs,target=/opt/cryostat.d/recordings.d \
--mount type=tmpfs,target=/opt/cryostat.d/templates.d \
--mount type=bind,source="$(dirname $0)/conf",destination=/opt/cryostat.d/conf.d,relabel=shared,bind-propagation=shared \
--mount type=tmpfs,target=/opt/cryostat.d/probes.d \
--mount type=tmpfs,target=/opt/cryostat.d/conf.d \
--mount type=bind,source="$(dirname $0)/truststore",destination=/truststore,relabel=shared,bind-propagation=shared \
--mount type=bind,source="$(dirname $0)/certs",destination=/certs,relabel=shared,bind-propagation=shared \
--mount type=bind,source="$(dirname $0)/clientlib",destination=/clientlib,relabel=shared,bind-propagation=shared \
-e CRYOSTAT_PLATFORM=$CRYOSTAT_PLATFORM \
-e CRYOSTAT_DISABLE_SSL=$CRYOSTAT_DISABLE_SSL \
-e CRYOSTAT_DISABLE_JMX_AUTH=$CRYOSTAT_DISABLE_JMX_AUTH \
-e CRYOSTAT_DISABLE_SSL="true" \
-e CRYOSTAT_DISABLE_JMX_AUTH="true" \
-e CRYOSTAT_RJMX_USER=$CRYOSTAT_RJMX_USER \
-e CRYOSTAT_RJMX_PASS=$CRYOSTAT_RJMX_PASS \
-e CRYOSTAT_RJMX_PORT=$CRYOSTAT_RJMX_PORT \
Expand All @@ -93,7 +96,9 @@ podman run \
-e CRYOSTAT_CONFIG_PATH="/opt/cryostat.d/conf.d" \
-e CRYOSTAT_ARCHIVE_PATH="/opt/cryostat.d/recordings.d" \
-e CRYOSTAT_TEMPLATE_PATH="/opt/cryostat.d/templates.d" \
-e CRYOSTAT_PROBE_TEMPLATE_PATH="/opt/cryostat.d/probes.d" \
-e CRYOSTAT_CLIENTLIB_PATH="/clientlib" \
-e CRYOSTAT_AGENT_PATH="/clientlib/agent-1.0.1.jar" \
-e CRYOSTAT_REPORT_GENERATION_MAX_HEAP="$CRYOSTAT_REPORT_GENERATION_MAX_HEAP" \
-e GRAFANA_DATASOURCE_URL=$GRAFANA_DATASOURCE_URL \
-e GRAFANA_DASHBOARD_URL=$GRAFANA_DASHBOARD_URL \
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/cryostat/net/security/ResourceAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public enum ResourceAction {
UPDATE_TEMPLATE(UPDATE, TEMPLATE),
DELETE_TEMPLATE(DELETE, TEMPLATE),

CREATE_PROBE_TEMPLATE(CREATE, TEMPLATE),
DELETE_PROBE_TEMPLATE(DELETE, TEMPLATE),

CREATE_REPORT(CREATE, REPORT),
READ_REPORT(READ, REPORT),
UPDATE_REPORT(UPDATE, REPORT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,29 @@ public abstract class HttpApiBetaModule {
@Binds
@IntoSet
abstract RequestHandler bindDiscoveryGetHandler(DiscoveryGetHandler handler);

@Binds
@IntoSet
abstract RequestHandler bindProbeTemplateUploadHandler(ProbeTemplateUploadHandler handler);

@Binds
@IntoSet
abstract RequestHandler bindProbeTemplateUploadBodyHandler(
ProbeTemplateUploadBodyHandler handler);

@Binds
@IntoSet
abstract RequestHandler bindProbeTemplateDeleteHandler(ProbeTemplateDeleteHandler handler);

@Binds
@IntoSet
abstract RequestHandler bindTargetProbePostHandler(TargetProbePostHandler handler);

@Binds
@IntoSet
abstract RequestHandler bindTargetProbeDeleteHandler(TargetProbePostHandler handler);
Josh-Matsuoka marked this conversation as resolved.
Show resolved Hide resolved

@Binds
@IntoSet
abstract RequestHandler bindTargetProbesGetHandler(TargetProbePostHandler handler);
Josh-Matsuoka marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright The Cryostat Authors
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.cryostat.net.web.http.api.beta;

import java.util.EnumSet;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;

import io.cryostat.core.agent.LocalProbeTemplateService;
import io.cryostat.core.log.Logger;
import io.cryostat.core.sys.FileSystem;
import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.AuthManager;
import io.cryostat.net.security.ResourceAction;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.api.ApiVersion;
import io.cryostat.net.web.http.api.v2.AbstractV2RequestHandler;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;

import com.google.gson.Gson;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.handler.impl.HttpStatusException;

public class ProbeTemplateDeleteHandler extends AbstractV2RequestHandler<Void> {

static final String PATH = "probes/:probetemplateName";

private static Logger logger;
private final NotificationFactory notificationFactory;
private final LocalProbeTemplateService probeTemplateService;
private final FileSystem fs;
private static final String NOTIFICATION_CATEGORY = "ProbeTemplateUploaded";

@Inject
ProbeTemplateDeleteHandler(
AuthManager auth,
NotificationFactory notificationFactory,
LocalProbeTemplateService probeTemplateService,
Logger logger,
FileSystem fs,
Gson gson) {
super(auth, gson);
this.notificationFactory = notificationFactory;
this.logger = logger;
this.probeTemplateService = probeTemplateService;
this.fs = fs;
}

@Override
public ApiVersion apiVersion() {
return ApiVersion.V2;
}

@Override
public HttpMethod httpMethod() {
return HttpMethod.DELETE;
}

@Override
public String path() {
return basePath() + PATH;
}

@Override
public boolean isAsync() {
return false;
}

@Override
public boolean isOrdered() {
return true;
}

@Override
public boolean requiresAuthentication() {
return false;
Josh-Matsuoka marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public IntermediateResponse<Void> handle(RequestParameters params) throws Exception {
String probeTemplateName = params.getPathParams().get("probetemplateName");
try {
this.probeTemplateService.deleteTemplate(probeTemplateName);
notificationFactory
.createBuilder()
.metaCategory(NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(Map.of("probeTemplate", probeTemplateName))
.build()
.send();
} catch (Exception e) {
throw new HttpStatusException(400, e.getMessage(), e);
}
return new IntermediateResponse().body(null);
}

@Override
public Set<ResourceAction> resourceActions() {
return EnumSet.of(ResourceAction.DELETE_PROBE_TEMPLATE);
}

@Override
public HttpMimeType mimeType() {
return HttpMimeType.PLAINTEXT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright The Cryostat Authors
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.cryostat.net.web.http.api.beta;

import java.util.Set;

import javax.inject.Inject;

import io.cryostat.net.AuthManager;
import io.cryostat.net.security.ResourceAction;
import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler;
import io.cryostat.net.web.http.api.ApiVersion;

import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;

public class ProbeTemplateUploadBodyHandler extends AbstractAuthenticatedRequestHandler {

static final BodyHandler BODY_HANDLER = BodyHandler.create(true);

@Inject
ProbeTemplateUploadBodyHandler(AuthManager auth) {
super(auth);
}

@Override
public ApiVersion apiVersion() {
return ApiVersion.V2;
}

@Override
public int getPriority() {
return DEFAULT_PRIORITY - 1;
}

@Override
public HttpMethod httpMethod() {
return HttpMethod.POST;
}

@Override
public String path() {
return basePath() + ProbeTemplateUploadHandler.PATH;
}

@Override
public Set<ResourceAction> resourceActions() {
return ResourceAction.NONE;
}

@Override
public void handleAuthenticated(RoutingContext ctx) {
BODY_HANDLER.handle(ctx);
}
}
Loading