Search in sources :

Example 6 with FlowEdge

use of org.apache.gobblin.runtime.api.FlowEdge in project incubator-gobblin by apache.

the class MultiHopsFlowToJobSpecCompiler method findPath.

// Basically a dijkstra path finding for connecting source and sink by multiple hops in between.
// If there's any user-specified prioritization, conduct the DFS and see if the user-specified path is available.
// there's no updates on TopologySpec, or user should be aware of the possibility
// that a topologySpec not being reflected in findPath.
private void findPath(Map<Spec, SpecExecutor> specExecutorInstanceMap, Spec spec) {
    inMemoryWeightGraphGenerator();
    FlowSpec flowSpec = (FlowSpec) spec;
    if (optionalUserSpecifiedPath.isPresent()) {
        log.info("Starting to evaluate user's specified path ... ");
        if (userSpecifiedPathVerificator(specExecutorInstanceMap, flowSpec)) {
            log.info("User specified path[ " + optionalUserSpecifiedPath.get() + "] successfully verified.");
            return;
        } else {
            log.error("Will not execute user specified path[ " + optionalUserSpecifiedPath.get() + "]");
            log.info("Start to execute FlowCompiler's algorithm for valid data movement path");
        }
    }
    ServiceNode sourceNode = new BaseServiceNodeImpl(flowSpec.getConfig().getString(ServiceConfigKeys.FLOW_SOURCE_IDENTIFIER_KEY));
    ServiceNode targetNode = new BaseServiceNodeImpl(flowSpec.getConfig().getString(ServiceConfigKeys.FLOW_DESTINATION_IDENTIFIER_KEY));
    List<FlowEdge> resultEdgePath = dijkstraBasedPathFindingHelper(sourceNode, targetNode, this.weightedGraph);
    for (int i = 0; i < resultEdgePath.size(); i++) {
        FlowEdge tmpFlowEdge = resultEdgePath.get(i);
        ServiceNode edgeSrcNode = ((LoadBasedFlowEdgeImpl) tmpFlowEdge).getSourceNode();
        ServiceNode edgeTgtNode = ((LoadBasedFlowEdgeImpl) tmpFlowEdge).getTargetNode();
        specExecutorInstanceMap.put(convertHopToJobSpec(edgeSrcNode, edgeTgtNode, flowSpec), ((LoadBasedFlowEdgeImpl) (resultEdgePath.get(i))).getSpecExecutorInstance());
    }
}
Also used : FlowEdge(org.apache.gobblin.runtime.api.FlowEdge) ServiceNode(org.apache.gobblin.runtime.api.ServiceNode) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) BaseServiceNodeImpl(org.apache.gobblin.runtime.spec_executorInstance.BaseServiceNodeImpl)

Example 7 with FlowEdge

use of org.apache.gobblin.runtime.api.FlowEdge in project incubator-gobblin by apache.

the class MultiHopsFlowToJobSpecCompiler method convertHopToJobSpec.

/**
 * A naive implementation of resolving templates in each JobSpec among Multi-hop FlowSpec.
 * Handle the case when edge is not specified.
 * Always select the first available template.
 */
private JobSpec convertHopToJobSpec(ServiceNode sourceNode, ServiceNode targetNode, FlowSpec flowSpec) {
    FlowEdge flowEdge = weightedGraph.getAllEdges(sourceNode, targetNode).iterator().next();
    URI templateURI = getTemplateURI(sourceNode, targetNode, flowSpec, flowEdge);
    return buildJobSpec(sourceNode, targetNode, templateURI, flowSpec);
}
Also used : FlowEdge(org.apache.gobblin.runtime.api.FlowEdge) URI(java.net.URI)

Example 8 with FlowEdge

use of org.apache.gobblin.runtime.api.FlowEdge in project incubator-gobblin by apache.

the class MultiHopsFlowToJobSpecCompiler method weightGraphGenerateHelper.

// Helper function for transform TopologySpecMap into a weightedDirectedGraph.
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);
    }
}
Also used : FlowEdge(org.apache.gobblin.runtime.api.FlowEdge) ServiceNode(org.apache.gobblin.runtime.api.ServiceNode) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) BaseServiceNodeImpl(org.apache.gobblin.runtime.spec_executorInstance.BaseServiceNodeImpl)

Example 9 with FlowEdge

use of org.apache.gobblin.runtime.api.FlowEdge in project incubator-gobblin by apache.

the class StaticServicePolicy method populateBlackListedEdges.

@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());
        }
    }
}
Also used : FlowEdge(org.apache.gobblin.runtime.api.FlowEdge) ServiceNode(org.apache.gobblin.runtime.api.ServiceNode)

Aggregations

FlowEdge (org.apache.gobblin.runtime.api.FlowEdge)9 ServiceNode (org.apache.gobblin.runtime.api.ServiceNode)5 FlowSpec (org.apache.gobblin.runtime.api.FlowSpec)4 TopologySpec (org.apache.gobblin.runtime.api.TopologySpec)3 Test (org.testng.annotations.Test)3 HashMap (java.util.HashMap)2 BaseServiceNodeImpl (org.apache.gobblin.runtime.spec_executorInstance.BaseServiceNodeImpl)2 LoadBasedFlowEdgeImpl (org.apache.gobblin.service.modules.flow.LoadBasedFlowEdgeImpl)2 VisibleForTesting (avro.shaded.com.google.common.annotations.VisibleForTesting)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 PriorityQueue (java.util.PriorityQueue)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 MultiHopsFlowToJobSpecCompiler (org.apache.gobblin.service.modules.flow.MultiHopsFlowToJobSpecCompiler)1