Skip to content

Commit

Permalink
correcting response status codes to match 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Nov 21, 2023
1 parent 571709f commit 43cda6d
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/main/java/io/cryostat/recordings/Recordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import io.cryostat.ConfigProperties;
import io.cryostat.Producers;
import io.cryostat.V2Response;
import io.cryostat.core.net.JFRConnection;
import io.cryostat.core.sys.Clock;
import io.cryostat.core.templates.TemplateType;
Expand Down Expand Up @@ -497,29 +498,42 @@ public Response patchV1(@RestPath URI connectUrl, @RestPath String recordingName
@Blocking
@Path("/api/v1/targets/{connectUrl}/snapshot")
@RolesAllowed("write")
public Response createSnapshotV1(@RestPath URI connectUrl) {
return Response.status(RestResponse.Status.PERMANENT_REDIRECT)
.location(
URI.create(
String.format(
"/api/v3/targets/%d/snapshot",
Target.getTargetByConnectUrl(connectUrl).id)))
.build();
public Response createSnapshotV1(@RestPath URI connectUrl) throws Exception {
Target target = Target.getTargetByConnectUrl(connectUrl);
try {
ActiveRecording recording =
connectionManager.executeConnectedTask(
target,
connection -> recordingHelper.createSnapshot(target, connection));
return Response.status(Response.Status.OK).entity(recording.name).build();
} catch (SnapshotCreationException sce) {
return Response.status(Response.Status.ACCEPTED).build();
}
}

@POST
@Transactional
@Blocking
@Path("/api/v2/targets/{connectUrl}/snapshot")
@RolesAllowed("write")
public Response createSnapshotV2(@RestPath URI connectUrl) {
return Response.status(RestResponse.Status.PERMANENT_REDIRECT)
.location(
URI.create(
String.format(
"/api/v3/targets/%d/snapshot",
Target.getTargetByConnectUrl(connectUrl).id)))
.build();
public Response createSnapshotV2(@RestPath URI connectUrl) throws Exception {
Target target = Target.getTargetByConnectUrl(connectUrl);
try {
ActiveRecording recording =
connectionManager.executeConnectedTask(
target,
connection -> recordingHelper.createSnapshot(target, connection));
return Response.status(Response.Status.CREATED)
.entity(
V2Response.json(
recordingHelper.toExternalForm(recording),
RestResponse.Status.CREATED.toString()))
.build();
} catch (SnapshotCreationException sce) {
return Response.status(Response.Status.ACCEPTED)
.entity(V2Response.json(null, RestResponse.Status.ACCEPTED.toString()))
.build();
}
}

@POST
Expand Down

0 comments on commit 43cda6d

Please sign in to comment.