Skip to content

Commit

Permalink
updated but still has errors to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 committed Sep 11, 2023
1 parent 151ba16 commit 89f096b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
49 changes: 20 additions & 29 deletions src/main/java/io/cryostat/net/AgentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,44 +132,35 @@ Future<IRecordingDescriptor> startRecording(StartRecordingRequest req) {

Future<IRecordingDescriptor> startSnapshot() {
StartRecordingRequest snapshotReq = new StartRecordingRequest("snapshot", "", "", 0, 0, 0);

Future<HttpResponse<String>> f =
invoke(
HttpMethod.POST,
"/recordings/",
Buffer.buffer(gson.toJson(snapshotReq)),
BodyCodec.string());

return f.map(
resp -> {

return invoke(HttpMethod.POST, "/recordings/", Buffer.buffer(gson.toJson(snapshotReq)), BodyCodec.string())
.compose(resp -> {
int statusCode = resp.statusCode();
if (HttpStatusCodeIdentifier.isSuccessCode(statusCode)) {
String body = resp.body();
return gson.fromJson(body, SerializableRecordingDescriptor.class)
.toJmcForm();
return Future.succeededFuture(resp.body());
} else if (statusCode == 403) {
throw new UnsupportedOperationException();
} else {
throw new RuntimeException("Unknown failure");
}
})
.map(body -> {
IRecordingDescriptor recordingDescriptor = gson.fromJson(body, SerializableRecordingDescriptor.class)
.toJmcForm();
if ("snapshot".equals(recordingDescriptor.getName())) {
String newName = String.format("snapshot-%d", recordingDescriptor.getId());
updateRecordingOptions(recordingDescriptor.getId(), newName);
}
return recordingDescriptor;
});
}

Future<Void> updateRecordingOptions(long id, IConstrainedMap<String> newSettings) {


Future<Void> updateRecordingOptions(long id, String newName) {
JsonObject jsonSettings = new JsonObject();
for (String key : newSettings.keySet()) {
jsonSettings.put(key, newSettings.get(key));
}
Future<HttpResponse<Void>> f =
invoke(
HttpMethod.PATCH,
String.format("/recordings/%d", id),
jsonSettings.toBuffer(),
BodyCodec.none());

return f.map(
resp -> {
jsonSettings.put("name", newName);

return invoke(HttpMethod.PATCH, String.format("/recordings/%d", id), jsonSettings.toBuffer(), BodyCodec.none())
.map(resp -> {
int statusCode = resp.statusCode();
if (HttpStatusCodeIdentifier.isSuccessCode(statusCode)) {
return null;
Expand All @@ -180,7 +171,7 @@ Future<Void> updateRecordingOptions(long id, IConstrainedMap<String> newSettings
}
});
}

Future<Buffer> openStream(long id) {
Future<HttpResponse<Buffer>> f =
invoke(HttpMethod.GET, "/recordings/" + id, BodyCodec.buffer());
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/io/cryostat/net/AgentJFRService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import org.openjdk.jmc.common.unit.IConstrainedMap;
Expand Down Expand Up @@ -250,14 +251,23 @@ public void updateEventOptions(IRecordingDescriptor arg0, IConstrainedMap<EventO

@Override
public void updateRecordingOptions(
IRecordingDescriptor recordingDescriptor, IConstrainedMap<String> newSettings)
throws FlightRecorderException {
IRecordingDescriptor recordingDescriptor, IConstrainedMap<String> newSettings)
throws FlightRecorderException {
try {
long recordingId = recordingDescriptor.getId();
client.updateRecordingOptions(recordingId, newSettings)

Set<String> keys = newSettings.keySet();
boolean nameKeyExists = keys.contains("name");

if (nameKeyExists) {
// Get the new name from newSettings
String newName = (String) newSettings.get("name");
// Update the recording name using the AgentClient's method
client.updateRecordingOptions(recordingId, newName)
.toCompletionStage()
.toCompletableFuture()
.get();
}
} catch (ExecutionException | InterruptedException e) {
throw new FlightRecorderException("Failed to update recording options", e);
}
Expand Down

0 comments on commit 89f096b

Please sign in to comment.