From a1410726bc892a6e1122de75b462d128d3429258 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 28 Nov 2024 15:17:51 -0500 Subject: [PATCH] fix(eventtemplates): log warning and continue if declarative Event Template already exists (#726) --- .../java/io/cryostat/events/S3TemplateService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/cryostat/events/S3TemplateService.java b/src/main/java/io/cryostat/events/S3TemplateService.java index 61e67ef79..f33c2f4d8 100644 --- a/src/main/java/io/cryostat/events/S3TemplateService.java +++ b/src/main/java/io/cryostat/events/S3TemplateService.java @@ -115,6 +115,8 @@ void onStart(@Observes StartupEvent evt) { | InvalidXmlException | InvalidEventTemplateException e) { logger.error(e); + } catch (IllegalArgumentException e) { + logger.warn(e); } }); } catch (IOException e) { @@ -225,8 +227,7 @@ public Template addTemplate(InputStream stream) var template = createTemplate(model); var existing = getTemplates(); if (existing.stream().anyMatch(t -> Objects.equals(t.getName(), template.getName()))) { - throw new IllegalArgumentException( - String.format("Duplicate event template name: %s", template.getName())); + throw new DuplicateTemplateException(template.getName()); } storage.putObject( PutObjectRequest.builder() @@ -357,4 +358,10 @@ private String getAttributeValue(XMLTagInstance node, String valueKey) { .findFirst() .get(); } + + static class DuplicateTemplateException extends IllegalArgumentException { + DuplicateTemplateException(String templateName) { + super(String.format("Event Template with name \"%s\" already exists", templateName)); + } + } }