Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Dec 19, 2024
1 parent 702a425 commit d68e4c2
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/main/java/io/cryostat/rules/Rules.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Objects;

import io.cryostat.ConfigProperties;
import io.cryostat.expressions.MatchExpression;
Expand Down Expand Up @@ -71,12 +70,6 @@ void onStart(@Observes StartupEvent evt) {
Files.walk(dir)
.filter(Files::isRegularFile)
.filter(Files::isReadable)
.peek(
p ->
logger.tracev(
"Processing declarative Automated Rule definition at"
+ " {}",
p))
.forEach(this::processDeclarativeRule);
} catch (IOException e) {
logger.error(e);
Expand All @@ -87,24 +80,17 @@ private void processDeclarativeRule(java.nio.file.Path path) {
try (var is = new BufferedInputStream(Files.newInputStream(path))) {
var declarativeRule = mapper.readValue(is, Rule.class);
logger.tracev(
"Processing eclarative Automated" + " Rule with name \"{}\"",
declarativeRule.name);
"Processing declarative Automated Rule with name \"{}\" at {}",
declarativeRule.name,
path);
var exists = Rule.find("name", declarativeRule.name).count() != 0;
if (exists) {
var existingRule = Rule.<Rule>find("name", declarativeRule.name).singleResult();
// remove for equality check. The declarative rule is not expected to have a
// database ID yet existingRule.id = null;
if (Objects.equals(declarativeRule, existingRule)) {
return;
}
logger.debugv(
"Rule with name \"{}\" already exists in database. Replacing with"
+ " declarative rule at {}. Previous definition:\n"
+ "{}",
logger.tracev(
"Rule with name \"{}\" already exists in database. Skipping declarative"
+ " rule at {}",
declarativeRule.name,
path,
mapper.writeValueAsString(existingRule));
existingRule.delete();
path);
return;
}
declarativeRule.persist();
} catch (IOException ioe) {
Expand Down

0 comments on commit d68e4c2

Please sign in to comment.