use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class PipelineFacade method resolveForInstallation.
private Graph<Entity> resolveForInstallation(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entity);
final PipelineEntity pipelineEntity = objectMapper.convertValue(entity.data(), PipelineEntity.class);
final String source = pipelineEntity.source().asString(parameters);
final Collection<String> referencedRules = referencedRules(source);
referencedRules.stream().map(ModelId::of).map(modelId -> EntityDescriptor.create(modelId, ModelTypes.PIPELINE_RULE_V1)).map(entities::get).filter(Objects::nonNull).forEach(ruleEntity -> mutableGraph.putEdge(entity, ruleEntity));
pipelineEntity.connectedStreams().stream().map(valueReference -> valueReference.asString(parameters)).map(ModelId::of).map(modelId -> EntityDescriptor.create(modelId, ModelTypes.STREAM_V1)).map(entities::get).filter(Objects::nonNull).forEach(streamEntity -> mutableGraph.putEdge(entity, streamEntity));
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class PipelineFacade method resolveNativeEntity.
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
try {
final PipelineDao pipelineDao = pipelineService.load(modelId.id());
final String pipelineSource = pipelineDao.source();
final Collection<String> referencedRules = referencedRules(pipelineSource);
referencedRules.stream().map(ModelId::of).map(id -> EntityDescriptor.create(id, ModelTypes.PIPELINE_RULE_V1)).forEach(rule -> mutableGraph.putEdge(entityDescriptor, rule));
final Set<PipelineConnections> pipelineConnections = connectionsService.loadByPipelineId(pipelineDao.id());
pipelineConnections.stream().map(PipelineConnections::streamId).map(ModelId::of).map(id -> EntityDescriptor.create(id, ModelTypes.STREAM_V1)).forEach(stream -> mutableGraph.putEdge(entityDescriptor, stream));
} catch (NotFoundException e) {
LOG.debug("Couldn't find pipeline {}", entityDescriptor, e);
}
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class PipelineFacade method decode.
private NativeEntity<PipelineDao> decode(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities) {
final DateTime now = Tools.nowUTC();
final PipelineEntity pipelineEntity = objectMapper.convertValue(entity.data(), PipelineEntity.class);
final ValueReference description = pipelineEntity.description();
final PipelineDao pipelineDao = PipelineDao.builder().title(pipelineEntity.title().asString(parameters)).description(description == null ? null : description.asString(parameters)).source(pipelineEntity.source().asString(parameters)).createdAt(now).modifiedAt(now).build();
final PipelineDao savedPipelineDao = pipelineService.save(pipelineDao);
final String pipelineId = requireNonNull(savedPipelineDao.id(), "Saved pipeline ID must not be null");
final Set<EntityDescriptor> connectedStreamEntities = pipelineEntity.connectedStreams().stream().map(valueReference -> valueReference.asString(parameters)).map(streamId -> EntityDescriptor.create(streamId, ModelTypes.STREAM_V1)).collect(Collectors.toSet());
final Set<Stream> connectedStreams = connectedStreams(connectedStreamEntities, nativeEntities);
createPipelineConnections(pipelineId, connectedStreams);
return NativeEntity.create(entity.id(), pipelineId, TYPE_V1, savedPipelineDao.title(), savedPipelineDao);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacade method exportEntity.
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Configuration configuration = configurationService.find(modelId.id());
if (isNull(configuration)) {
LOG.debug("Couldn't find collector configuration {}", entityDescriptor);
return Optional.empty();
}
return Optional.of(exportNativeEntity(configuration, entityDescriptorIds));
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacade method resolveNativeEntity.
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
final Configuration configuration = configurationService.find(modelId.id());
if (isNull(configuration)) {
LOG.debug("Could not find configuration {}", entityDescriptor);
} else {
final EntityDescriptor collectorEntityDescriptor = EntityDescriptor.create(configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1);
mutableGraph.putEdge(entityDescriptor, collectorEntityDescriptor);
}
return ImmutableGraph.copyOf(mutableGraph);
}
Aggregations