use of org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(Configuration configuration, EntityDescriptorIds entityDescriptorIds) {
final SidecarCollectorConfigurationEntity configurationEntity = SidecarCollectorConfigurationEntity.create(ValueReference.of(entityDescriptorIds.getOrThrow(configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1)), ValueReference.of(configuration.name()), ValueReference.of(configuration.color()), ValueReference.of(configuration.template()));
final JsonNode data = objectMapper.convertValue(configurationEntity, JsonNode.class);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(configuration.id(), ModelTypes.SIDECAR_COLLECTOR_CONFIGURATION_V1))).type(TYPE_V1).data(data).build();
}
use of org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacadeTest method exportEntity.
@Test
@MongoDBFixtures("SidecarCollectorConfigurationFacadeTest.json")
public void exportEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5b17e1a53f3ab8204eea1051", ModelTypes.SIDECAR_COLLECTOR_CONFIGURATION_V1);
final EntityDescriptor collectorDescriptor = EntityDescriptor.create("5b4c920b4b900a0024af0001", ModelTypes.SIDECAR_COLLECTOR_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, collectorDescriptor);
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.SIDECAR_COLLECTOR_CONFIGURATION_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final SidecarCollectorConfigurationEntity configEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorConfigurationEntity.class);
assertThat(configEntity.title()).isEqualTo(ValueReference.of("filebeat config"));
assertThat(configEntity.collectorId()).isEqualTo(ValueReference.of(entityDescriptorIds.get(collectorDescriptor).orElse(null)));
assertThat(configEntity.color().asString(Collections.emptyMap())).isEqualTo("#ffffff");
assertThat(configEntity.template().asString(Collections.emptyMap())).isEqualTo("empty template");
}
use of org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacade method resolveEntityV1.
private Graph<Entity> resolveEntityV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entity);
final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
final EntityDescriptor collectorDescriptor = EntityDescriptor.create(configurationEntity.collectorId().asString(parameters), ModelTypes.SIDECAR_COLLECTOR_V1);
final Entity collectorEntity = entities.get(collectorDescriptor);
if (collectorEntity != null) {
mutableGraph.putEdge(entity, collectorEntity);
}
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacade method decode.
private NativeEntity<Configuration> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
final Configuration configuration = Configuration.create(configurationEntity.collectorId().asString(parameters), configurationEntity.title().asString(parameters), configurationEntity.color().asString(parameters), configurationEntity.template().asString(parameters));
final Configuration savedConfiguration = configurationService.save(configuration);
return NativeEntity.create(entity.id(), savedConfiguration.id(), TYPE_V1, configuration.name(), savedConfiguration);
}
Aggregations