use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class InMemoryRuleService method save.
@Override
public RuleDao save(RuleDao rule) {
RuleDao toSave = rule.id() != null ? rule : rule.toBuilder().id(createId()).build();
// enforce the title unique constraint
if (titleToId.containsKey(toSave.title())) {
// if this is an update and the title belongs to the passed rule, then it's fine
if (!titleToId.get(toSave.title()).equals(toSave.id())) {
throw new IllegalArgumentException("Duplicate rule titles are not allowed: " + toSave.title());
}
}
titleToId.put(toSave.title(), toSave.id());
store.put(toSave.id(), toSave);
clusterBus.post(RulesChangedEvent.updatedRuleId(toSave.id()));
return toSave;
}
use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class InMemoryRuleService method delete.
@Override
public void delete(String id) {
if (id == null) {
return;
}
final RuleDao removed = store.remove(id);
// clean up title index if the rule existed
if (removed != null) {
titleToId.remove(removed.title());
}
clusterBus.post(RulesChangedEvent.deletedRuleId(id));
}
use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class MongoDbRuleService method save.
@Override
public RuleDao save(RuleDao rule) {
final WriteResult<RuleDao, String> save = dbCollection.save(rule);
final RuleDao savedRule = save.getSavedObject();
clusterBus.post(RulesChangedEvent.updatedRuleId(savedRule.id()));
return savedRule;
}
use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class PipelineRuleFacade method decode.
private NativeEntity<RuleDao> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
final PipelineRuleEntity ruleEntity = objectMapper.convertValue(entity.data(), PipelineRuleEntity.class);
final String title = ruleEntity.title().asString(parameters);
final String source = ruleEntity.source().asString(parameters);
final DateTime now = Tools.nowUTC();
final ValueReference description = ruleEntity.description();
final RuleDao ruleDao = RuleDao.builder().title(title).description(description == null ? null : description.asString(parameters)).source(source).createdAt(now).modifiedAt(now).build();
final RuleDao savedRuleDao = ruleService.save(ruleDao);
return NativeEntity.create(entity.id(), savedRuleDao.id(), TYPE_V1, savedRuleDao.title(), savedRuleDao);
}
Aggregations