use of org.graylog2.contentpacks.model.entities.InputEntity in project graylog2-server by Graylog2.
the class InputFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(InputWithExtractors inputWithExtractors, EntityDescriptorIds entityDescriptorIds) {
final Input input = inputWithExtractors.input();
// TODO: Create independent representation of entity?
final Map<String, ValueReference> staticFields = input.getStaticFields().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, kv -> ValueReference.of(kv.getValue())));
final ReferenceMap configuration = toReferenceMap(input.getConfiguration());
final List<ExtractorEntity> extractors = inputWithExtractors.extractors().stream().map(this::encodeExtractor).collect(Collectors.toList());
final InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), configuration, staticFields, ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractors);
final JsonNode data = objectMapper.convertValue(inputEntity, JsonNode.class);
final Set<Constraint> constraints = versionConstraints(input);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(input.getId(), ModelTypes.INPUT_V1))).type(ModelTypes.INPUT_V1).data(data).constraints(ImmutableSet.copyOf(constraints)).build();
}
use of org.graylog2.contentpacks.model.entities.InputEntity in project graylog2-server by Graylog2.
the class InputFacade method resolveForInstallationV1.
private Graph<Entity> resolveForInstallationV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> graph = GraphBuilder.directed().build();
graph.addNode(entity);
final InputEntity input = objectMapper.convertValue(entity.data(), InputEntity.class);
resolveForInstallationV1LookupTable(entity, input, parameters, entities, graph);
resolveForInstallationV1GrokPattern(entity, input, parameters, entities, graph);
return ImmutableGraph.copyOf(graph);
}
use of org.graylog2.contentpacks.model.entities.InputEntity in project graylog2-server by Graylog2.
the class InputFacade method decode.
private NativeEntity<InputWithExtractors> decode(EntityV1 entity, Map<String, ValueReference> parameters, String username) {
final InputEntity inputEntity = objectMapper.convertValue(entity.data(), InputEntity.class);
final Map<String, ValueReference> staticFields = inputEntity.staticFields();
final MessageInput messageInput;
try {
messageInput = createMessageInput(inputEntity.title().asString(parameters), inputEntity.type().asString(parameters), inputEntity.global().asBoolean(parameters), toValueMap(inputEntity.configuration(), parameters), username);
} catch (Exception e) {
throw new RuntimeException("Couldn't create input", e);
}
final Input input;
try {
input = inputService.find(messageInput.getPersistId());
} catch (NotFoundException e) {
throw new RuntimeException("Couldn't find persisted input", e);
}
try {
addStaticFields(input, messageInput, staticFields, parameters);
} catch (ValidationException e) {
throw new RuntimeException("Couldn't add static fields to input", e);
}
final List<Extractor> extractors;
try {
extractors = createExtractors(input, inputEntity.extractors(), username, parameters);
} catch (Exception e) {
throw new RuntimeException("Couldn't create extractors", e);
}
return NativeEntity.create(entity.id(), input.getId(), TYPE_V1, input.getTitle(), InputWithExtractors.create(input, extractors));
}
use of org.graylog2.contentpacks.model.entities.InputEntity in project graylog2-server by Graylog2.
the class InputFacadeTest method exportEntity.
@Test
@MongoDBFixtures("InputFacadeTest.json")
public void exportEntity() {
final ModelId id = ModelId.of("5acc84f84b900a4ff290d9a7");
final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.INPUT_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Local Raw UDP"));
assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
assertThat(inputEntity.global()).isEqualTo(ValueReference.of(false));
assertThat(inputEntity.configuration()).containsEntry("bind_address", ValueReference.of("127.0.0.1")).containsEntry("port", ValueReference.of(5555));
}
use of org.graylog2.contentpacks.model.entities.InputEntity in project graylog2-server by Graylog2.
the class InputFacadeTest method collectEntity.
@Test
@MongoDBFixtures("InputFacadeTest.json")
public void collectEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5adf25294b900a0fdb4e5365", ModelTypes.INPUT_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
final EntityV1 entity = (EntityV1) collectedEntity.get();
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
final InputEntity inputEntity = objectMapper.convertValue(entity.data(), InputEntity.class);
assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Global Random HTTP"));
assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.random.FakeHttpMessageInput"));
assertThat(inputEntity.global()).isEqualTo(ValueReference.of(true));
assertThat(inputEntity.staticFields()).containsEntry("custom_field", ValueReference.of("foobar"));
assertThat(inputEntity.configuration()).isNotEmpty();
assertThat(inputEntity.extractors()).hasSize(5);
}
Aggregations