use of co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo in project cdap by caskdata.
the class ProgramLifecycleService method getExistingAppProgramStatus.
/**
* Returns the program status with no need of application existence check.
* @param appSpec the ApplicationSpecification of the existing application
* @param programId the id of the program for which the status call is made
* @return the status of the program
* @throws NotFoundException if the application to which this program belongs was not found
*/
private ProgramStatus getExistingAppProgramStatus(ApplicationSpecification appSpec, ProgramId programId) throws Exception {
ProgramRuntimeService.RuntimeInfo runtimeInfo = findRuntimeInfo(programId);
if (runtimeInfo == null) {
if (programId.getType() != ProgramType.WEBAPP) {
//Runtime info not found. Check to see if the program exists.
ProgramSpecification spec = getExistingAppProgramSpecification(appSpec, programId);
if (spec == null) {
// program doesn't exist
throw new NotFoundException(programId);
}
ensureAccess(programId);
if ((programId.getType() == ProgramType.MAPREDUCE || programId.getType() == ProgramType.SPARK) && !store.getRuns(programId, ProgramRunStatus.RUNNING, 0, Long.MAX_VALUE, 1).isEmpty()) {
// MapReduce program exists and running as a part of Workflow
return ProgramStatus.RUNNING;
}
return ProgramStatus.STOPPED;
}
throw new IllegalStateException("Webapp status is not supported");
}
return runtimeInfo.getController().getState().getProgramStatus();
}
use of co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo in project cdap by caskdata.
the class ProgramLifecycleService method setFlowletInstances.
private void setFlowletInstances(ProgramId programId, String flowletId, int instances) throws ExecutionException, InterruptedException, BadRequestException {
int oldInstances = store.getFlowletInstances(programId, flowletId);
if (oldInstances != instances) {
FlowSpecification flowSpec = store.setFlowletInstances(programId, flowletId, instances);
ProgramRuntimeService.RuntimeInfo runtimeInfo = findRuntimeInfo(programId);
if (runtimeInfo != null) {
runtimeInfo.getController().command(ProgramOptionConstants.INSTANCES, ImmutableMap.of("flowlet", flowletId, "newInstances", String.valueOf(instances), "oldFlowSpec", GSON.toJson(flowSpec, FlowSpecification.class))).get();
}
}
}
Aggregations