use of org.graylog2.contentpacks.model.entities.OutputEntity in project graylog2-server by Graylog2.
the class OutputFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(Output output, EntityDescriptorIds entityDescriptorIds) {
final OutputEntity outputEntity = OutputEntity.create(ValueReference.of(output.getTitle()), ValueReference.of(output.getType()), toReferenceMap(output.getConfiguration()));
final JsonNode data = objectMapper.convertValue(outputEntity, JsonNode.class);
final Set<Constraint> constraints = versionConstraints(output);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(output.getId(), ModelTypes.OUTPUT_V1))).type(ModelTypes.OUTPUT_V1).constraints(ImmutableSet.copyOf(constraints)).data(data).build();
}
use of org.graylog2.contentpacks.model.entities.OutputEntity in project graylog2-server by Graylog2.
the class OutputFacade method decode.
private NativeEntity<Output> decode(EntityV1 entity, Map<String, ValueReference> parameters, String username) {
final OutputEntity outputEntity = objectMapper.convertValue(entity.data(), OutputEntity.class);
final CreateOutputRequest createOutputRequest = CreateOutputRequest.create(outputEntity.title().asString(parameters), outputEntity.type().asString(parameters), toValueMap(outputEntity.configuration(), parameters), // Outputs are assigned to streams in StreamFacade
null);
try {
final Output output = outputService.create(createOutputRequest, username);
return NativeEntity.create(entity.id(), output.getId(), TYPE_V1, output.getTitle(), output);
} catch (ValidationException e) {
throw new IllegalArgumentException(e);
}
}
use of org.graylog2.contentpacks.model.entities.OutputEntity in project graylog2-server by Graylog2.
the class StreamFacade method resolveForInstallation.
private Graph<Entity> resolveForInstallation(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entity);
final StreamEntity streamEntity = objectMapper.convertValue(entity.data(), StreamEntity.class);
streamEntity.outputs().stream().map(valueReference -> valueReference.asString(parameters)).map(ModelId::of).map(modelId -> EntityDescriptor.create(modelId, ModelTypes.OUTPUT_V1)).map(entities::get).filter(Objects::nonNull).forEach(outputEntity -> mutableGraph.putEdge(entity, outputEntity));
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.OutputEntity in project graylog2-server by Graylog2.
the class OutputFacadeTest method exportNativeEntity.
@Test
@MongoDBFixtures("OutputFacadeTest.json")
public void exportNativeEntity() throws NotFoundException {
final Output output = outputService.load("5adf239e4b900a0fdb4e5197");
final EntityDescriptor descriptor = EntityDescriptor.create(output.getId(), ModelTypes.OUTPUT_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(output, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.OUTPUT_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final OutputEntity outputEntity = objectMapper.convertValue(entityV1.data(), OutputEntity.class);
assertThat(outputEntity.title()).isEqualTo(ValueReference.of("STDOUT"));
assertThat(outputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.outputs.LoggingOutput"));
assertThat(outputEntity.configuration()).containsEntry("prefix", ValueReference.of("Writing message: "));
}
use of org.graylog2.contentpacks.model.entities.OutputEntity in project graylog2-server by Graylog2.
the class OutputFacadeTest method exportEntity.
@Test
public void exportEntity() {
final ImmutableMap<String, Object> configuration = ImmutableMap.of("some-setting", "foobar");
final OutputImpl output = OutputImpl.create("01234567890", "Output Title", "org.graylog2.outputs.LoggingOutput", "admin", configuration, new Date(0L), null);
final EntityDescriptor descriptor = EntityDescriptor.create(output.getId(), ModelTypes.OUTPUT_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(output, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.OUTPUT_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final OutputEntity outputEntity = objectMapper.convertValue(entityV1.data(), OutputEntity.class);
assertThat(outputEntity.title()).isEqualTo(ValueReference.of("Output Title"));
assertThat(outputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.outputs.LoggingOutput"));
assertThat(outputEntity.configuration()).containsEntry("some-setting", ValueReference.of("foobar"));
}
Aggregations