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);
}
}
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");
}
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);
}
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();
}
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");
}
Aggregations