Search in sources :

Example 11 with RuntimeInfo

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();
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) RuntimeInfo(co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo) ProgramRuntimeService(co.cask.cdap.app.runtime.ProgramRuntimeService)

Example 12 with RuntimeInfo

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();
        }
    }
}
Also used : FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) RuntimeInfo(co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo) ProgramRuntimeService(co.cask.cdap.app.runtime.ProgramRuntimeService)

Aggregations

RuntimeInfo (co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo)12 ProgramRuntimeService (co.cask.cdap.app.runtime.ProgramRuntimeService)9 RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)4 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 LogLevelUpdater (co.cask.cdap.app.runtime.LogLevelUpdater)2 ProgramController (co.cask.cdap.app.runtime.ProgramController)2 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)2 BadRequestException (co.cask.cdap.common.BadRequestException)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 ArrayList (java.util.ArrayList)2 RunId (org.apache.twill.api.RunId)2 Predicate (co.cask.cdap.api.Predicate)1 ProgramSpecification (co.cask.cdap.api.ProgramSpecification)1 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)1 ProgramDescriptor (co.cask.cdap.app.program.ProgramDescriptor)1 AbstractListener (co.cask.cdap.internal.app.runtime.AbstractListener)1 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)1 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)1