diff --git a/src/main/java/io/cryostat/recordings/ActiveRecording.java b/src/main/java/io/cryostat/recordings/ActiveRecording.java index 3e7242189..3b9996262 100644 --- a/src/main/java/io/cryostat/recordings/ActiveRecording.java +++ b/src/main/java/io/cryostat/recordings/ActiveRecording.java @@ -15,9 +15,7 @@ */ package io.cryostat.recordings; -import java.net.URI; import java.util.Objects; -import java.util.Optional; import org.openjdk.jmc.common.unit.UnitLookup; import org.openjdk.jmc.flightrecorder.configuration.IRecordingDescriptor; @@ -215,19 +213,14 @@ public record ActiveRecordingEvent( Objects.requireNonNull(payload); } - public record Payload( - String target, LinkedRecordingDescriptor recording, String jvmId) { + public record Payload(LinkedRecordingDescriptor recording, String jvmId) { public Payload { - Objects.requireNonNull(target); Objects.requireNonNull(recording); Objects.requireNonNull(jvmId); } public static Payload of(RecordingHelper helper, ActiveRecording recording) { - return new Payload( - recording.target.connectUrl.toString(), - helper.toExternalForm(recording), - recording.target.jvmId); + return new Payload(helper.toExternalForm(recording), recording.target.jvmId); } } } @@ -239,21 +232,14 @@ public record ArchivedRecordingEvent( Objects.requireNonNull(payload); } - // FIXME the target connectUrl URI may no longer be known if the target - // has disappeared and we are emitting an event regarding an archived recording - // originally sourced from that target, or if we are accepting a recording upload from a - // client. - // This should embed the target jvmId and optionally the database ID. public record Payload(String target, ArchivedRecordings.ArchivedRecording recording) { public Payload { Objects.requireNonNull(recording); } public static Payload of( - URI connectUrl, ArchivedRecordings.ArchivedRecording recording) { - return new Payload( - Optional.ofNullable(connectUrl).map(URI::toString).orElse(null), - recording); + String jvmId, ArchivedRecordings.ArchivedRecording recording) { + return new Payload(jvmId, recording); } } } diff --git a/src/main/java/io/cryostat/recordings/ArchivedRecordings.java b/src/main/java/io/cryostat/recordings/ArchivedRecordings.java index 8d7302828..686ee2663 100644 --- a/src/main/java/io/cryostat/recordings/ArchivedRecordings.java +++ b/src/main/java/io/cryostat/recordings/ArchivedRecordings.java @@ -179,7 +179,7 @@ public void agentPush( new ArchivedRecordingEvent( ActiveRecordings.RecordingEventCategory.ARCHIVED_DELETED, ArchivedRecordingEvent.Payload.of( - target.map(t -> t.connectUrl).orElse(null), + target.map(t -> t.jvmId).orElseThrow(), new ArchivedRecording( jvmId, recording.fileName(), @@ -291,12 +291,11 @@ Map doUpload(FileUpload recording, Metadata metadata, String jvm RequestBody.fromFile(recording.filePath())); logger.trace("Upload complete"); - var target = Target.getTargetByJvmId(jvmId); var event = new ArchivedRecordingEvent( ActiveRecordings.RecordingEventCategory.ARCHIVED_CREATED, ArchivedRecordingEvent.Payload.of( - target.map(t -> t.connectUrl).orElse(null), + jvmId, new ArchivedRecording( jvmId, filename, @@ -348,14 +347,12 @@ public Collection listFsArchives() { .getArchivedRecordingMetadata(jvmId, filename) .orElseGet(Metadata::empty); - String connectUrl = - metadata.labels().computeIfAbsent("connectUrl", k -> jvmId); var dir = map.computeIfAbsent( jvmId, id -> new ArchivedRecordingDirectory( - connectUrl, id, new ArrayList<>())); + id, new ArrayList<>())); dir.recordings.add( new ArchivedRecording( jvmId, @@ -386,14 +383,12 @@ public Collection listFsArchives(@RestPath String jv .getArchivedRecordingMetadata(jvmId, filename) .orElseGet(Metadata::empty); - String connectUrl = - metadata.labels().computeIfAbsent("connectUrl", k -> jvmId); var dir = map.computeIfAbsent( jvmId, id -> new ArchivedRecordingDirectory( - connectUrl, id, new ArrayList<>())); + id, new ArrayList<>())); dir.recordings.add( new ArchivedRecording( jvmId, @@ -419,19 +414,6 @@ public void deleteArchivedRecording(@RestPath String jvmId, @RestPath String fil .getArchivedRecordingMetadata(jvmId, filename) .orElseGet(Metadata::empty); - var connectUrl = - Target.getTargetByJvmId(jvmId) - .map(t -> t.connectUrl) - .map(c -> c.toString()) - .filter(StringUtils::isNotBlank) - .orElseGet( - () -> - metadata.labels() - .computeIfAbsent( - "connectUrl", k -> "lost-" + jvmId)); - logger.tracev( - "Archived recording from connectUrl \"{0}\" has metadata: {1}", - connectUrl, metadata); logger.tracev( "Sending S3 deletion request for {0} {1}", bucket, recordingHelper.archivedRecordingKey(jvmId, filename)); @@ -449,7 +431,7 @@ public void deleteArchivedRecording(@RestPath String jvmId, @RestPath String fil new ArchivedRecordingEvent( ActiveRecordings.RecordingEventCategory.ARCHIVED_DELETED, ArchivedRecordingEvent.Payload.of( - URI.create(connectUrl), + jvmId, new ArchivedRecording( jvmId, filename, @@ -568,10 +550,8 @@ public record ArchivedRecording( } @SuppressFBWarnings("EI_EXPOSE_REP") - public record ArchivedRecordingDirectory( - String connectUrl, String jvmId, List recordings) { + public record ArchivedRecordingDirectory(String jvmId, List recordings) { public ArchivedRecordingDirectory { - Objects.requireNonNull(connectUrl); Objects.requireNonNull(jvmId); if (recordings == null) { recordings = Collections.emptyList(); diff --git a/src/main/java/io/cryostat/recordings/RecordingHelper.java b/src/main/java/io/cryostat/recordings/RecordingHelper.java index d40850e48..c684ba773 100644 --- a/src/main/java/io/cryostat/recordings/RecordingHelper.java +++ b/src/main/java/io/cryostat/recordings/RecordingHelper.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLDecoder; @@ -903,12 +902,11 @@ public ArchivedRecording archiveRecording( accum, now.getEpochSecond()); - URI connectUrl = recording.target.connectUrl; - var event = new ArchivedRecordingEvent( ActiveRecordings.RecordingEventCategory.ARCHIVED_CREATED, - ArchivedRecordingEvent.Payload.of(connectUrl, archivedRecording)); + ArchivedRecordingEvent.Payload.of( + recording.target.jvmId, archivedRecording)); bus.publish(event.category().category(), event.payload().recording()); bus.publish( MessagingServer.class.getName(), @@ -1059,7 +1057,7 @@ public void deleteArchivedRecording(String jvmId, String filename) { new ArchivedRecordingEvent( ActiveRecordings.RecordingEventCategory.ARCHIVED_DELETED, ArchivedRecordingEvent.Payload.of( - target.map(t -> t.connectUrl).orElse(null), + target.map(t -> t.jvmId).orElseThrow(), new ArchivedRecording( jvmId, filename, diff --git a/src/main/java/io/cryostat/targets/Target.java b/src/main/java/io/cryostat/targets/Target.java index f24f9af7c..576947b78 100644 --- a/src/main/java/io/cryostat/targets/Target.java +++ b/src/main/java/io/cryostat/targets/Target.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.function.Predicate; import java.util.stream.Collectors; import io.cryostat.ConfigProperties; @@ -134,15 +133,6 @@ public static Optional getTargetByJvmId(String jvmId) { return find("jvmId", jvmId).firstResultOptional(); } - public static Optional getTarget(Predicate predicate) { - List targets = listAll(); - return targets.stream().filter(predicate).findFirst(); - } - - public static boolean deleteByConnectUrl(URI connectUrl) { - return delete("connectUrl", connectUrl) > 0; - } - public static List findByRealm(String realm) { List targets = findAll().list();