Skip to content

Commit

Permalink
fix(eventtemplates): log warning and continue if declarative Event Te…
Browse files Browse the repository at this point in the history
…mplate already exists
  • Loading branch information
andrewazores committed Nov 27, 2024
1 parent 25eaba2 commit ecfc143
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/io/cryostat/events/S3TemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void onStart(@Observes StartupEvent evt) {
| InvalidXmlException
| InvalidEventTemplateException e) {
logger.error(e);
} catch (IllegalArgumentException e) {
logger.warn(e);
}
});
} catch (IOException e) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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));
}
}
}

0 comments on commit ecfc143

Please sign in to comment.