Skip to content

Commit

Permalink
correct how recording stop payloads are delivered to agent
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Sep 19, 2023
1 parent cea7155 commit 9e2ba17
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions src/main/java/io/cryostat/net/AgentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand All @@ -29,6 +30,7 @@

import org.openjdk.jmc.common.unit.IConstrainedMap;
import org.openjdk.jmc.common.unit.IConstraint;
import org.openjdk.jmc.common.unit.IMutableConstrainedMap;
import org.openjdk.jmc.common.unit.IOptionDescriptor;
import org.openjdk.jmc.common.unit.QuantityConversionException;
import org.openjdk.jmc.common.unit.SimpleConstrainedMap;
Expand Down Expand Up @@ -58,6 +60,7 @@
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.codec.BodyCodec;
import jdk.jfr.RecordingState;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.auth.InvalidCredentialsException;
Expand Down Expand Up @@ -208,24 +211,42 @@ Future<Buffer> openStream(long id) {
}

Future<Void> stopRecording(long id) {
Future<HttpResponse<Void>> f =
invoke(
HttpMethod.PATCH,
String.format("/recordings/%d", id),
Buffer.buffer(),
BodyCodec.none());
return f.map(
resp -> {
int statusCode = resp.statusCode();
if (HttpStatusCodeIdentifier.isSuccessCode(statusCode)) {
return null;
} else if (statusCode == 403) {
throw new AuthorizationErrorException(
new UnsupportedOperationException("stopRecording"));
} else {
throw new AgentApiException(statusCode);
// FIXME this is a terrible hack, the interfaces here should not require only an
// IConstrainedMap with IOptionDescriptors but allow us to pass other and more simply
// serializable data to the Agent, such as this recording state entry
IConstrainedMap<String> map =
new IConstrainedMap<String>() {
@Override
public Set<String> keySet() {
return Set.of("state");
}
});

@Override
public Object get(String key) {
return RecordingState.STOPPED.name();
}

@Override
public IConstraint<?> getConstraint(String key) {
throw new UnsupportedOperationException();
}

@Override
public String getPersistableString(String key) {
throw new UnsupportedOperationException();
}

@Override
public IMutableConstrainedMap<String> emptyWithSameConstraints() {
throw new UnsupportedOperationException();
}

@Override
public IMutableConstrainedMap<String> mutableCopy() {
throw new UnsupportedOperationException();
}
};
return updateRecordingOptions(id, map);
}

Future<Void> deleteRecording(long id) {
Expand Down

0 comments on commit 9e2ba17

Please sign in to comment.