Skip to content

Commit

Permalink
feat(recordings): set recording template in label (#864)
Browse files Browse the repository at this point in the history
* fix(graphql): populate metadata on recordings responses

* chore(metadata): refactor to generalize labels to metadata

* feat(recordings): set recording template in label

* include metadata in query

* fixup! feat(recordings): set recording template in label

* update web-client
  • Loading branch information
andrewazores authored Mar 17, 2022
1 parent fec2298 commit 726467b
Show file tree
Hide file tree
Showing 24 changed files with 325 additions and 205 deletions.
6 changes: 6 additions & 0 deletions graphql/environment-nodes-query-3.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ query {
active {
name
state
metadata {
labels
}
}
archived {
name
metadata {
labels
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
import io.cryostat.recordings.RecordingNotFoundException;

import com.google.gson.Gson;
import io.vertx.core.http.HttpMethod;

public class RecordingMetadataLabelsPostHandler extends AbstractV2RequestHandler {
public class RecordingMetadataLabelsPostHandler extends AbstractV2RequestHandler<Metadata> {

static final String PATH = "recordings/:recordingName/metadata/labels";

Expand Down Expand Up @@ -116,28 +117,27 @@ public boolean requiresAuthentication() {
}

@Override
public IntermediateResponse<Map<String, String>> handle(RequestParameters params)
throws Exception {
public IntermediateResponse<Metadata> handle(RequestParameters params) throws Exception {
String recordingName = params.getPathParams().get("recordingName");

try {
Map<String, String> labels =
recordingMetadataManager.parseRecordingLabels(params.getBody());
Metadata metadata =
new Metadata(recordingMetadataManager.parseRecordingLabels(params.getBody()));

recordingArchiveHelper.getRecordingPath(recordingName).get();

Map<String, String> updatedLabels =
recordingMetadataManager.setRecordingLabels(recordingName, labels).get();
Metadata updatedMetadata =
recordingMetadataManager.setRecordingMetadata(recordingName, metadata).get();

notificationFactory
.createBuilder()
.metaCategory(RecordingMetadataManager.NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(Map.of("recordingName", recordingName, "labels", labels))
.message(Map.of("recordingName", recordingName, "metadata", updatedMetadata))
.build()
.send();

return new IntermediateResponse<Map<String, String>>().body(updatedLabels);
return new IntermediateResponse<Metadata>().body(updatedMetadata);
} catch (ExecutionException e) {
if (e.getCause() instanceof RecordingNotFoundException) {
throw new ApiException(404, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.recordings.RecordingTargetHelper;

import com.google.gson.Gson;
import io.vertx.core.http.HttpMethod;

public class TargetRecordingMetadataLabelsPostHandler extends AbstractV2RequestHandler {
public class TargetRecordingMetadataLabelsPostHandler extends AbstractV2RequestHandler<Metadata> {

static final String PATH = "targets/:targetId/recordings/:recordingName/metadata/labels";

Expand Down Expand Up @@ -126,23 +127,23 @@ public boolean requiresAuthentication() {
}

@Override
public IntermediateResponse<Map<String, String>> handle(RequestParameters params)
throws Exception {
public IntermediateResponse<Metadata> handle(RequestParameters params) throws Exception {
String recordingName = params.getPathParams().get("recordingName");
String targetId = params.getPathParams().get("targetId");

try {
Map<String, String> labels =
recordingMetadataManager.parseRecordingLabels(params.getBody());
Metadata metadata = new Metadata(labels);

if (!this.targetRecordingFound(
getConnectionDescriptorFromParams(params), recordingName)) {
throw new RecordingNotFoundException(targetId, recordingName);
}

Map<String, String> updatedLabels =
Metadata updatedMetadata =
recordingMetadataManager
.setRecordingLabels(targetId, recordingName, labels)
.setRecordingMetadata(targetId, recordingName, metadata)
.get();

notificationFactory
Expand All @@ -155,11 +156,11 @@ public IntermediateResponse<Map<String, String>> handle(RequestParameters params
recordingName,
"target",
targetId,
"labels",
updatedLabels))
"metadata",
updatedMetadata))
.build()
.send();
return new IntermediateResponse<Map<String, String>>().body(updatedLabels);
return new IntermediateResponse<Metadata>().body(updatedMetadata);
} catch (RecordingNotFoundException e) {
throw new ApiException(404, e);
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import io.cryostat.net.web.http.RequestHandler;
import io.cryostat.platform.PlatformClient;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingOptionsBuilderFactory;
import io.cryostat.recordings.RecordingTargetHelper;

Expand Down Expand Up @@ -189,9 +190,11 @@ static RecordingsFetcher provideRecordingsFetcher(
TargetConnectionManager tcm,
RecordingArchiveHelper archiveHelper,
CredentialsManager credentialsManager,
RecordingMetadataManager metadataManager,
Provider<WebServer> webServer,
Logger logger) {
return new RecordingsFetcher(tcm, archiveHelper, credentialsManager, webServer, logger);
return new RecordingsFetcher(
tcm, archiveHelper, credentialsManager, metadataManager, webServer, logger);
}

@Provides
Expand Down Expand Up @@ -267,9 +270,14 @@ static StopRecordingMutator provideStopRecordingsOnTargetMutator(
TargetConnectionManager targetConnectionManager,
RecordingTargetHelper recordingTargetHelper,
CredentialsManager credentialsManager,
RecordingMetadataManager metadataManager,
Provider<WebServer> webServer) {
return new StopRecordingMutator(
targetConnectionManager, recordingTargetHelper, credentialsManager, webServer);
targetConnectionManager,
recordingTargetHelper,
credentialsManager,
metadataManager,
webServer);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,27 @@

import io.cryostat.jmc.serialization.HyperlinkedSerializableRecordingDescriptor;
import io.cryostat.platform.ServiceRef;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;

class GraphRecordingDescriptor extends HyperlinkedSerializableRecordingDescriptor {

protected transient ServiceRef target;

public GraphRecordingDescriptor(
ServiceRef target, IRecordingDescriptor original, String downloadUrl, String reportUrl)
ServiceRef target,
IRecordingDescriptor original,
String downloadUrl,
String reportUrl,
Metadata metadata)
throws QuantityConversionException {
super(original, downloadUrl, reportUrl);
super(original, downloadUrl, reportUrl, metadata);
this.target = target;
}

public GraphRecordingDescriptor(ServiceRef target, HyperlinkedSerializableRecordingDescriptor o)
throws QuantityConversionException {
super(o, o.getDownloadUrl(), o.getReportUrl());
this.target = target;
this.metadata = o.getMetadata();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import io.cryostat.platform.ServiceRef;
import io.cryostat.platform.discovery.TargetNode;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
import io.cryostat.rules.ArchivedRecordingInfo;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand All @@ -68,6 +70,7 @@ class RecordingsFetcher implements DataFetcher<Recordings> {
private final TargetConnectionManager tcm;
private final RecordingArchiveHelper archiveHelper;
private final CredentialsManager credentialsManager;
private final RecordingMetadataManager metadataManager;
private final Provider<WebServer> webServer;
private final Logger logger;

Expand All @@ -76,11 +79,13 @@ class RecordingsFetcher implements DataFetcher<Recordings> {
TargetConnectionManager tcm,
RecordingArchiveHelper archiveHelper,
CredentialsManager credentialsManager,
RecordingMetadataManager metadataManager,
Provider<WebServer> webServer,
Logger logger) {
this.tcm = tcm;
this.archiveHelper = archiveHelper;
this.credentialsManager = credentialsManager;
this.metadataManager = metadataManager;
this.webServer = webServer;
this.logger = logger;
}
Expand Down Expand Up @@ -119,8 +124,15 @@ public Recordings get(DataFetchingEnvironment environment) throws Exception {
.get()
.getReportURL(
conn, r.getName());
Metadata metadata =
metadataManager.getMetadata(
targetId, r.getName());
return new GraphRecordingDescriptor(
target, r, downloadUrl, reportUrl);
target,
r,
downloadUrl,
reportUrl,
metadata);
} catch (QuantityConversionException
| URISyntaxException
| IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import io.cryostat.net.TargetConnectionManager;
import io.cryostat.net.web.WebServer;
import io.cryostat.platform.ServiceRef;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
import io.cryostat.recordings.RecordingTargetHelper;

import graphql.schema.DataFetcher;
Expand All @@ -57,17 +59,20 @@ class StopRecordingMutator implements DataFetcher<GraphRecordingDescriptor> {
private final TargetConnectionManager targetConnectionManager;
private final RecordingTargetHelper recordingTargetHelper;
private final CredentialsManager credentialsManager;
private final RecordingMetadataManager metadataManager;
private final Provider<WebServer> webServer;

@Inject
StopRecordingMutator(
TargetConnectionManager targetConnectionManager,
RecordingTargetHelper recordingTargetHelper,
CredentialsManager credentialsManager,
RecordingMetadataManager metadataManager,
Provider<WebServer> webServer) {
this.targetConnectionManager = targetConnectionManager;
this.recordingTargetHelper = recordingTargetHelper;
this.credentialsManager = credentialsManager;
this.metadataManager = metadataManager;
this.webServer = webServer;
}

Expand All @@ -85,11 +90,13 @@ public GraphRecordingDescriptor get(DataFetchingEnvironment environment) throws
IRecordingDescriptor desc =
recordingTargetHelper.stopRecording(cd, source.getName(), true);
WebServer ws = webServer.get();
Metadata metadata = metadataManager.getMetadata(uri, desc.getName());
return new GraphRecordingDescriptor(
target,
desc,
ws.getDownloadURL(conn, desc.getName()),
ws.getReportURL(conn, desc.getName()));
ws.getReportURL(conn, desc.getName()),
metadata);
},
true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.api.ApiVersion;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;

import com.google.gson.Gson;
import io.vertx.core.http.HttpHeaders;
Expand Down Expand Up @@ -131,12 +130,10 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
webServer.getDownloadURL(
connection, desc.getName()),
webServer.getReportURL(connection, desc.getName()),
new Metadata(
recordingMetadataManager.getRecordingLabels(
getConnectionDescriptorFromContext(
ctx)
.getTargetId(),
desc.getName()))));
recordingMetadataManager.getMetadata(
getConnectionDescriptorFromContext(ctx)
.getTargetId(),
desc.getName())));
}
return list;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
attrs.get("metadata"),
new TypeToken<Metadata>() {}.getType());
recordingMetadataManager
.setRecordingLabels(
.setRecordingMetadata(
connectionDescriptor.getTargetId(),
recordingName,
metadata.getLabels())
metadata)
.get();
}
Pair<String, TemplateType> template =
Expand All @@ -214,10 +214,9 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
connection, descriptor.getName()),
webServer.getReportURL(
connection, descriptor.getName()),
new Metadata(
recordingMetadataManager.getRecordingLabels(
connectionDescriptor.getTargetId(),
recordingName)));
recordingMetadataManager.getMetadata(
connectionDescriptor.getTargetId(),
recordingName));
} catch (QuantityConversionException
| URISyntaxException
| IOException e) {
Expand Down
Loading

0 comments on commit 726467b

Please sign in to comment.