Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Nov 20, 2023
1 parent f8699b0 commit 4b95b49
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 73 deletions.
16 changes: 4 additions & 12 deletions src/main/java/io/cryostat/recordings/Recordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,28 +305,20 @@ public List<ArchivedRecording> agentGet(@RestPath String jvmId) {

@DELETE
@Blocking
@Path("/api/beta/recordings/{jvmId}/{filename}")
@Path("/api/beta/recordings/{connectUrl}/{filename}")
@RolesAllowed("write")
public void agentDelete(
@RestPath String jvmId,
@RestPath String connectUrl,
@RestPath String filename,
@RestForm("recording") FileUpload recording,
@RestForm("labels") JsonObject rawLabels)
throws Exception {
var metadata =
recordingHelper
.getArchivedRecordingMetadata(jvmId, filename)
.orElseGet(Metadata::empty);
var connectUrl =
Target.getTargetByJvmId(jvmId)
.map(t -> t.connectUrl)
.map(c -> c.toString())
.orElseGet(() -> metadata.labels.computeIfAbsent("connectUrl", k -> jvmId));
var target = Target.getTargetByConnectUrl(URI.create(connectUrl));
var resp =
storage.deleteObject(
DeleteObjectRequest.builder()
.bucket(archiveBucket)
.key(recordingHelper.archivedRecordingKey(jvmId, filename))
.key(recordingHelper.archivedRecordingKey(target.jvmId, filename))
.build());
if (resp.sdkHttpResponse().isSuccessful()) {
bus.publish(
Expand Down
94 changes: 33 additions & 61 deletions src/test/java/itest/RecordingWorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package itest;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand All @@ -40,7 +41,6 @@
import jdk.jfr.consumer.RecordingFile;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -51,8 +51,6 @@ public class RecordingWorkflowTest extends StandardSelfTest {
static final String TEST_RECORDING_NAME = "workflow_itest";
static final String TARGET_ALIAS = "selftest";

public static final Logger logger = Logger.getLogger(RecordingWorkflowTest.class);

@Test
public void testWorkflow() throws Exception {
// Check preconditions
Expand All @@ -73,6 +71,7 @@ public void testWorkflow() throws Exception {
JsonArray listResp = listRespFuture1.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
Assertions.assertTrue(listResp.isEmpty());

List<String> archivedRecordingFilenames = new ArrayList<>();
try {
// create an in-memory recording
MultiMap form = MultiMap.caseInsensitiveMultiMap();
Expand Down Expand Up @@ -120,16 +119,20 @@ public void testWorkflow() throws Exception {
// save a copy of the partial recording dump
MultiMap saveHeaders = MultiMap.caseInsensitiveMultiMap();
saveHeaders.add(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.PLAINTEXT.mime());
webClient
.extensions()
.patch(
String.format(
"/api/v1/targets/%s/recordings/%s",
getSelfReferenceConnectUrlEncoded(), TEST_RECORDING_NAME),
true,
saveHeaders,
"SAVE",
REQUEST_TIMEOUT_SECONDS);
String archivedRecordingFilename =
webClient
.extensions()
.patch(
String.format(
"/api/v1/targets/%s/recordings/%s",
getSelfReferenceConnectUrlEncoded(),
TEST_RECORDING_NAME),
true,
saveHeaders,
"SAVE",
REQUEST_TIMEOUT_SECONDS)
.bodyAsString();
archivedRecordingFilenames.add(archivedRecordingFilename);

// check that the in-memory recording list hasn't changed
CompletableFuture<JsonArray> listRespFuture3 = new CompletableFuture<>();
Expand Down Expand Up @@ -264,56 +267,25 @@ public void testWorkflow() throws Exception {
true,
REQUEST_TIMEOUT_SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error(
new ITestCleanupFailedException(
String.format(
"Failed to delete target recording %s",
TEST_RECORDING_NAME),
e));
throw new ITestCleanupFailedException(
String.format("Failed to delete target recording %s", TEST_RECORDING_NAME),
e);
}

CompletableFuture<JsonArray> savedRecordingsFuture = new CompletableFuture<>();
webClient
.get("/api/v1/recordings")
.basicAuthentication("user", "pass")
.send(
ar -> {
if (assertRequestStatus(ar, savedRecordingsFuture)) {
savedRecordingsFuture.complete(ar.result().bodyAsJsonArray());
}
});

JsonArray savedRecordings = null;
try {
savedRecordings =
savedRecordingsFuture.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error(
new ITestCleanupFailedException(
"Failed to retrieve archived recordings", e));
}

for (Object savedRecording : savedRecordings) {
String recordingName = ((JsonObject) savedRecording).getString("name");
if (recordingName.matches(
TARGET_ALIAS + "_" + TEST_RECORDING_NAME + "_[\\d]{8}T[\\d]{6}Z.jfr")) {
try {
webClient
.extensions()
.delete(
String.format(
"/api/beta/recordings/%s/%s",
getSelfReferenceConnectUrlEncoded(), recordingName),
true,
REQUEST_TIMEOUT_SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error(
new ITestCleanupFailedException(
String.format(
"Failed to delete archived recording %s",
recordingName),
e));
}
for (String savedRecording : archivedRecordingFilenames) {
try {
webClient
.extensions()
.delete(
String.format(
"/api/beta/recordings/%s/%s",
getSelfReferenceConnectUrlEncoded(), savedRecording),
true,
REQUEST_TIMEOUT_SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new ITestCleanupFailedException(
String.format("Failed to delete archived recording %s", savedRecording),
e);
}
}
}
Expand Down

0 comments on commit 4b95b49

Please sign in to comment.