Search in sources :

Example 1 with SidecarCollectorConfigurationEntity

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();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with SidecarCollectorConfigurationEntity

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");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with SidecarCollectorConfigurationEntity

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);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)

Example 4 with SidecarCollectorConfigurationEntity

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);
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)

Aggregations

SidecarCollectorConfigurationEntity (org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)4 Entity (org.graylog2.contentpacks.model.entities.Entity)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Configuration (org.graylog.plugins.sidecar.rest.models.Configuration)1 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)1 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)1 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)1 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)1 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)1 Test (org.junit.Test)1