Skip to content

Commit

Permalink
refactor, extracted bugfix logic out to -core
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Dec 6, 2023
1 parent b3c831e commit 5b352dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 126 deletions.
17 changes: 9 additions & 8 deletions src/main/java/io/cryostat/agent/remote/RecordingsContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import io.cryostat.agent.FlightRecorderHelper;
import io.cryostat.agent.util.StringUtils;
import io.cryostat.core.serialization.SerializableRecordingDescriptor;
import io.cryostat.core.templates.MutableTemplateService.InvalidEventTemplateException;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -127,9 +128,9 @@ private static long extractId(HttpExchange exchange) throws IOException {

private void handleGetList(HttpExchange exchange) {
try (OutputStream response = exchange.getResponseBody()) {
List<SerializableRecording> recordings =
List<SerializableRecordingDescriptor> recordings =
flightRecorder.getRecordings().stream()
.map(SerializableRecording::new)
.map(SerializableRecordingDescriptor::new)
.collect(Collectors.toList());
exchange.sendResponseHeaders(HttpStatus.SC_OK, BODY_LENGTH_UNKNOWN);
mapper.writeValue(response, recordings);
Expand Down Expand Up @@ -182,10 +183,10 @@ private void handleStartRecordingOrSnapshot(HttpExchange exchange) throws IOExce
StartRecordingRequest req = mapper.readValue(body, StartRecordingRequest.class);
if (req.requestSnapshot()) {
try {
SerializableRecording snapshot =
SerializableRecordingDescriptor snapshot =
flightRecorder
.createSnapshot()
.map(SerializableRecording::new)
.map(SerializableRecordingDescriptor::new)
.orElse(null);
if (snapshot == null) {
exchange.sendResponseHeaders(
Expand All @@ -208,7 +209,7 @@ private void handleStartRecordingOrSnapshot(HttpExchange exchange) throws IOExce
exchange.sendResponseHeaders(HttpStatus.SC_BAD_REQUEST, BODY_LENGTH_NONE);
return;
}
SerializableRecording recording = startRecording(req);
SerializableRecordingDescriptor recording = startRecording(req);
exchange.sendResponseHeaders(HttpStatus.SC_CREATED, BODY_LENGTH_UNKNOWN);
try (OutputStream response = exchange.getResponseBody()) {
mapper.writeValue(response, recording);
Expand Down Expand Up @@ -301,7 +302,7 @@ private void handleStopOrUpdate(HttpExchange exchange, long recordingId) throws
response,
flightRecorder
.getRecording(recordingId)
.map(SerializableRecording::new)
.map(SerializableRecordingDescriptor::new)
.get());
}
}
Expand Down Expand Up @@ -347,7 +348,7 @@ private boolean ensureMethodAccepted(HttpExchange exchange) throws IOException {
return passed;
}

private SerializableRecording startRecording(StartRecordingRequest req)
private SerializableRecordingDescriptor startRecording(StartRecordingRequest req)
throws InvalidEventTemplateException {
Recording recording;
if (req.requestsCustomTemplate()) {
Expand All @@ -370,7 +371,7 @@ private SerializableRecording startRecording(StartRecordingRequest req)
recording.setMaxSize(req.maxSize);
recording.setMaxAge(Duration.ofMillis(req.maxAge));
recording.start();
return new SerializableRecording(recording);
return new SerializableRecordingDescriptor(recording);
}

static class StartRecordingRequest {
Expand Down
118 changes: 0 additions & 118 deletions src/main/java/io/cryostat/agent/remote/SerializableRecording.java

This file was deleted.

0 comments on commit 5b352dc

Please sign in to comment.