use of io.cdap.cdap.app.guice.ClusterMode in project cdap by caskdata.
the class RemoteExecutionTwillRunnerService method createControllerIfNeeded.
/**
* Creates a {@link TwillController} based on the given {@link RunRecordDetail} if it should be monitored by this
* service.
*/
private boolean createControllerIfNeeded(RunRecordDetail runRecordDetail) {
// Program runs in PENDING and STARTING state will eventually start and controller will be created later.
if (runRecordDetail.getStatus() != ProgramRunStatus.RUNNING && runRecordDetail.getStatus() != ProgramRunStatus.SUSPENDED) {
LOG.debug("Skip creating controller for run {} with status {}", runRecordDetail.getProgramRunId(), runRecordDetail.getStatus());
return false;
}
Map<String, String> systemArgs = runRecordDetail.getSystemArgs();
try {
ClusterMode clusterMode = ClusterMode.valueOf(systemArgs.getOrDefault(ProgramOptionConstants.CLUSTER_MODE, ClusterMode.ON_PREMISE.name()));
if (clusterMode != ClusterMode.ISOLATED) {
LOG.debug("Ignore run {} of non supported cluster mode {}", runRecordDetail.getProgramRunId(), clusterMode);
return false;
}
} catch (IllegalArgumentException e) {
LOG.warn("Ignore run record with an invalid cluster mode", e);
return false;
}
ProgramOptions programOpts = new SimpleProgramOptions(runRecordDetail.getProgramRunId().getParent(), new BasicArguments(runRecordDetail.getSystemArgs()), new BasicArguments(runRecordDetail.getUserArgs()));
// Creates a controller via the controller factory.
// Since there is no startup start needed, the timeout is arbitrarily short
new ControllerFactory(runRecordDetail.getProgramRunId(), programOpts).create(null, 5, TimeUnit.SECONDS);
return true;
}
Aggregations