Search in sources :

Example 16 with RuleDao

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;
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao)

Example 17 with RuleDao

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));
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao)

Example 18 with RuleDao

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;
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao)

Example 19 with RuleDao

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);
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) PipelineRuleEntity(org.graylog2.contentpacks.model.entities.PipelineRuleEntity) DateTime(org.joda.time.DateTime) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference)

Aggregations

RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)19 Test (org.junit.Test)10 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)4 PipelineRuleEntity (org.graylog2.contentpacks.model.entities.PipelineRuleEntity)4 NotFoundException (org.graylog2.database.NotFoundException)4 ApiOperation (io.swagger.annotations.ApiOperation)3 BadRequestException (javax.ws.rs.BadRequestException)3 Rule (org.graylog.plugins.pipelineprocessor.ast.Rule)3 ParseException (org.graylog.plugins.pipelineprocessor.parser.ParseException)3 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)3 DateTime (org.joda.time.DateTime)3 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Api (io.swagger.annotations.Api)1