Skip to content

Commit

Permalink
Check validation earlier, cleanup probes on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Matsuoka committed Apr 19, 2024
1 parent 89820a8 commit 5ce7b61
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/io/cryostat/jmcagent/JMCAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,25 @@ public Response postProbe(@RestPath long id, @RestPath String probeTemplateName)
return connectionManager.executeConnectedTask(
target,
connection -> {
AgentJMXHelper helper = new AgentJMXHelper(connection.getHandle());
try {
AgentJMXHelper helper = new AgentJMXHelper(connection.getHandle());
String templateContent = service.getTemplateContent(probeTemplateName);
helper.defineEventProbes(templateContent);
ProbeTemplate template = new ProbeTemplate();
// Retrieve template and deserialize to validate
String templateContent = service.getTemplateContent(probeTemplateName);
template.deserialize(
new ByteArrayInputStream(
templateContent.getBytes(StandardCharsets.UTF_8)));
helper.defineEventProbes(templateContent);
bus.publish(
MessagingServer.class.getName(),
new Notification(
TEMPLATE_APPLIED_CATEGORY,
Map.of("probeTemplate", template.getFileName())));
return Response.status(RestResponse.Status.OK).build();
} catch (Exception e) {
// Cleanup the probes if something went wrong, calling defineEventProbes
// with a null argument will remove any active probes.
helper.defineEventProbes(null);
return Response.status(RestResponse.Status.INTERNAL_SERVER_ERROR)
.build();
}
Expand Down

0 comments on commit 5ce7b61

Please sign in to comment.