Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(jmc-agent): clean up probe template utility #241

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,20 @@ public LocalProbeTemplateService(FileSystem fs, Environment env) throws IOExcept
}
}

public void addTemplate(InputStream inputStream, String filename)
public ProbeTemplate addTemplate(InputStream inputStream, String filename)
throws FileAlreadyExistsException, IOException, SAXException {
Path path = fs.pathOf(env.getEnv(TEMPLATE_PATH), filename);
if (fs.exists(path)) {
throw new FileAlreadyExistsException(
String.format("Probe template \"%s\" already exists.", filename));
}
try (inputStream) {
ProbeTemplate template = new ProbeTemplate();
template.setFileName(filename);
// If validation fails this will throw a ProbeValidationException with details
template.deserialize(inputStream);
Path path = fs.pathOf(env.getEnv(TEMPLATE_PATH), filename);
if (fs.exists(path)) {
throw new FileAlreadyExistsException(template.getFileName());
}
fs.writeString(path, template.serialize());
return template;
}
}

Expand All @@ -108,9 +111,10 @@ public void deleteTemplate(String templateName) throws IOException {
}
}

public String getTemplate(String templateName) throws IOException, SAXException {
public String getTemplateContent(String templateName) throws IOException, SAXException {
Path probeTemplatePath = fs.pathOf(env.getEnv(TEMPLATE_PATH), templateName);
ProbeTemplate template = new ProbeTemplate();
template.setFileName(templateName);
template.deserialize(fs.newInputStream(probeTemplatePath));
return template.serialize();
}
Expand All @@ -136,8 +140,8 @@ public List<ProbeTemplate> getTemplates() throws FlightRecorderException {
Path fileName = path.getFileName();
if (fileName != null) {
ProbeTemplate template = new ProbeTemplate();
template.deserialize(stream);
template.setFileName(fileName.toString());
template.deserialize(stream);
templates.add(template);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/cryostat/core/agent/ProbeTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void deserialize(InputStream xmlStream) throws IOException, SAXException
}

Document document = builder.parse(stream);
stream.close();
stream.trulyClose();
NodeList elements;

// parse global configurations
Expand Down