From 1929840629442f8a72cb967865b5069c8d050aa8 Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Fri, 29 Sep 2023 15:26:28 -0400 Subject: [PATCH] include jvmId in issueNotifications for recordings --- .../recordings/RecordingTargetHelper.java | 24 +++++++++++++------ .../cryostat/recordings/RecordingsModule.java | 2 ++ .../recordings/RecordingTargetHelperTest.java | 3 +++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java b/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java index 949f75e728..8582396757 100644 --- a/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java +++ b/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java @@ -45,6 +45,8 @@ import io.cryostat.net.reports.ReportService; import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.HttpMimeType; +import io.cryostat.recordings.JvmIdHelper; +import io.cryostat.recordings.JvmIdHelper.JvmIdGetException; import io.cryostat.recordings.RecordingMetadataManager.Metadata; import dagger.Lazy; @@ -72,6 +74,7 @@ public class RecordingTargetHelper { private final Vertx vertx; private final TargetConnectionManager targetConnectionManager; private final Lazy webServer; + private final Lazy jvmIdHelper; private final EventOptionsBuilder.Factory eventOptionsBuilderFactory; private final NotificationFactory notificationFactory; private final RecordingOptionsBuilderFactory recordingOptionsBuilderFactory; @@ -85,6 +88,7 @@ public class RecordingTargetHelper { Vertx vertx, TargetConnectionManager targetConnectionManager, Lazy webServer, + Lazy jvmIdHelper, EventOptionsBuilder.Factory eventOptionsBuilderFactory, NotificationFactory notificationFactory, RecordingOptionsBuilderFactory recordingOptionsBuilderFactory, @@ -95,6 +99,7 @@ public class RecordingTargetHelper { this.vertx = vertx; this.targetConnectionManager = targetConnectionManager; this.webServer = webServer; + this.jvmIdHelper = jvmIdHelper; this.eventOptionsBuilderFactory = eventOptionsBuilderFactory; this.notificationFactory = notificationFactory; this.recordingOptionsBuilderFactory = recordingOptionsBuilderFactory; @@ -467,13 +472,18 @@ private void issueNotification( String targetId, HyperlinkedSerializableRecordingDescriptor linkedDesc, String notificationCategory) { - notificationFactory - .createBuilder() - .metaCategory(notificationCategory) - .metaType(HttpMimeType.JSON) - .message(Map.of("recording", linkedDesc, "target", targetId)) - .build() - .send(); + try { + notificationFactory + .createBuilder() + .metaCategory(notificationCategory) + .metaType(HttpMimeType.JSON) + .message(Map.of("recording", linkedDesc, "target", targetId, "jvmId", jvmIdHelper.get().getJvmId(targetId))) + .build() + .send(); + } catch (JvmIdGetException e) { + logger.info("Retain null jvmId for target [{}]", targetId); + logger.info(e); + } } private void cancelScheduledTasksIfExists(String targetId, String stoppedRecordingName) diff --git a/src/main/java/io/cryostat/recordings/RecordingsModule.java b/src/main/java/io/cryostat/recordings/RecordingsModule.java index 1ab3e655ea..210b41129a 100644 --- a/src/main/java/io/cryostat/recordings/RecordingsModule.java +++ b/src/main/java/io/cryostat/recordings/RecordingsModule.java @@ -79,6 +79,7 @@ static RecordingTargetHelper provideRecordingTargetHelper( Vertx vertx, TargetConnectionManager targetConnectionManager, Lazy webServer, + Lazy jvmIdHelper, EventOptionsBuilder.Factory eventOptionsBuilderFactory, NotificationFactory notificationFactory, RecordingOptionsBuilderFactory recordingOptionsBuilderFactory, @@ -90,6 +91,7 @@ static RecordingTargetHelper provideRecordingTargetHelper( vertx, targetConnectionManager, webServer, + jvmIdHelper, eventOptionsBuilderFactory, notificationFactory, recordingOptionsBuilderFactory, diff --git a/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java b/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java index ee6c77f426..124b3883a7 100644 --- a/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java +++ b/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java @@ -53,6 +53,7 @@ import io.cryostat.net.reports.ReportService; import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.HttpMimeType; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingMetadataManager.Metadata; import io.cryostat.recordings.RecordingTargetHelper.ReplacementPolicy; import io.cryostat.recordings.RecordingTargetHelper.SnapshotCreationException; @@ -80,6 +81,7 @@ public class RecordingTargetHelperTest { @Mock AuthManager auth; @Mock TargetConnectionManager targetConnectionManager; @Mock WebServer webServer; + @Mock JvmIdHelper jvmIdHelper; @Mock EventOptionsBuilder.Factory eventOptionsBuilderFactory; @Mock NotificationFactory notificationFactory; @Mock RecordingOptionsBuilderFactory recordingOptionsBuilderFactory; @@ -113,6 +115,7 @@ void setup() { vertx, targetConnectionManager, () -> webServer, + () -> jvmIdHelper, eventOptionsBuilderFactory, notificationFactory, recordingOptionsBuilderFactory,