InferredNullability(Graph<InferenceVariable> constraints) { this.constraintGraph = ImmutableGraph.copyOf(constraints); }
/** * Returns an empty graph (immutable) initialized with all properties queryable from {@code graph}. * * @param graph The graph to use as template for the created graph * @param <N> The class of the nodes * @return an empty graph * @see GraphBuilder#from(Graph) */ public static <N> ImmutableGraph<N> emptyGraph(Graph<N> graph) { return ImmutableGraph.copyOf(GraphBuilder.from(graph).build()); }
/** * Returns an immutable directed graph, containing only the specified node. * * @param node The single node in the returned graph * @param <N> The class of the nodes * @return an immutable directed graph with a single node */ public static <N> ImmutableGraph<N> singletonDirectedGraph(N node) { final MutableGraph<N> graph = GraphBuilder.directed().build(); graph.addNode(node); return ImmutableGraph.copyOf(graph); }
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); } }
@Override public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) { final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entityDescriptor); final ModelId modelId = entityDescriptor.id(); final Optional<LookupTableDto> lookupTableDto = lookupTableService.get(modelId.id()); lookupTableDto.map(LookupTableDto::dataAdapterId) .map(this::adapterDescriptor) .ifPresent(dataAdapter -> mutableGraph.putEdge(entityDescriptor, dataAdapter)); lookupTableDto.map(LookupTableDto::cacheId) .map(this::cacheDescriptor) .ifPresent(cache -> mutableGraph.putEdge(entityDescriptor, cache)); return ImmutableGraph.copyOf(mutableGraph); }
/** * Create the dependency graph of a native entity described by the given entity descriptor. * * @param entityDescriptor the descriptor of the native entity to resolve dependencies for * @return A directed graph of the native entity with entity descriptors as nodes. * @see Graph */ default Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) { final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entityDescriptor); return ImmutableGraph.copyOf(mutableGraph); }
/** * Returns an immutable undirected graph, containing only the specified node. * * @param node The single node in the returned graph * @param <N> The class of the nodes * @return an immutable undirected graph with a single node */ public static <N> ImmutableGraph<N> singletonUndirectedGraph(N node) { final MutableGraph<N> graph = GraphBuilder.undirected().build(); graph.addNode(node); return ImmutableGraph.copyOf(graph); }
/** * Returns an immutable graph, containing only the specified node. * * @param graph The graph to use as template for the created graph * @param node The single node in the returned graph * @param <N> The class of the nodes * @return an immutable graph with a single node * @see GraphBuilder#from(Graph) */ public static <N> ImmutableGraph<N> singletonGraph(Graph<N> graph, N node) { final MutableGraph<N> mutableGraph = GraphBuilder.from(graph).build(); mutableGraph.addNode(node); return ImmutableGraph.copyOf(mutableGraph); }
/** * Create the dependency graph of an entity described by the given entity model during content pack installation. * * @param entity the entity model to resolve dependencies for * @return A directed graph of the native entity with entity models as nodes. * @see Graph */ default Graph<Entity> resolveForInstallation(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) { final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entity); return ImmutableGraph.copyOf(mutableGraph); } }
@Override public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) { final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entityDescriptor); final ModelId modelId = entityDescriptor.id(); try { final Stream stream = streamService.load(modelId.id()); stream.getOutputs().stream() .map(Output::getId) .map(ModelId::of) .map(id -> EntityDescriptor.create(id, ModelTypes.OUTPUT_V1)) .forEach(output -> mutableGraph.putEdge(entityDescriptor, output)); } catch (NotFoundException e) { LOG.debug("Couldn't find stream {}", entityDescriptor, e); } return ImmutableGraph.copyOf(mutableGraph); }
private Graph<Entity> resolveForInstallationV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) { final MutableGraph<Entity> graph = GraphBuilder.directed().build(); graph.addNode(entity); final InputEntity input = objectMapper.convertValue(entity.data(), InputEntity.class); resolveForInstallationV1LookupTable(entity, input, parameters, entities, graph); resolveForInstallationV1GrokPattern(entity, input, parameters, entities, graph); return ImmutableGraph.copyOf(graph); }
private static <N> ImmutableGraph<N> graphWithNode(N node) { MutableGraph<N> graph = GraphBuilder.directed().build(); graph.addNode(node); return ImmutableGraph.copyOf(graph); }
private static ImmutableGraph<Character> createSingleRootGraph() { MutableGraph<Character> graph = GraphBuilder.directed().build(); graph.addNode('a'); return ImmutableGraph.copyOf(graph); }
private Graph<Entity> resolveEntityV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) { final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entity); final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class); final EntityDescriptor collectorDescriptor = EntityDescriptor.create(configurationEntity.collectorId().asString(parameters), ModelTypes.SIDECAR_COLLECTOR_V1); final Entity collectorEntity = entities.get(collectorDescriptor); if (collectorEntity != null) { mutableGraph.putEdge(entity, collectorEntity); } return ImmutableGraph.copyOf(mutableGraph); } }
@Override public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) { final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entityDescriptor); final ModelId modelId = entityDescriptor.id(); try { final Input input = inputService.find(modelId.toString()); final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input)); resolveNativeEntityLookupTable(entityDescriptor, inputWithExtractors, mutableGraph); resolveNativeEntityGrokPattern(entityDescriptor, inputWithExtractors, mutableGraph); return ImmutableGraph.copyOf(mutableGraph); } catch (NotFoundException e) { LOG.debug("Couldn't find input {}", entityDescriptor, e); } return ImmutableGraph.copyOf(mutableGraph); }
@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); }
@Override public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) { final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entityDescriptor); final ModelId modelId = entityDescriptor.id(); try { final Dashboard dashboard = dashboardService.load(modelId.id()); for (DashboardWidget widget : dashboard.getWidgets().values()) { final String streamId = (String) widget.getConfig().get("stream_id"); if (!isNullOrEmpty(streamId)) { LOG.debug("Adding stream <{}> as dependency of widget <{}> on dashboard <{}>", streamId, widget.getId(), dashboard.getId()); final EntityDescriptor stream = EntityDescriptor.create(streamId, ModelTypes.STREAM_V1); mutableGraph.putEdge(entityDescriptor, stream); } } } catch (NotFoundException e) { LOG.debug("Couldn't find dashboard {}", entityDescriptor, e); } return ImmutableGraph.copyOf(mutableGraph); }
@Test public void immutableGraph() { MutableGraph<String> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode("A"); ImmutableGraph<String> immutableGraph = ImmutableGraph.copyOf(mutableGraph); assertThat(immutableGraph).isNotInstanceOf(MutableValueGraph.class); assertThat(immutableGraph).isEqualTo(mutableGraph); mutableGraph.addNode("B"); assertThat(immutableGraph).isNotEqualTo(mutableGraph); }
static <N> void validateGraph(Graph<N> graph) { assertStronglyEquivalent(graph, Graphs.copyOf(graph)); assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));