Skip to content

Commit

Permalink
Backend state changes (#470)
Browse files Browse the repository at this point in the history
* Iniitial implementations of delete notifications

* Implementation of template notifications

* Implementation of archived recording notifications

* Implementation of created/archived recordings notifactions, test cleanup

* Add target ID to notification payload, rename RecordingsPostHandler notification category
  • Loading branch information
Josh-Matsuoka authored Apr 28, 2021
1 parent f28691a commit 6837ea3
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.cryostat.MainModule;
import io.cryostat.core.sys.Clock;
import io.cryostat.core.sys.FileSystem;
import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.TargetConnectionManager;
import io.cryostat.net.web.http.RequestHandler;
import io.cryostat.platform.PlatformClient;
Expand Down Expand Up @@ -102,9 +103,15 @@ static TargetRecordingPatchSave provideTargetRecordingPatchSave(
@Named(MainModule.RECORDINGS_PATH) Path recordingsPath,
TargetConnectionManager targetConnectionManager,
Clock clock,
PlatformClient platformClient) {
PlatformClient platformClient,
NotificationFactory notificationFactory) {
return new TargetRecordingPatchSave(
fs, recordingsPath, targetConnectionManager, clock, platformClient);
fs,
recordingsPath,
targetConnectionManager,
clock,
platformClient,
notificationFactory);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import io.cryostat.MainModule;
import io.cryostat.core.sys.FileSystem;
import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.AuthManager;
import io.cryostat.net.reports.ReportService;
import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.api.ApiVersion;

import io.vertx.core.http.HttpMethod;
Expand All @@ -59,17 +62,21 @@ class RecordingDeleteHandler extends AbstractAuthenticatedRequestHandler {
private final ReportService reportService;
private final FileSystem fs;
private final Path savedRecordingsPath;
private final NotificationFactory notificationFactory;
private static final String NOTIFICATION_CATEGORY = "RecordingDeleted";

@Inject
RecordingDeleteHandler(
AuthManager auth,
ReportService reportService,
FileSystem fs,
NotificationFactory notificationFactory,
@Named(MainModule.RECORDINGS_PATH) Path savedRecordingsPath) {
super(auth);
this.reportService = reportService;
this.fs = fs;
this.savedRecordingsPath = savedRecordingsPath;
this.notificationFactory = notificationFactory;
}

@Override
Expand Down Expand Up @@ -106,6 +113,13 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
throw new HttpStatusException(404, recordingName);
}
fs.deleteIfExists(path);
notificationFactory
.createBuilder()
.metaCategory(NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(Map.of("recording", recordingName))
.build()
.send();
} catch (IOException e) {
throw new HttpStatusException(500, e.getMessage(), e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import io.cryostat.MainModule;
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.HttpServer;
import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler;
Expand Down Expand Up @@ -81,6 +82,8 @@ class RecordingsPostHandler extends AbstractAuthenticatedRequestHandler {
private final Path savedRecordingsPath;
private final Gson gson;
private final Logger logger;
private final NotificationFactory notificationFactory;
private static final String NOTIFICATION_CATEGORY = "RecordingSaved";

@Inject
RecordingsPostHandler(
Expand All @@ -89,13 +92,15 @@ class RecordingsPostHandler extends AbstractAuthenticatedRequestHandler {
FileSystem fs,
@Named(MainModule.RECORDINGS_PATH) Path savedRecordingsPath,
Gson gson,
Logger logger) {
Logger logger,
NotificationFactory notificationFactory) {
super(auth);
this.vertx = httpServer.getVertx();
this.fs = fs;
this.savedRecordingsPath = savedRecordingsPath;
this.gson = gson;
this.logger = logger;
this.notificationFactory = notificationFactory;
}

@Override
Expand Down Expand Up @@ -191,6 +196,14 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
.end(gson.toJson(Map.of("name", res2.result())));

logger.info("Recording saved as {}", res2.result());

notificationFactory
.createBuilder()
.metaCategory(NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(Map.of("recording", res2.result()))
.build()
.send();
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@
*/
package io.cryostat.net.web.http.api.v1;

import java.util.Map;
import java.util.Optional;

import javax.inject.Inject;

import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor;

import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.AuthManager;
import io.cryostat.net.ConnectionDescriptor;
import io.cryostat.net.TargetConnectionManager;
import io.cryostat.net.reports.ReportService;
import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.api.ApiVersion;

import io.vertx.core.http.HttpMethod;
Expand All @@ -58,13 +61,17 @@ class TargetRecordingDeleteHandler extends AbstractAuthenticatedRequestHandler {

private final TargetConnectionManager targetConnectionManager;
private final ReportService reportService;
private final NotificationFactory notificationFactory;
private static final String NOTIFICATION_CATEGORY = "RecordingDeleted";

@Inject
TargetRecordingDeleteHandler(
AuthManager auth,
TargetConnectionManager targetConnectionManager,
NotificationFactory notificationFactory,
ReportService reportService) {
super(auth);
this.notificationFactory = notificationFactory;
this.targetConnectionManager = targetConnectionManager;
this.reportService = reportService;
}
Expand Down Expand Up @@ -103,6 +110,18 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
if (descriptor.isPresent()) {
connection.getService().close(descriptor.get());
reportService.delete(connectionDescriptor, recordingName);
notificationFactory
.createBuilder()
.metaCategory(NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(
Map.of(
"recording",
recordingName,
"target",
connectionDescriptor.getTargetId()))
.build()
.send();
ctx.response().setStatusCode(200);
ctx.response().end();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.time.temporal.ChronoUnit;
import java.util.Map;
import java.util.Optional;

import javax.inject.Inject;
Expand All @@ -52,8 +53,10 @@
import io.cryostat.core.net.JFRConnection;
import io.cryostat.core.sys.Clock;
import io.cryostat.core.sys.FileSystem;
import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.ConnectionDescriptor;
import io.cryostat.net.TargetConnectionManager;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.platform.PlatformClient;

import io.vertx.ext.web.RoutingContext;
Expand All @@ -66,19 +69,23 @@ class TargetRecordingPatchSave {
private final TargetConnectionManager targetConnectionManager;
private final Clock clock;
private final PlatformClient platformClient;
private final NotificationFactory notificationFactory;
private static final String NOTIFICATION_CATEGORY = "RecordingArchived";

@Inject
TargetRecordingPatchSave(
FileSystem fs,
@Named(MainModule.RECORDINGS_PATH) Path recordingsPath,
TargetConnectionManager targetConnectionManager,
Clock clock,
PlatformClient platformClient) {
PlatformClient platformClient,
NotificationFactory notificationFactory) {
this.fs = fs;
this.recordingsPath = recordingsPath;
this.targetConnectionManager = targetConnectionManager;
this.clock = clock;
this.platformClient = platformClient;
this.notificationFactory = notificationFactory;
}

void handle(RoutingContext ctx, ConnectionDescriptor connectionDescriptor) throws Exception {
Expand Down Expand Up @@ -108,6 +115,14 @@ void handle(RoutingContext ctx, ConnectionDescriptor connectionDescriptor) throw
});
ctx.response().setStatusCode(200);
ctx.response().end(saveName);
notificationFactory
.createBuilder()
.metaCategory(NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(
Map.of("recording", saveName, "target", connectionDescriptor.getTargetId()))
.build()
.send();
}

private String saveRecording(JFRConnection connection, IRecordingDescriptor descriptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
Expand All @@ -60,6 +61,7 @@
import io.cryostat.core.templates.Template;
import io.cryostat.core.templates.TemplateType;
import io.cryostat.jmc.serialization.HyperlinkedSerializableRecordingDescriptor;
import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.AuthManager;
import io.cryostat.net.TargetConnectionManager;
import io.cryostat.net.web.WebServer;
Expand Down Expand Up @@ -96,6 +98,8 @@ class TargetRecordingsPostHandler extends AbstractAuthenticatedRequestHandler {
private final EventOptionsBuilder.Factory eventOptionsBuilderFactory;
private final Provider<WebServer> webServerProvider;
private final Gson gson;
private final NotificationFactory notificationFactory;
private static final String NOTIFICATION_CATEGORY = "RecordingCreated";

@Inject
TargetRecordingsPostHandler(
Expand All @@ -104,13 +108,15 @@ class TargetRecordingsPostHandler extends AbstractAuthenticatedRequestHandler {
RecordingOptionsBuilderFactory recordingOptionsBuilderFactory,
EventOptionsBuilder.Factory eventOptionsBuilderFactory,
Provider<WebServer> webServerProvider,
Gson gson) {
Gson gson,
NotificationFactory notificationFactory) {
super(auth);
this.targetConnectionManager = targetConnectionManager;
this.recordingOptionsBuilderFactory = recordingOptionsBuilderFactory;
this.eventOptionsBuilderFactory = eventOptionsBuilderFactory;
this.webServerProvider = webServerProvider;
this.gson = gson;
this.notificationFactory = notificationFactory;
}

@Override
Expand Down Expand Up @@ -187,7 +193,19 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
.start(
recordingOptions,
enableEvents(connection, eventSpecifier));

notificationFactory
.createBuilder()
.metaCategory(NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(
Map.of(
"recording",
recordingName,
"target",
getConnectionDescriptorFromContext(ctx)
.getTargetId()))
.build()
.send();
return getDescriptorByName(connection, recordingName)
.map(
d -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
*/
package io.cryostat.net.web.http.api.v1;

import java.util.Map;

import javax.inject.Inject;

import io.cryostat.core.templates.LocalStorageTemplateService;
import io.cryostat.core.templates.MutableTemplateService.InvalidEventTemplateException;
import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.AuthManager;
import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.api.ApiVersion;

import io.vertx.core.http.HttpMethod;
Expand All @@ -52,11 +56,17 @@
class TemplateDeleteHandler extends AbstractAuthenticatedRequestHandler {

private final LocalStorageTemplateService templateService;
private final NotificationFactory notificationFactory;
private static final String NOTIFICATION_CATEGORY = "TemplateDeleted";

@Inject
TemplateDeleteHandler(AuthManager auth, LocalStorageTemplateService templateService) {
TemplateDeleteHandler(
AuthManager auth,
LocalStorageTemplateService templateService,
NotificationFactory notificationFactory) {
super(auth);
this.templateService = templateService;
this.notificationFactory = notificationFactory;
}

@Override
Expand Down Expand Up @@ -85,6 +95,13 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
try {
this.templateService.deleteTemplate(templateName);
ctx.response().end();
notificationFactory
.createBuilder()
.metaCategory(NOTIFICATION_CATEGORY)
.metaType(HttpMimeType.JSON)
.message(Map.of("template", templateName))
.build()
.send();
} catch (InvalidEventTemplateException iete) {
throw new HttpStatusException(400, iete.getMessage(), iete);
}
Expand Down
Loading

0 comments on commit 6837ea3

Please sign in to comment.