Search in sources :

Example 6 with ServiceNode

use of org.apache.gobblin.runtime.api.ServiceNode 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 7 with ServiceNode

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

the class MultiHopsFlowToJobSpecCompiler method jobSpecURIGenerator.

/**
 * A naive implementation of generating a jobSpec's URI within a multi-hop logical Flow.
 */
@Override
public URI jobSpecURIGenerator(Object... objects) {
    FlowSpec flowSpec = (FlowSpec) objects[0];
    ServiceNode sourceNode = (ServiceNode) objects[1];
    ServiceNode targetNode = (ServiceNode) objects[2];
    try {
        return new URI(JobSpec.Builder.DEFAULT_JOB_CATALOG_SCHEME, flowSpec.getUri().getAuthority(), StringUtils.appendIfMissing(StringUtils.prependIfMissing(flowSpec.getUri().getPath(), "/"), "/") + sourceNode.getNodeName() + "-" + targetNode.getNodeName(), null);
    } catch (URISyntaxException e) {
        log.error("URI construction failed when jobSpec from " + sourceNode.getNodeName() + " to " + targetNode.getNodeName());
        throw new RuntimeException();
    }
}
Also used : ServiceNode(org.apache.gobblin.runtime.api.ServiceNode) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 8 with ServiceNode

use of org.apache.gobblin.runtime.api.ServiceNode 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

ServiceNode (org.apache.gobblin.runtime.api.ServiceNode)8 FlowSpec (org.apache.gobblin.runtime.api.FlowSpec)6 FlowEdge (org.apache.gobblin.runtime.api.FlowEdge)5 TopologySpec (org.apache.gobblin.runtime.api.TopologySpec)4 BaseServiceNodeImpl (org.apache.gobblin.runtime.spec_executorInstance.BaseServiceNodeImpl)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 JobSpec (org.apache.gobblin.runtime.api.JobSpec)2 Spec (org.apache.gobblin.runtime.api.Spec)2 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)2 Test (org.testng.annotations.Test)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ResolvedJobSpec (org.apache.gobblin.runtime.job_spec.ResolvedJobSpec)1 InMemorySpecExecutor (org.apache.gobblin.runtime.spec_executorInstance.InMemorySpecExecutor)1 LoadBasedFlowEdgeImpl (org.apache.gobblin.service.modules.flow.LoadBasedFlowEdgeImpl)1