Search in sources :

Example 6 with ExecutionPlan

use of org.apache.samza.execution.ExecutionPlan in project samza by apache.

the class LocalApplicationRunner method run.

@Override
public void run(StreamApplication app) {
    try {
        // 1. initialize and plan
        ExecutionPlan plan = getExecutionPlan(app);
        writePlanJsonFile(plan.getPlanAsJson());
        // 2. create the necessary streams
        createStreams(plan.getIntermediateStreams());
        // 3. create the StreamProcessors
        if (plan.getJobConfigs().isEmpty()) {
            throw new SamzaException("No jobs to run.");
        }
        plan.getJobConfigs().forEach(jobConfig -> {
            log.debug("Starting job {} StreamProcessor with config {}", jobConfig.getName(), jobConfig);
            LocalStreamProcessorLifeCycleListener listener = new LocalStreamProcessorLifeCycleListener();
            StreamProcessor processor = createStreamProcessor(jobConfig, app, listener);
            listener.setProcessor(processor);
            processors.add(processor);
        });
        numProcessorsToStart.set(processors.size());
        // 4. start the StreamProcessors
        processors.forEach(StreamProcessor::start);
    } catch (Exception e) {
        throw new SamzaException("Failed to start application", e);
    }
}
Also used : StreamProcessor(org.apache.samza.processor.StreamProcessor) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) SamzaException(org.apache.samza.SamzaException) SamzaException(org.apache.samza.SamzaException)

Example 7 with ExecutionPlan

use of org.apache.samza.execution.ExecutionPlan in project samza by apache.

the class RemoteApplicationRunner method run.

/**
   * Run the {@link StreamApplication} on the remote cluster
   * @param app a StreamApplication
   */
@Override
public void run(StreamApplication app) {
    try {
        // 1. initialize and plan
        ExecutionPlan plan = getExecutionPlan(app);
        writePlanJsonFile(plan.getPlanAsJson());
        // 2. create the necessary streams
        getStreamManager().createStreams(plan.getIntermediateStreams());
        // 3. submit jobs for remote execution
        plan.getJobConfigs().forEach(jobConfig -> {
            log.info("Starting job {} with config {}", jobConfig.getName(), jobConfig);
            JobRunner runner = new JobRunner(jobConfig);
            runner.run(true);
        });
    } catch (Throwable t) {
        throw new SamzaException("Failed to run application", t);
    }
}
Also used : JobRunner(org.apache.samza.job.JobRunner) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) SamzaException(org.apache.samza.SamzaException)

Example 8 with ExecutionPlan

use of org.apache.samza.execution.ExecutionPlan in project samza by apache.

the class RemoteApplicationRunner method kill.

@Override
public void kill(StreamApplication app) {
    try {
        ExecutionPlan plan = getExecutionPlan(app);
        plan.getJobConfigs().forEach(jobConfig -> {
            log.info("Killing job {}", jobConfig.getName());
            JobRunner runner = new JobRunner(jobConfig);
            runner.kill();
        });
    } catch (Throwable t) {
        throw new SamzaException("Failed to kill application", t);
    }
}
Also used : JobRunner(org.apache.samza.job.JobRunner) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) SamzaException(org.apache.samza.SamzaException)

Aggregations

ExecutionPlan (org.apache.samza.execution.ExecutionPlan)8 JobConfig (org.apache.samza.config.JobConfig)5 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 SamzaException (org.apache.samza.SamzaException)4 StreamApplication (org.apache.samza.application.StreamApplication)4 MapConfig (org.apache.samza.config.MapConfig)4 ExecutionPlanner (org.apache.samza.execution.ExecutionPlanner)4 StreamSpec (org.apache.samza.system.StreamSpec)4 Test (org.junit.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)4 JobRunner (org.apache.samza.job.JobRunner)3 StreamProcessor (org.apache.samza.processor.StreamProcessor)3 List (java.util.List)2 StreamManager (org.apache.samza.execution.StreamManager)2 StreamProcessorLifecycleListener (org.apache.samza.processor.StreamProcessorLifecycleListener)2 TimeUnit (java.util.concurrent.TimeUnit)1 CoordinationUtils (org.apache.samza.coordinator.CoordinationUtils)1 Latch (org.apache.samza.coordinator.Latch)1 LeaderElector (org.apache.samza.coordinator.LeaderElector)1