Skip to content

Commit

Permalink
roughing out internal feature
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Oct 19, 2023
1 parent 0013d92 commit 69586b3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package io.cryostat.messaging.notifications;

import java.util.HashMap;
import java.util.Map;

import io.cryostat.net.web.http.HttpMimeType;

public class Notification<T> {
Expand Down Expand Up @@ -82,6 +85,27 @@ public Notification<T> build() {
}
}

public static class OwnedResourceBuilder extends Builder<Map<String, Object>> {

private final Map<String, Object> map = new HashMap<>();

OwnedResourceBuilder(NotificationSource source, String category) {
super(source);
metaType(HttpMimeType.JSON);
metaCategory(category);
message(map);
}

public OwnedResourceBuilder messageEntry(String key, Object value) {
if (value == null) {
this.map.remove(key);
} else {
this.map.put(key, value);
}
return this;
}
}

public static class Meta {
private final String category;
private final MetaType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,35 @@
*/
package io.cryostat.messaging.notifications;

import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.JvmIdHelper.JvmIdGetException;

public class NotificationFactory {

private final NotificationSource source;
private final JvmIdHelper jvmIdHelper;

NotificationFactory(NotificationSource source) {
NotificationFactory(NotificationSource source, JvmIdHelper jvmIdHelper) {
this.source = source;
this.jvmIdHelper = jvmIdHelper;
}

public <T> Notification.Builder<T> createBuilder() {
return new Notification.Builder<T>(source);
}

public <T> Notification.Builder<T> createOwnedResourceBuilder(String notificationCategory) {
return new Notification.Builder<T>(source)
.metaType(HttpMimeType.JSON)
.metaCategory(notificationCategory);
public Notification.OwnedResourceBuilder createOwnedResourceBuilder(
String notificationCategory) {
return new Notification.OwnedResourceBuilder(source, notificationCategory);
}

public Notification.OwnedResourceBuilder createOwnedResourceBuilder(
String targetId, String notificationCategory) throws JvmIdGetException {
return new Notification.OwnedResourceBuilder(source, notificationCategory)
// FIXME the websocket notification system should only emit the targetId under one
// named key or the other, not both - are we already consistent with this?
.messageEntry("target", targetId)
.messageEntry("connectUrl", targetId)
.messageEntry("jvmId", jvmIdHelper.getJvmId(targetId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import javax.inject.Singleton;

import io.cryostat.recordings.JvmIdHelper;

import dagger.Lazy;
import dagger.Module;
import dagger.Provides;
Expand All @@ -34,7 +36,8 @@ static NotificationSource provideNotificationSource(Lazy<Set<NotificationListene

@Provides
@Singleton
static NotificationFactory provideNotificationFactory(NotificationSource source) {
return new NotificationFactory(source);
static NotificationFactory provideNotificationFactory(
NotificationSource source, JvmIdHelper idHelper) {
return new NotificationFactory(source, idHelper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.JvmIdHelper.JvmIdDoesNotExistException;
import io.cryostat.recordings.JvmIdHelper.JvmIdGetException;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
Expand Down Expand Up @@ -274,35 +275,30 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
try {

notificationFactory
.createOwnedResourceBuilder(NOTIFICATION_CATEGORY)
.message(
Map.of(
"recording",
new ArchivedRecordingInfo(
connectUrl,
fsName,
webServer
.get()
.getArchivedDownloadURL(
connectUrl,
fsName),
webServer
.get()
.getArchivedReportURL(
connectUrl,
fsName),
metadata,
size,
archivedTime),
"target",
.createOwnedResourceBuilder(
connectUrl, NOTIFICATION_CATEGORY)
.messageEntry(
"recording",
new ArchivedRecordingInfo(
connectUrl,
"jvmId",
jvmId))
fsName,
webServer
.get()
.getArchivedDownloadURL(
connectUrl, fsName),
webServer
.get()
.getArchivedReportURL(
connectUrl, fsName),
metadata,
size,
archivedTime))
.build()
.send();
} catch (URISyntaxException
| UnknownHostException
| SocketException e) {
| SocketException
| JvmIdGetException e) {
logger.error(e);
throw new ApiException(500, e);
}
Expand Down

0 comments on commit 69586b3

Please sign in to comment.