private boolean userSpecifiedPathVerificator(Map<Spec, SpecExecutor> specExecutorInstanceMap, FlowSpec flowSpec) { Map<Spec, SpecExecutor> tmpSpecExecutorInstanceMap = new HashMap<>(); List<String> userSpecfiedPath = Arrays.asList(optionalUserSpecifiedPath.get().split(",")); for (int i = 0; i < userSpecfiedPath.size() - 1; i++) { ServiceNode sourceNode = new BaseServiceNodeImpl(userSpecfiedPath.get(i)); ServiceNode targetNode = new BaseServiceNodeImpl(userSpecfiedPath.get(i + 1)); if (weightedGraph.containsVertex(sourceNode) && weightedGraph.containsVertex(targetNode) && weightedGraph.containsEdge(sourceNode, targetNode)) { tmpSpecExecutorInstanceMap.put(convertHopToJobSpec(sourceNode, targetNode, flowSpec), (((LoadBasedFlowEdgeImpl) weightedGraph.getEdge(sourceNode, targetNode)).getSpecExecutorInstance())); } else { log.error("User Specified Path is invalid"); return false; } } specExecutorInstanceMap.putAll(tmpSpecExecutorInstanceMap); return true; }
@Override public void populateBlackListedEdges(DirectedWeightedMultigraph<ServiceNode, FlowEdge> graph) { for (ServiceNode node: serviceNodes) { if (graph.containsVertex(node)) { blacklistedEdges.addAll(graph.incomingEdgesOf(node)); blacklistedEdges.addAll(graph.outgoingEdgesOf(node)); } else { log.info("The graph " + graph + " doesn't contains node " + node.toString()); } } for( FlowEdge flowEdge: flowEdges) { if (graph.containsEdge(flowEdge)) { blacklistedEdges.add(flowEdge); } else { log.info("The graph " + graph + "doesn't contains edge " + flowEdge.toString()); } } } }
private void weightGraphGenerateHelper(TopologySpec topologySpec) { try { Map<ServiceNode, ServiceNode> capabilities = topologySpec.getSpecExecutor().getCapabilities().get(); for (Map.Entry<ServiceNode, ServiceNode> capability : capabilities.entrySet()) { BaseServiceNodeImpl sourceNode = new BaseServiceNodeImpl(capability.getKey().getNodeName()); BaseServiceNodeImpl targetNode = new BaseServiceNodeImpl(capability.getValue().getNodeName()); if (!weightedGraph.containsVertex(sourceNode)) { weightedGraph.addVertex(sourceNode); } if (!weightedGraph.containsVertex(targetNode)) { weightedGraph.addVertex(targetNode); } FlowEdge flowEdge = new LoadBasedFlowEdgeImpl(sourceNode, targetNode, defaultFlowEdgeProps, topologySpec.getSpecExecutor()); // In Multi-Graph if flowEdge existed, just skip it. if (!weightedGraph.containsEdge(flowEdge)) { weightedGraph.addEdge(sourceNode, targetNode, flowEdge); } } } catch (InterruptedException | ExecutionException e) { Instrumented.markMeter(this.flowCompilationFailedMeter); throw new RuntimeException("Cannot determine topology capabilities", e); } }
@Test public void testWeightedGraphConstruction(){ FlowSpec flowSpec = initFlowSpec(); TopologySpec topologySpec = initTopologySpec(TOPOLOGY_SPEC_STORE_DIR, TEST_SOURCE_NAME, TEST_HOP_NAME_A, TEST_HOP_NAME_B, TEST_SINK_NAME); this.compilerWithTemplateCalague.onAddSpec(topologySpec); // invocation of compileFlow trigger the weighedGraph construction this.compilerWithTemplateCalague.compileFlow(flowSpec); DirectedWeightedMultigraph<ServiceNode, FlowEdge> weightedGraph = compilerWithTemplateCalague.getWeightedGraph(); Assert.assertTrue(weightedGraph.containsVertex(vertexSource)); Assert.assertTrue(weightedGraph.containsVertex(vertexHopA)); Assert.assertTrue(weightedGraph.containsVertex(vertexHopB)); Assert.assertTrue(weightedGraph.containsVertex(vertexSink)); FlowEdge edgeSrc2A = new LoadBasedFlowEdgeImpl(vertexSource, vertexHopA, topologySpec.getSpecExecutor()); FlowEdge edgeA2B = new LoadBasedFlowEdgeImpl(vertexHopA, vertexHopB, topologySpec.getSpecExecutor()); FlowEdge edgeB2Sink = new LoadBasedFlowEdgeImpl(vertexHopB, vertexSink, topologySpec.getSpecExecutor()); Assert.assertTrue(weightedGraph.containsEdge(edgeSrc2A)); Assert.assertTrue(weightedGraph.containsEdge(edgeA2B)); Assert.assertTrue(weightedGraph.containsEdge(edgeB2Sink)); Assert.assertTrue(edgeEqual(weightedGraph.getEdge(vertexSource, vertexHopA), edgeSrc2A)); Assert.assertTrue(edgeEqual(weightedGraph.getEdge(vertexHopA, vertexHopB), edgeA2B)); Assert.assertTrue(edgeEqual(weightedGraph.getEdge(vertexHopB, vertexSink), edgeB2Sink)); this.compilerWithTemplateCalague.onDeleteSpec(topologySpec.getUri(), ""); }
private DirectedWeightedMultigraph<Node, LabeledLink> findModel(Node n) { for(DirectedWeightedMultigraph<Node, LabeledLink> model : this.models) { if(model.containsVertex(n)) return model; } return null; }
public HashMap<Integer, Set<Node>> getLevelToNodes(DirectedWeightedMultigraph<Node, LabeledLink> model, boolean considerColumnNodes) { HashMap<Integer, Set<Node>> levelToNodes = new HashMap<>(); if (this.nodesLevel == null) return levelToNodes; for (Entry<Node, Integer> entry : nodesLevel.entrySet()) { Set<Node> nodes = levelToNodes.get(entry.getValue()); if (nodes == null) { nodes = new HashSet<>(); levelToNodes.put(entry.getValue(), nodes); } if (!considerColumnNodes && entry.getKey() instanceof ColumnNode) continue; Node node = entry.getKey(); if(model == null || model.containsVertex(node)) nodes.add(node); } return levelToNodes; }
public boolean isNodeIsolatedInTree(String nodeId) { Node node = this.getNodeById(nodeId); if (node != null) { if (this.steinerTree != null && this.steinerTree.containsVertex(node)) { Set<LabeledLink> inLinks = this.steinerTree.edgesOf(node); if (inLinks == null || inLinks.isEmpty()) return true; } } logger.debug("Cannot find the link " + nodeId + " in the graph."); return false; }
@Override public void populateBlackListedEdges(DirectedWeightedMultigraph<ServiceNode, FlowEdge> graph) { for (ServiceNode node: serviceNodes) { if (graph.containsVertex(node)) { blacklistedEdges.addAll(graph.incomingEdgesOf(node)); blacklistedEdges.addAll(graph.outgoingEdgesOf(node)); } else { log.info("The graph " + graph + " doesn't contains node " + node.toString()); } } for( FlowEdge flowEdge: flowEdges) { if (graph.containsEdge(flowEdge)) { blacklistedEdges.add(flowEdge); } else { log.info("The graph " + graph + "doesn't contains edge " + flowEdge.toString()); } } } }
public Set<LabeledLink> getOutgoingEdgesOf(Node node) { Set<LabeledLink> edges = new HashSet<>(); for(DirectedWeightedMultigraph<Node, LabeledLink> model : models) { GraphUtil.printGraph(GraphUtil.asDefaultGraph(model)); if(model.containsVertex(node)) edges.addAll(model.outgoingEdgesOf(node)); } return edges; }
private void addForcedNodes() { Set<Node> forcedNodes = this.graphBuilder.getForcedNodes(); if (forcedNodes != null) for (Node node : forcedNodes) { if (!this.steinerTree.containsVertex(node)) { this.steinerTree.addVertex(node); } } }
private boolean userSpecifiedPathVerificator(Map<Spec, SpecExecutor> specExecutorInstanceMap, FlowSpec flowSpec) { Map<Spec, SpecExecutor> tmpSpecExecutorInstanceMap = new HashMap<>(); List<String> userSpecfiedPath = Arrays.asList(optionalUserSpecifiedPath.get().split(",")); for (int i = 0; i < userSpecfiedPath.size() - 1; i++) { ServiceNode sourceNode = new BaseServiceNodeImpl(userSpecfiedPath.get(i)); ServiceNode targetNode = new BaseServiceNodeImpl(userSpecfiedPath.get(i + 1)); if (weightedGraph.containsVertex(sourceNode) && weightedGraph.containsVertex(targetNode) && weightedGraph.containsEdge(sourceNode, targetNode)) { tmpSpecExecutorInstanceMap.put(convertHopToJobSpec(sourceNode, targetNode, flowSpec), (((LoadBasedFlowEdgeImpl) weightedGraph.getEdge(sourceNode, targetNode)).getSpecExecutorInstance())); } else { log.error("User Specified Path is invalid"); return false; } } specExecutorInstanceMap.putAll(tmpSpecExecutorInstanceMap); return true; }
private void addLinks(Set<LabeledLink> links) { if (links == null) return; for (LabeledLink link : links) { if (!this.tree.containsEdge(link) && this.tree.containsVertex(link.getSource()) && this.tree.containsVertex(link.getTarget())) { this.tree.addEdge(link.getSource(), link.getTarget(), link); } } }
public boolean removeNode(String nodeId) { Node node = this.getNodeById(nodeId); if (node != null) { node.setForced(false); this.graphBuilder.getForcedNodes().remove(node); if (this.steinerTree != null && this.steinerTree.containsVertex(node)) { Set<LabeledLink> links = this.steinerTree.edgesOf(node); if (links != null) { for (LabeledLink l : links) { this.changeLinkStatus(l.getId(), LinkStatus.Normal); } } this.steinerTree.removeVertex(node); return true; } } logger.debug("Cannot find the link " + nodeId + " in the graph."); return false; }
private void weightGraphGenerateHelper(TopologySpec topologySpec) { try { Map<ServiceNode, ServiceNode> capabilities = topologySpec.getSpecExecutor().getCapabilities().get(); for (Map.Entry<ServiceNode, ServiceNode> capability : capabilities.entrySet()) { BaseServiceNodeImpl sourceNode = new BaseServiceNodeImpl(capability.getKey().getNodeName()); BaseServiceNodeImpl targetNode = new BaseServiceNodeImpl(capability.getValue().getNodeName()); if (!weightedGraph.containsVertex(sourceNode)) { weightedGraph.addVertex(sourceNode); } if (!weightedGraph.containsVertex(targetNode)) { weightedGraph.addVertex(targetNode); } FlowEdge flowEdge = new LoadBasedFlowEdgeImpl(sourceNode, targetNode, defaultFlowEdgeProps, topologySpec.getSpecExecutor()); // In Multi-Graph if flowEdge existed, just skip it. if (!weightedGraph.containsEdge(flowEdge)) { weightedGraph.addEdge(sourceNode, targetNode, flowEdge); } } } catch (InterruptedException | ExecutionException e) { Instrumented.markMeter(this.flowCompilationFailedMeter); throw new RuntimeException("Cannot determine topology capabilities", e); } }
private void addForcedLinks() { Set<LabeledLink> forcedLinks = getLinksByStatus(LinkStatus.ForcedByUser); if (forcedLinks != null) for (LabeledLink link : forcedLinks) { if (!this.steinerTree.containsEdge(link)) { if (!this.steinerTree.containsVertex(link.getSource())) { this.steinerTree.addVertex(link.getSource()); } if (!this.steinerTree.containsVertex(link.getTarget())) { this.steinerTree.addVertex(link.getTarget()); } this.steinerTree.addEdge(link.getSource(), link.getTarget(), link); } } }