use of com.google.common.graph.Graph 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 com.google.common.graph.Graph 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 com.google.common.graph.Graph in project graylog2-server by Graylog2.
the class StreamFacade 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 StreamEntity streamEntity = objectMapper.convertValue(entity.data(), StreamEntity.class);
streamEntity.outputs().stream().map(valueReference -> valueReference.asString(parameters)).map(ModelId::of).map(modelId -> EntityDescriptor.create(modelId, ModelTypes.OUTPUT_V1)).map(entities::get).filter(Objects::nonNull).forEach(outputEntity -> mutableGraph.putEdge(entity, outputEntity));
return ImmutableGraph.copyOf(mutableGraph);
}
use of com.google.common.graph.Graph in project graylog2-server by Graylog2.
the class ViewFacadeTest method itShouldResolveDependencyForCreation.
@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldResolveDependencyForCreation() {
final EntityDescriptor streamEntityDescriptor = EntityDescriptor.create(streamId, ModelTypes.STREAM_V1);
final EntityDescriptor viewEntityDescriptor = EntityDescriptor.create(viewId, ModelTypes.SEARCH_V1);
Graph graph = facade.resolveNativeEntity(viewEntityDescriptor);
assertThat(graph.nodes().toArray()).contains(streamEntityDescriptor);
}
use of com.google.common.graph.Graph in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method resolveMatchingDependecyForCreation.
@Test
public void resolveMatchingDependecyForCreation() throws ValidationException {
final GrokPattern noDepGrokPattern = grokPatternService.save(GrokPattern.create("HALFLIFE", "\\d\\d"));
final EntityDescriptor noDepEntityDescriptor = EntityDescriptor.create(ModelId.of(noDepGrokPattern.id()), ModelTypes.GROK_PATTERN_V1);
final GrokPattern depGrokPattern = grokPatternService.save(GrokPattern.create("PORTAL", "\\d\\d"));
final EntityDescriptor depEntityDescriptor = EntityDescriptor.create(ModelId.of(depGrokPattern.id()), ModelTypes.GROK_PATTERN_V1);
final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test", "%{PORTAL}"));
final EntityDescriptor entityDescriptor = EntityDescriptor.create(ModelId.of(grokPattern.id()), ModelTypes.GROK_PATTERN_V1);
Graph graph = facade.resolveNativeEntity(entityDescriptor);
assertThat(graph.nodes().toArray()).contains(depEntityDescriptor);
assertThat(graph.nodes().toArray()).doesNotContain(noDepEntityDescriptor);
}
Aggregations