@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 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 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(), ""); }
@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 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 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 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); } } }
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); } } }