Search in sources :

Example 6 with FlowSpec

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

the class MultiHopsFlowToJobSpecCompilerTest method testServicePolicy.

@Test
public void testServicePolicy() {
    // Initialize compiler with some blacklist properties
    Properties properties = new Properties();
    properties.setProperty(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY, TEST_TEMPLATE_CATALOG_URI);
    String testPath = TEST_SOURCE_NAME + "," + TEST_HOP_NAME_A + "," + TEST_HOP_NAME_B + "," + TEST_SINK_NAME;
    properties.setProperty(ServiceConfigKeys.POLICY_BASED_DATA_MOVEMENT_PATH, testPath);
    properties.setProperty(ServiceConfigKeys.POLICY_BASED_BLOCKED_NODES, "testHopA");
    MultiHopsFlowToJobSpecCompiler compiler = new MultiHopsFlowToJobSpecCompiler(ConfigUtils.propertiesToConfig(properties));
    FlowSpec flowSpec = initFlowSpec();
    TopologySpec topologySpec = initTopologySpec(TOPOLOGY_SPEC_STORE_DIR, TEST_SOURCE_NAME, TEST_HOP_NAME_A, TEST_HOP_NAME_B, TEST_SINK_NAME);
    compiler.onAddSpec(topologySpec);
    // invocation of compileFlow trigger the weighedGraph construction
    compiler.compileFlow(flowSpec);
    compiler.servicePolicy.populateBlackListedEdges(compiler.getWeightedGraph());
    Assert.assertEquals(compiler.servicePolicy.getBlacklistedEdges().size(), 2);
    FlowEdge edgeSrc2A = new LoadBasedFlowEdgeImpl(vertexSource, vertexHopA, topologySpec.getSpecExecutor());
    FlowEdge edgeA2B = new LoadBasedFlowEdgeImpl(vertexHopA, vertexHopB, topologySpec.getSpecExecutor());
    Assert.assertTrue(compiler.servicePolicy.getBlacklistedEdges().contains(edgeSrc2A));
    Assert.assertTrue(compiler.servicePolicy.getBlacklistedEdges().contains(edgeA2B));
}
Also used : FlowEdge(org.apache.gobblin.runtime.api.FlowEdge) LoadBasedFlowEdgeImpl(org.apache.gobblin.service.modules.flow.LoadBasedFlowEdgeImpl) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) Properties(java.util.Properties) TopologySpec(org.apache.gobblin.runtime.api.TopologySpec) MultiHopsFlowToJobSpecCompiler(org.apache.gobblin.service.modules.flow.MultiHopsFlowToJobSpecCompiler) Test(org.testng.annotations.Test)

Example 7 with FlowSpec

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

the class Orchestrator method orchestrate.

public void orchestrate(Spec spec) throws Exception {
    // Add below waiting because TopologyCatalog and FlowCatalog service can be launched at the same time
    this.topologyCatalog.get().getInitComplete().await();
    long startTime = System.nanoTime();
    if (spec instanceof FlowSpec) {
        Map<Spec, SpecExecutor> specExecutorInstanceMap = specCompiler.compileFlow(spec);
        if (specExecutorInstanceMap.isEmpty()) {
            _log.warn("Cannot determine an executor to run on for Spec: " + spec);
            return;
        }
        // Schedule all compiled JobSpecs on their respective Executor
        for (Map.Entry<Spec, SpecExecutor> specsToExecute : specExecutorInstanceMap.entrySet()) {
            // Run this spec on selected executor
            SpecProducer producer = null;
            try {
                producer = specsToExecute.getValue().getProducer().get();
                Spec jobSpec = specsToExecute.getKey();
                _log.info(String.format("Going to orchestrate JobSpec: %s on Executor: %s", jobSpec, producer));
                producer.addSpec(jobSpec);
            } catch (Exception e) {
                _log.error("Cannot successfully setup spec: " + specsToExecute.getKey() + " on executor: " + producer + " for flow: " + spec, e);
            }
        }
    } else {
        Instrumented.markMeter(this.flowOrchestrationFailedMeter);
        throw new RuntimeException("Spec not of type FlowSpec, cannot orchestrate: " + spec);
    }
    Instrumented.markMeter(this.flowOrchestrationSuccessFulMeter);
    Instrumented.updateTimer(this.flowOrchestrationTimer, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
}
Also used : SpecProducer(org.apache.gobblin.runtime.api.SpecProducer) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) SpecExecutor(org.apache.gobblin.runtime.api.SpecExecutor) TopologySpec(org.apache.gobblin.runtime.api.TopologySpec) Spec(org.apache.gobblin.runtime.api.Spec) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with FlowSpec

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

the class Orchestrator method remove.

public void remove(Spec spec) {
    // Note: Current logic assumes compilation is consistent between all executions
    if (spec instanceof FlowSpec) {
        Map<Spec, SpecExecutor> specExecutorInstanceMap = specCompiler.compileFlow(spec);
        if (specExecutorInstanceMap.isEmpty()) {
            _log.warn("Cannot determine an executor to delete Spec: " + spec);
            return;
        }
        // Delete all compiled JobSpecs on their respective Executor
        for (Map.Entry<Spec, SpecExecutor> specsToDelete : specExecutorInstanceMap.entrySet()) {
            // Delete this spec on selected executor
            SpecProducer producer = null;
            try {
                producer = specsToDelete.getValue().getProducer().get();
                Spec jobSpec = specsToDelete.getKey();
                _log.info(String.format("Going to delete JobSpec: %s on Executor: %s", jobSpec, producer));
                producer.deleteSpec(jobSpec.getUri());
            } catch (Exception e) {
                _log.error("Cannot successfully delete spec: " + specsToDelete.getKey() + " on executor: " + producer + " for flow: " + spec, e);
            }
        }
    } else {
        throw new RuntimeException("Spec not of type FlowSpec, cannot delete: " + spec);
    }
}
Also used : SpecProducer(org.apache.gobblin.runtime.api.SpecProducer) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) SpecExecutor(org.apache.gobblin.runtime.api.SpecExecutor) TopologySpec(org.apache.gobblin.runtime.api.TopologySpec) Spec(org.apache.gobblin.runtime.api.Spec) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with FlowSpec

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

the class GobblinServiceJobScheduler method disableFlowRunImmediatelyOnStart.

@VisibleForTesting
protected static Spec disableFlowRunImmediatelyOnStart(FlowSpec spec) {
    Properties properties = spec.getConfigAsProperties();
    properties.setProperty(ConfigurationKeys.FLOW_RUN_IMMEDIATELY, "false");
    Config config = ConfigFactory.parseProperties(properties);
    FlowSpec flowSpec = new FlowSpec(spec.getUri(), spec.getVersion(), spec.getDescription(), config, properties, spec.getTemplateURIs(), spec.getChildSpecs());
    return flowSpec;
}
Also used : Config(com.typesafe.config.Config) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) Properties(java.util.Properties) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with FlowSpec

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

the class GobblinServiceJobScheduler method runJob.

@Override
public void runJob(Properties jobProps, JobListener jobListener) throws JobException {
    try {
        Spec flowSpec = this.scheduledFlowSpecs.get(jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY));
        this.orchestrator.orchestrate(flowSpec);
    } catch (Exception e) {
        throw new JobException("Failed to run Spec: " + jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY), e);
    }
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobException(org.apache.gobblin.runtime.JobException) Spec(org.apache.gobblin.runtime.api.Spec) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) JobExecutionException(org.quartz.JobExecutionException) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobException(org.apache.gobblin.runtime.JobException)

Aggregations

FlowSpec (org.apache.gobblin.runtime.api.FlowSpec)32 Spec (org.apache.gobblin.runtime.api.Spec)18 Test (org.testng.annotations.Test)16 URI (java.net.URI)12 TopologySpec (org.apache.gobblin.runtime.api.TopologySpec)12 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)10 Properties (java.util.Properties)9 Config (com.typesafe.config.Config)7 InMemorySpecExecutor (org.apache.gobblin.runtime.spec_executorInstance.InMemorySpecExecutor)7 URISyntaxException (java.net.URISyntaxException)6 ServiceNode (org.apache.gobblin.runtime.api.ServiceNode)6 JobSpec (org.apache.gobblin.runtime.api.JobSpec)5 RefSpec (org.eclipse.jgit.transport.RefSpec)5 FlowEdge (org.apache.gobblin.runtime.api.FlowEdge)4 Map (java.util.Map)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 JobException (org.apache.gobblin.runtime.JobException)2 SpecProducer (org.apache.gobblin.runtime.api.SpecProducer)2 BaseServiceNodeImpl (org.apache.gobblin.runtime.spec_executorInstance.BaseServiceNodeImpl)2