From 787048f98ea8fb240cc8159cdfcecbfe39c5a07f Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Wed, 21 Jun 2023 20:40:58 -0400 Subject: [PATCH 1/3] chore(template): correct template name for logs --- .../io/cryostat/core/agent/LocalProbeTemplateService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java b/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java index c4b04046..45826c5d 100644 --- a/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java +++ b/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java @@ -91,6 +91,7 @@ public void addTemplate(InputStream inputStream, String filename) throws FileAlreadyExistsException, IOException, SAXException { 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); @@ -108,9 +109,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(); } From 1e0c034be1c2714e7c6aac8af6425938bf597e71 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Thu, 22 Jun 2023 01:19:28 -0400 Subject: [PATCH 2/3] chore(template): return template when uploading --- .../core/agent/LocalProbeTemplateService.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java b/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java index 45826c5d..10e7cabc 100644 --- a/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java +++ b/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java @@ -87,18 +87,19 @@ 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(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; } } @@ -138,8 +139,8 @@ public List 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); } } From b5d053ef26b340c0565c32c66821a5a9abd0e2ed Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Thu, 22 Jun 2023 02:48:42 -0400 Subject: [PATCH 3/3] fix(template): should truly close the inputstream --- .../java/io/cryostat/core/agent/LocalProbeTemplateService.java | 3 ++- src/main/java/io/cryostat/core/agent/ProbeTemplate.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java b/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java index 10e7cabc..9f979c8b 100644 --- a/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java +++ b/src/main/java/io/cryostat/core/agent/LocalProbeTemplateService.java @@ -91,7 +91,8 @@ 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(filename); + throw new FileAlreadyExistsException( + String.format("Probe template \"%s\" already exists.", filename)); } try (inputStream) { ProbeTemplate template = new ProbeTemplate(); diff --git a/src/main/java/io/cryostat/core/agent/ProbeTemplate.java b/src/main/java/io/cryostat/core/agent/ProbeTemplate.java index fe5e4f36..13133f8b 100644 --- a/src/main/java/io/cryostat/core/agent/ProbeTemplate.java +++ b/src/main/java/io/cryostat/core/agent/ProbeTemplate.java @@ -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