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 (#726)
  • Loading branch information
andrewazores authored Nov 28, 2024
1 parent c3ee63b commit a141072
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 a141072

Please sign in to comment.