use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(GrokPattern grokPattern, EntityDescriptorIds entityDescriptorIds) {
final GrokPatternEntity grokPatternEntity = GrokPatternEntity.create(grokPattern.name(), grokPattern.pattern());
final JsonNode data = objectMapper.convertValue(grokPatternEntity, JsonNode.class);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(grokPattern.id(), ModelTypes.GROK_PATTERN_V1))).type(ModelTypes.GROK_PATTERN_V1).data(data).build();
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacade method decode.
private NativeEntity<GrokPattern> decode(EntityV1 entity) {
final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entity.data(), GrokPatternEntity.class);
final GrokPattern grokPattern = GrokPattern.create(grokPatternEntity.name(), grokPatternEntity.pattern());
try {
final GrokPattern savedGrokPattern = grokPatternService.save(grokPattern);
return NativeEntity.create(entity.id(), savedGrokPattern.id(), TYPE_V1, savedGrokPattern.name(), savedGrokPattern);
} catch (ValidationException e) {
throw new RuntimeException("Couldn't create grok pattern " + grokPattern.name());
}
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() throws NotFoundException {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
final NativeEntity<GrokPattern> nativeEntity = facade.createNativeEntity(grokPatternEntity, Collections.emptyMap(), Collections.emptyMap(), "admin");
final GrokPattern expectedGrokPattern = GrokPattern.create("1", "Test", "[a-z]+", null);
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create("1", "1", ModelTypes.GROK_PATTERN_V1, "Test");
assertThat(nativeEntity.descriptor().title()).isEqualTo(expectedDescriptor.title());
assertThat(nativeEntity.descriptor().type()).isEqualTo(expectedDescriptor.type());
assertThat(nativeEntity.entity()).isEqualTo(expectedGrokPattern);
assertThat(grokPatternService.load("1")).isEqualTo(expectedGrokPattern);
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method findExisting.
@Test
public void findExisting() throws ValidationException {
final GrokPattern grokPattern = 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", "[a-z]+"), JsonNode.class)).build();
final Optional<NativeEntity<GrokPattern>> existingGrokPattern = facade.findExisting(grokPatternEntity, Collections.emptyMap());
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(grokPatternEntity.id(), "1", ModelTypes.GROK_PATTERN_V1, grokPattern.name(), false);
assertThat(existingGrokPattern).isPresent().get().satisfies(nativeEntity -> {
assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
assertThat(nativeEntity.entity()).isEqualTo(grokPattern);
});
}
use of org.graylog2.contentpacks.model.entities.GrokPatternEntity in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method resolveMatchingDependecyForInstallation.
@Test
public void resolveMatchingDependecyForInstallation() {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{PORTAL}"), 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()).contains(grokPatternEntityDependency);
}
Aggregations