use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.
the class SidecarService method assignConfiguration.
public Sidecar assignConfiguration(String collectorNodeId, List<ConfigurationAssignment> assignments) throws NotFoundException {
Sidecar sidecar = findByNodeId(collectorNodeId);
if (sidecar == null) {
throw new NotFoundException("Couldn't find collector with ID " + collectorNodeId);
}
for (ConfigurationAssignment assignment : assignments) {
Collector collector = collectorService.find(assignment.collectorId());
if (collector == null) {
throw new NotFoundException("Couldn't find collector with ID " + assignment.collectorId());
}
Configuration configuration = configurationService.find(assignment.configurationId());
if (configuration == null) {
throw new NotFoundException("Couldn't find configuration with ID " + assignment.configurationId());
}
if (!configuration.collectorId().equals(collector.id())) {
throw new NotFoundException("Configuration doesn't match collector ID " + assignment.collectorId());
}
}
Sidecar toSave = sidecar.toBuilder().assignments(assignments).build();
return save(toSave);
}
use of org.graylog.plugins.sidecar.rest.models.Collector 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.graylog.plugins.sidecar.rest.models.Collector 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