Search in sources :

Example 1 with SidecarCollectorEntity

use of org.graylog2.contentpacks.model.entities.SidecarCollectorEntity in project graylog2-server by Graylog2.

the class SidecarCollectorFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(Collector collector, EntityDescriptorIds entityDescriptorIds) {
    final SidecarCollectorEntity collectorEntity = SidecarCollectorEntity.create(ValueReference.of(collector.name()), ValueReference.of(collector.serviceType()), ValueReference.of(collector.nodeOperatingSystem()), ValueReference.of(collector.executablePath()), ValueReference.of(collector.executeParameters()), ValueReference.of(collector.validationParameters()), ValueReference.of(collector.defaultTemplate()));
    final JsonNode data = objectMapper.convertValue(collectorEntity, JsonNode.class);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1))).type(TYPE_V1).data(data).build();
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with SidecarCollectorEntity

use of org.graylog2.contentpacks.model.entities.SidecarCollectorEntity in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method exportEntity.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void exportEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5b4c920b4b900a0024af0001", ModelTypes.SIDECAR_COLLECTOR_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.SIDECAR_COLLECTOR_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorEntity.class);
    assertThat(collectorEntity.name()).isEqualTo(ValueReference.of("filebeat"));
    assertThat(collectorEntity.serviceType()).isEqualTo(ValueReference.of("exec"));
    assertThat(collectorEntity.nodeOperatingSystem()).isEqualTo(ValueReference.of("linux"));
    assertThat(collectorEntity.executablePath()).isEqualTo(ValueReference.of("/usr/lib/graylog-sidecar/filebeat"));
    assertThat(collectorEntity.executeParameters()).isEqualTo(ValueReference.of("-c %s"));
    assertThat(collectorEntity.validationParameters()).isEqualTo(ValueReference.of("test config -c %s"));
    assertThat(collectorEntity.defaultTemplate()).isEqualTo(ValueReference.of(""));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with SidecarCollectorEntity

use of org.graylog2.contentpacks.model.entities.SidecarCollectorEntity in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method exportNativeEntity.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void exportNativeEntity() {
    final Collector collector = collectorService.find("5b4c920b4b900a0024af0001");
    final EntityDescriptor descriptor = EntityDescriptor.create(collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(collector, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorEntity.class);
    assertThat(collectorEntity.name()).isEqualTo(ValueReference.of("filebeat"));
    assertThat(collectorEntity.serviceType()).isEqualTo(ValueReference.of("exec"));
    assertThat(collectorEntity.nodeOperatingSystem()).isEqualTo(ValueReference.of("linux"));
    assertThat(collectorEntity.executablePath()).isEqualTo(ValueReference.of("/usr/lib/graylog-sidecar/filebeat"));
    assertThat(collectorEntity.executeParameters()).isEqualTo(ValueReference.of("-c %s"));
    assertThat(collectorEntity.validationParameters()).isEqualTo(ValueReference.of("test config -c %s"));
    assertThat(collectorEntity.defaultTemplate()).isEqualTo(ValueReference.of(""));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) Collector(org.graylog.plugins.sidecar.rest.models.Collector) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 4 with SidecarCollectorEntity

use of org.graylog2.contentpacks.model.entities.SidecarCollectorEntity in project graylog2-server by Graylog2.

the class SidecarCollectorFacade method decode.

private NativeEntity<Collector> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final Collector collector = Collector.builder().name(collectorEntity.name().asString(parameters)).serviceType(collectorEntity.serviceType().asString(parameters)).nodeOperatingSystem(collectorEntity.nodeOperatingSystem().asString(parameters)).executablePath(collectorEntity.executablePath().asString(parameters)).executeParameters(collectorEntity.executeParameters().asString(parameters)).validationParameters(collectorEntity.validationParameters().asString(parameters)).defaultTemplate(collectorEntity.defaultTemplate().asString(parameters)).build();
    final Collector savedCollector = collectorService.save(collector);
    return NativeEntity.create(entity.id(), savedCollector.id(), TYPE_V1, collector.name(), savedCollector);
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Example 5 with SidecarCollectorEntity

use of org.graylog2.contentpacks.model.entities.SidecarCollectorEntity in project graylog2-server by Graylog2.

the class SidecarCollectorFacade method findExisting.

private Optional<NativeEntity<Collector>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final String name = collectorEntity.name().asString(parameters);
    final String os = collectorEntity.nodeOperatingSystem().asString(parameters);
    final Optional<Collector> existingCollector = Optional.ofNullable(collectorService.findByNameAndOs(name, os));
    return existingCollector.map(collector -> NativeEntity.create(entity.id(), collector.id(), TYPE_V1, collector.name(), collector));
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Aggregations

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