Search in sources :

Example 1 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class RemoteApplicationRunner method status.

@Override
public ApplicationStatus status(StreamApplication app) {
    try {
        boolean hasNewJobs = false;
        boolean hasRunningJobs = false;
        ApplicationStatus unsuccessfulFinishStatus = null;
        ExecutionPlan plan = getExecutionPlan(app);
        for (JobConfig jobConfig : plan.getJobConfigs()) {
            JobRunner runner = new JobRunner(jobConfig);
            ApplicationStatus status = runner.status();
            log.debug("Status is {} for job {}", new Object[] { status, jobConfig.getName() });
            switch(status.getStatusCode()) {
                case New:
                    hasNewJobs = true;
                    break;
                case Running:
                    hasRunningJobs = true;
                    break;
                case UnsuccessfulFinish:
                    unsuccessfulFinishStatus = status;
                    break;
                case SuccessfulFinish:
                    break;
                default:
            }
        }
        if (hasNewJobs) {
            // There are jobs not started, report as New
            return ApplicationStatus.New;
        } else if (hasRunningJobs) {
            // All jobs are started, some are running
            return ApplicationStatus.Running;
        } else if (unsuccessfulFinishStatus != null) {
            // All jobs are finished, some are not successful
            return unsuccessfulFinishStatus;
        } else {
            // All jobs are finished successfully
            return ApplicationStatus.SuccessfulFinish;
        }
    } catch (Throwable t) {
        throw new SamzaException("Failed to get status for application", t);
    }
}
Also used : JobRunner(org.apache.samza.job.JobRunner) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) ApplicationStatus(org.apache.samza.job.ApplicationStatus) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig)

Example 2 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class TestLocalApplicationRunner method testStreamCreation.

@Test
public void testStreamCreation() throws Exception {
    Map<String, String> config = new HashMap<>();
    LocalApplicationRunner runner = new LocalApplicationRunner(new MapConfig(config));
    StreamApplication app = mock(StreamApplication.class);
    doNothing().when(app).init(anyObject(), anyObject());
    ExecutionPlanner planner = mock(ExecutionPlanner.class);
    Field plannerField = runner.getClass().getSuperclass().getDeclaredField("planner");
    plannerField.setAccessible(true);
    plannerField.set(runner, planner);
    StreamManager streamManager = mock(StreamManager.class);
    Field streamManagerField = runner.getClass().getSuperclass().getDeclaredField("streamManager");
    streamManagerField.setAccessible(true);
    streamManagerField.set(runner, streamManager);
    ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
    ExecutionPlan plan = new ExecutionPlan() {

        @Override
        public List<JobConfig> getJobConfigs() {
            return Collections.emptyList();
        }

        @Override
        public List<StreamSpec> getIntermediateStreams() {
            return Collections.singletonList(new StreamSpec("test-stream", "test-stream", "test-system"));
        }

        @Override
        public String getPlanAsJson() throws Exception {
            return "";
        }
    };
    when(planner.plan(anyObject())).thenReturn(plan);
    LocalApplicationRunner spy = spy(runner);
    try {
        spy.run(app);
    } catch (Throwable t) {
        //no jobs exception
        assertNotNull(t);
    }
    verify(streamManager).createStreams(captor.capture());
    List<StreamSpec> streamSpecs = captor.getValue();
    assertEquals(streamSpecs.size(), 1);
    assertEquals(streamSpecs.get(0).getId(), "test-stream");
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) HashMap(java.util.HashMap) StreamApplication(org.apache.samza.application.StreamApplication) ExecutionPlanner(org.apache.samza.execution.ExecutionPlanner) Matchers.anyString(org.mockito.Matchers.anyString) JobConfig(org.apache.samza.config.JobConfig) Field(java.lang.reflect.Field) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) StreamManager(org.apache.samza.execution.StreamManager) List(java.util.List) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 3 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class TestLocalApplicationRunner method testRunFailure.

@Test
public void testRunFailure() throws Exception {
    final Map<String, String> config = new HashMap<>();
    config.put(ApplicationConfig.PROCESSOR_ID, "0");
    LocalApplicationRunner runner = new LocalApplicationRunner(new MapConfig(config));
    StreamApplication app = mock(StreamApplication.class);
    doNothing().when(app).init(anyObject(), anyObject());
    ExecutionPlanner planner = mock(ExecutionPlanner.class);
    Field plannerField = runner.getClass().getSuperclass().getDeclaredField("planner");
    plannerField.setAccessible(true);
    plannerField.set(runner, planner);
    ExecutionPlan plan = new ExecutionPlan() {

        @Override
        public List<JobConfig> getJobConfigs() {
            return Collections.singletonList(new JobConfig(new MapConfig(config)));
        }

        @Override
        public List<StreamSpec> getIntermediateStreams() {
            return Collections.emptyList();
        }

        @Override
        public String getPlanAsJson() throws Exception {
            return "";
        }
    };
    when(planner.plan(anyObject())).thenReturn(plan);
    Throwable t = new Throwable("test failure");
    StreamProcessor sp = mock(StreamProcessor.class);
    ArgumentCaptor<StreamProcessorLifecycleListener> captor = ArgumentCaptor.forClass(StreamProcessorLifecycleListener.class);
    doAnswer(i -> {
        StreamProcessorLifecycleListener listener = captor.getValue();
        listener.onFailure(t);
        return null;
    }).when(sp).start();
    LocalApplicationRunner spy = spy(runner);
    doReturn(sp).when(spy).createStreamProcessor(anyObject(), anyObject(), captor.capture());
    try {
        spy.run(app);
    } catch (Throwable th) {
        assertNotNull(th);
    }
    assertEquals(spy.status(app), ApplicationStatus.UnsuccessfulFinish);
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) StreamProcessor(org.apache.samza.processor.StreamProcessor) HashMap(java.util.HashMap) StreamApplication(org.apache.samza.application.StreamApplication) ExecutionPlanner(org.apache.samza.execution.ExecutionPlanner) Matchers.anyString(org.mockito.Matchers.anyString) StreamProcessorLifecycleListener(org.apache.samza.processor.StreamProcessorLifecycleListener) JobConfig(org.apache.samza.config.JobConfig) Field(java.lang.reflect.Field) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 4 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class YarnJobValidationTool method main.

public static void main(String[] args) throws Exception {
    CommandLine cmdline = new CommandLine();
    OptionParser parser = cmdline.parser();
    OptionSpec<String> validatorOpt = parser.accepts("metrics-validator", "The metrics validator class.").withOptionalArg().ofType(String.class).describedAs("com.foo.bar.ClassName");
    OptionSet options = cmdline.parser().parse(args);
    Config config = cmdline.loadConfig(options);
    MetricsValidator validator = null;
    if (options.has(validatorOpt)) {
        String validatorClass = options.valueOf(validatorOpt);
        validator = ClassLoaderHelper.<MetricsValidator>fromClassName(validatorClass);
    }
    YarnConfiguration hadoopConfig = new YarnConfiguration();
    hadoopConfig.set("fs.http.impl", HttpFileSystem.class.getName());
    hadoopConfig.set("fs.https.impl", HttpFileSystem.class.getName());
    ClientHelper clientHelper = new ClientHelper(hadoopConfig);
    new YarnJobValidationTool(new JobConfig(config), clientHelper.yarnClient(), validator).run();
}
Also used : CommandLine(org.apache.samza.util.CommandLine) ClientHelper(org.apache.samza.job.yarn.ClientHelper) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) JobConfig(org.apache.samza.config.JobConfig) Config(org.apache.samza.config.Config) HttpFileSystem(org.apache.samza.util.hadoop.HttpFileSystem) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) JobConfig(org.apache.samza.config.JobConfig) MetricsValidator(org.apache.samza.metrics.MetricsValidator)

Example 5 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class TestExecutionPlanner method testTriggerIntervalWithInvalidWindowMs.

@Test
public void testTriggerIntervalWithInvalidWindowMs() throws Exception {
    Map<String, String> map = new HashMap<>(config);
    map.put(TaskConfig.WINDOW_MS(), "-1");
    map.put(JobConfig.JOB_INTERMEDIATE_STREAM_PARTITIONS(), String.valueOf(DEFAULT_PARTITIONS));
    Config cfg = new MapConfig(map);
    ExecutionPlanner planner = new ExecutionPlanner(cfg, streamManager);
    StreamGraphImpl streamGraph = createStreamGraphWithJoinAndWindow();
    ExecutionPlan plan = planner.plan(streamGraph);
    List<JobConfig> jobConfigs = plan.getJobConfigs();
    assertEquals(jobConfigs.size(), 1);
    // GCD of 8, 16, 1600 and 252 is 4
    assertEquals(jobConfigs.get(0).get(TaskConfig.WINDOW_MS()), "4");
}
Also used : HashMap(java.util.HashMap) JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) TaskConfig(org.apache.samza.config.TaskConfig) Config(org.apache.samza.config.Config) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) MapConfig(org.apache.samza.config.MapConfig) JobConfig(org.apache.samza.config.JobConfig) Test(org.junit.Test)

Aggregations

JobConfig (org.apache.samza.config.JobConfig)13 HashMap (java.util.HashMap)10 MapConfig (org.apache.samza.config.MapConfig)10 Test (org.junit.Test)9 Config (org.apache.samza.config.Config)8 TaskConfig (org.apache.samza.config.TaskConfig)6 StreamGraphImpl (org.apache.samza.operators.StreamGraphImpl)6 StreamApplication (org.apache.samza.application.StreamApplication)5 ExecutionPlan (org.apache.samza.execution.ExecutionPlan)5 Field (java.lang.reflect.Field)4 ExecutionPlanner (org.apache.samza.execution.ExecutionPlanner)4 StreamSpec (org.apache.samza.system.StreamSpec)4 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 SamzaException (org.apache.samza.SamzaException)2 StreamManager (org.apache.samza.execution.StreamManager)2 StreamProcessor (org.apache.samza.processor.StreamProcessor)2 StreamProcessorLifecycleListener (org.apache.samza.processor.StreamProcessorLifecycleListener)2 Joiner (com.google.common.base.Joiner)1 ArrayList (java.util.ArrayList)1