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();
}
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(""));
}
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(""));
}
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);
}
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));
}
Aggregations