Skip to content

Commit

Permalink
fix(archives): accept and delete recording uploads, emit event with c…
Browse files Browse the repository at this point in the history
…orrect size
  • Loading branch information
andrewazores committed Mar 4, 2024
1 parent 606f7e2 commit 34e8406
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/main/java/io/cryostat/recordings/ActiveRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,18 @@ public record ArchivedRecordingEvent(

// 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.
// 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, ArchivedRecording recording) {
public Payload {
Objects.requireNonNull(target);
Objects.requireNonNull(recording);
}

public static Payload of(URI connectUrl, ArchivedRecording recording) {
return new Payload(connectUrl.toString(), recording);
return new Payload(
Optional.ofNullable(connectUrl).map(URI::toString).orElse(null),
recording);
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/io/cryostat/recordings/Recordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,18 @@ public List<ArchivedRecording> agentGet(@RestPath String jvmId) {
@RolesAllowed("write")
public Response agentDelete(@RestPath String connectUrl, @RestPath String filename)
throws Exception {
var target = Target.getTargetByConnectUrl(URI.create(connectUrl));
if (!recordingHelper.listArchivedRecordingObjects(target.jvmId).stream()
String jvmId;
if ("uploads".equals(connectUrl)) {
jvmId = "uploads";
} else {
jvmId = Target.getTargetByConnectUrl(URI.create(connectUrl)).jvmId;
}
if (!recordingHelper.listArchivedRecordingObjects(jvmId).stream()
.map(item -> item.key().strip().split("/")[1])
.anyMatch(fn -> Objects.equals(fn, filename))) {
return Response.status(RestResponse.Status.NOT_FOUND).build();
}
recordingHelper.deleteArchivedRecording(target.jvmId, filename);
recordingHelper.deleteArchivedRecording(jvmId, filename);
return Response.status(RestResponse.Status.NO_CONTENT).build();
}

Expand Down Expand Up @@ -376,7 +381,7 @@ Map<String, Object> doUpload(FileUpload recording, Metadata metadata, String jvm
recordingHelper.downloadUrl(jvmId, filename),
recordingHelper.reportUrl(jvmId, filename),
metadata,
0 /*filesize*/,
recording.size(),
clock.getMonotonicTime())));
bus.publish(event.category().category(), event.payload().recording());
bus.publish(
Expand Down

0 comments on commit 34e8406

Please sign in to comment.