use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class InputFacadeTest method resolveForInstallationGrokPattern.
@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveForInstallationGrokPattern() throws NotFoundException {
final Input input = inputService.find("5ae2ebbeef27464477f0fd8b");
final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
final GrokExtractor grokExtractor = (GrokExtractor) inputWithExtractors.extractors().iterator().next();
final ExtractorEntity extractorEntity = ExtractorEntity.create(ValueReference.of(grokExtractor.getTitle()), ValueReference.of(grokExtractor.getType()), ValueReference.of(grokExtractor.getCursorStrategy()), ValueReference.of(grokExtractor.getTargetField()), ValueReference.of(grokExtractor.getSourceField()), ReferenceMapUtils.toReferenceMap(grokExtractor.getExtractorConfig()), Collections.emptyList(), ValueReference.of(grokExtractor.getConditionType()), ValueReference.of(grokExtractor.getConditionValue()), ValueReference.of(grokExtractor.getOrder()));
List<ExtractorEntity> extractorEntities = new ArrayList<>(1);
extractorEntities.add(extractorEntity);
InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), ReferenceMapUtils.toReferenceMap(input.getConfiguration()), Collections.emptyMap(), ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractorEntities);
Entity entity = EntityV1.builder().id(ModelId.of(input.getId())).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(inputEntity, JsonNode.class)).build();
final GrokPatternEntity grokPatternEntity = GrokPatternEntity.create("GREEDY", ".*");
final Entity expectedEntity = EntityV1.builder().id(ModelId.of("dead-feed")).data(objectMapper.convertValue(grokPatternEntity, JsonNode.class)).type(ModelTypes.GROK_PATTERN_V1).build();
final EntityDescriptor entityDescriptor = expectedEntity.toEntityDescriptor();
final Map<EntityDescriptor, Entity> entities = new HashMap<>(1);
entities.put(entityDescriptor, expectedEntity);
Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), entities);
assertThat(graph.nodes()).contains(expectedEntity);
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method notResolveNotMatchingDependecyForInstallation.
@Test
public void notResolveNotMatchingDependecyForInstallation() {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{DOOM}"), JsonNode.class)).build();
final Entity grokPatternEntityDependency = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("PORTAL", "\\d\\d"), JsonNode.class)).build();
final EntityDescriptor dependencyDescriptor = grokPatternEntityDependency.toEntityDescriptor();
final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap(1);
entityDescriptorEntityMap.put(dependencyDescriptor, grokPatternEntityDependency);
final Map<String, ValueReference> parameters = Collections.emptyMap();
Graph<Entity> graph = facade.resolveForInstallation(grokPatternEntity, parameters, entityDescriptorEntityMap);
assertThat(graph.nodes().toArray()).doesNotContain(grokPatternEntityDependency);
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method findExistingFailsWithDivergingPatterns.
@Test
public void findExistingFailsWithDivergingPatterns() throws ValidationException {
grokPatternService.save(GrokPattern.create("Test", "[a-z]+"));
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "BOOM"), JsonNode.class)).build();
assertThatThrownBy(() -> facade.findExisting(grokPatternEntity, Collections.emptyMap())).isInstanceOf(DivergingEntityConfigurationException.class).hasMessage("Expected Grok pattern for name \"Test\": <BOOM>; actual Grok pattern: <[a-z]+>");
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method exportNativeEntity.
@Test
public void exportNativeEntity() {
final GrokPattern grokPattern = GrokPattern.create("01234567890", "name", "pattern", null);
final EntityDescriptor descriptor = EntityDescriptor.create(grokPattern.id(), ModelTypes.GROK_PATTERN_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(grokPattern, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.GROK_PATTERN_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entityV1.data(), GrokPatternEntity.class);
assertThat(grokPatternEntity.name()).isEqualTo("name");
assertThat(grokPatternEntity.pattern()).isEqualTo("pattern");
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacade method resolveForInstallationV1.
private Graph<Entity> resolveForInstallationV1(EntityV1 entity, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entity);
final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entity.data(), GrokPatternEntity.class);
final String namedPattern = grokPatternEntity.pattern();
final Set<String> patterns = GrokPatternService.extractPatternNames(namedPattern);
patterns.stream().forEach(patternName -> {
entities.entrySet().stream().filter(x -> x.getValue().type().equals(ModelTypes.GROK_PATTERN_V1)).filter(x -> {
EntityV1 entityV1 = (EntityV1) x.getValue();
GrokPatternEntity grokPatternEntity1 = objectMapper.convertValue(entityV1.data(), GrokPatternEntity.class);
return grokPatternEntity1.name().equals(patternName);
}).forEach(x -> mutableGraph.putEdge(entity, x.getValue()));
});
return ImmutableGraph.copyOf(mutableGraph);
}
Aggregations