Skip to content

Commit

Permalink
chore(cleanup): Adjust for core changes to abstract away the Document…
Browse files Browse the repository at this point in the history
… type (#449)
  • Loading branch information
Josh-Matsuoka authored May 21, 2024
1 parent b6da1bb commit 1d991d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
9 changes: 4 additions & 5 deletions src/main/java/io/cryostat/events/EventTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.jboss.resteasy.reactive.RestPath;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.multipart.FileUpload;
import org.jsoup.nodes.Document;

@Path("")
public class EventTemplates {
Expand Down Expand Up @@ -179,24 +178,24 @@ public Response getTargetTemplate(
@RestPath long id, @RestPath TemplateType templateType, @RestPath String templateName)
throws Exception {
Target target = Target.find("id", id).singleResult();
Document doc;
String xml;
switch (templateType) {
case TARGET:
doc =
xml =
targetTemplateServiceFactory
.create(target)
.getXml(templateName, templateType)
.orElseThrow();
break;
case CUSTOM:
doc = customTemplateService.getXml(templateName, templateType).orElseThrow();
xml = customTemplateService.getXml(templateName, templateType).orElseThrow();
break;
default:
throw new BadRequestException();
}
return Response.status(RestResponse.Status.OK)
.header(HttpHeaders.CONTENT_TYPE, HttpMimeType.JFC.mime())
.entity(doc.toString())
.entity(xml)
.build();
}
}
11 changes: 4 additions & 7 deletions src/main/java/io/cryostat/events/S3TemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import io.cryostat.StorageBuckets;
import io.cryostat.core.FlightRecorderException;
import io.cryostat.core.templates.MutableTemplateService;
import io.cryostat.core.templates.MutableTemplateService.InvalidEventTemplateException;
import io.cryostat.core.templates.MutableTemplateService.InvalidXmlException;
import io.cryostat.core.templates.Template;
import io.cryostat.core.templates.TemplateType;
import io.cryostat.ws.MessagingServer;
Expand All @@ -62,7 +60,6 @@
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.parser.Parser;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
Expand Down Expand Up @@ -156,12 +153,12 @@ public List<Template> getTemplates() throws FlightRecorderException {
}

@Override
public Optional<Document> getXml(String templateName, TemplateType unused)
public Optional<String> getXml(String templateName, TemplateType unused)
throws FlightRecorderException {
try (var stream = getModel(templateName)) {
Document doc =
Jsoup.parse(stream, StandardCharsets.UTF_8.name(), "", Parser.xmlParser());
return Optional.of(doc);
return Optional.of(
Jsoup.parse(stream, StandardCharsets.UTF_8.name(), "", Parser.xmlParser())
.outerHtml());
} catch (IOException e) {
logger.error(e);
return Optional.empty();
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/io/cryostat/events/TargetTemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jsoup.nodes.Document;

public class TargetTemplateService implements TemplateService {

Expand Down Expand Up @@ -62,11 +61,15 @@ public List<Template> getTemplates() throws FlightRecorderException {
}

@Override
public Optional<Document> getXml(String templateName, TemplateType unused)
public Optional<String> getXml(String templateName, TemplateType unused)
throws FlightRecorderException {
return connectionManager.executeConnectedTask(
target,
conn -> conn.getTemplateService().getXml(templateName, TemplateType.TARGET));
Optional doc =
connectionManager.executeConnectedTask(
target,
conn ->
conn.getTemplateService()
.getXml(templateName, TemplateType.TARGET));
return doc.isPresent() ? Optional.of(doc.toString()) : Optional.empty();
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/cryostat/targets/AgentJFRService.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ public IRecordingDescriptor start(
null,
templateService
.getXml(templateName, preferredTemplateType)
.orElseThrow()
.outerHtml(),
.orElseThrow(),
duration,
maxSize,
maxAge);
Expand Down

0 comments on commit 1d991d1

Please sign in to comment.