Search in sources :

Example 1 with ProgramId

use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.

the class RemoteRuntimeStoreHandler method setSuspend.

@POST
@Path("/setSuspend")
public void setSuspend(HttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    ProgramId program = deserializeNext(arguments);
    String pid = deserializeNext(arguments);
    store.setSuspend(program, pid);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : MethodArgument(co.cask.cdap.common.internal.remote.MethodArgument) ProgramId(co.cask.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with ProgramId

use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.

the class RemoteRuntimeStoreHandler method setResume.

@POST
@Path("/setResume")
public void setResume(HttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    ProgramId program = deserializeNext(arguments);
    String pid = deserializeNext(arguments);
    store.setResume(program, pid);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : MethodArgument(co.cask.cdap.common.internal.remote.MethodArgument) ProgramId(co.cask.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with ProgramId

use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.

the class RemoteUsageRegistryHandler method registerDataset.

@POST
@Path("/registerDataset")
public void registerDataset(HttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    ProgramId programId = deserializeNext(arguments);
    DatasetId datasetInstance = deserializeNext(arguments);
    usageRegistry.register(programId, datasetInstance);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : MethodArgument(co.cask.cdap.common.internal.remote.MethodArgument) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with ProgramId

use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.

the class ProgramLifecycleService method validateAndCorrectRunningRunRecords.

/**
   * Fix all the possible inconsistent states for RunRecords that shows it is in RUNNING state but actually not
   * via check to {@link ProgramRuntimeService} for a type of CDAP program.
   *
   * @param programType The type of program the run records need to validate and update.
   * @param processedInvalidRunRecordIds the {@link Set} of processed invalid run record ids.
   */
@VisibleForTesting
void validateAndCorrectRunningRunRecords(final ProgramType programType, final Set<String> processedInvalidRunRecordIds) {
    final Map<RunId, RuntimeInfo> runIdToRuntimeInfo = runtimeService.list(programType);
    LOG.trace("Start getting run records not actually running ...");
    Collection<RunRecordMeta> notActuallyRunning = store.getRuns(ProgramRunStatus.RUNNING, new com.google.common.base.Predicate<RunRecordMeta>() {

        @Override
        public boolean apply(RunRecordMeta input) {
            String runId = input.getPid();
            // Check if it is not actually running.
            return !runIdToRuntimeInfo.containsKey(RunIds.fromString(runId));
        }
    }).values();
    LOG.trace("End getting {} run records not actually running.", notActuallyRunning.size());
    final Map<String, ProgramId> runIdToProgramId = new HashMap<>();
    LOG.trace("Start getting invalid run records  ...");
    Collection<RunRecordMeta> invalidRunRecords = Collections2.filter(notActuallyRunning, new com.google.common.base.Predicate<RunRecordMeta>() {

        @Override
        public boolean apply(RunRecordMeta input) {
            String runId = input.getPid();
            // check for program Id for the run record, if null then it is invalid program type.
            ProgramId targetProgramId = retrieveProgramIdForRunRecord(programType, runId);
            // Check if run id is for the right program type
            if (targetProgramId != null) {
                runIdToProgramId.put(runId, targetProgramId);
                return true;
            } else {
                return false;
            }
        }
    });
    // don't correct run records for programs running inside a workflow
    // for instance, a MapReduce running in a Workflow will not be contained in the runtime info in this class
    invalidRunRecords = Collections2.filter(invalidRunRecords, new com.google.common.base.Predicate<RunRecordMeta>() {

        @Override
        public boolean apply(RunRecordMeta invalidRunRecordMeta) {
            boolean shouldCorrect = shouldCorrectForWorkflowChildren(invalidRunRecordMeta, processedInvalidRunRecordIds);
            if (!shouldCorrect) {
                LOG.trace("Will not correct invalid run record {} since it's parent workflow still running.", invalidRunRecordMeta);
                return false;
            }
            return true;
        }
    });
    LOG.trace("End getting invalid run records.");
    if (!invalidRunRecords.isEmpty()) {
        LOG.warn("Found {} RunRecords with RUNNING status and the program not actually running for program type {}", invalidRunRecords.size(), programType.getPrettyName());
    } else {
        LOG.trace("No RunRecords found with RUNNING status and the program not actually running for program type {}", programType.getPrettyName());
    }
    // Now lets correct the invalid RunRecords
    for (RunRecordMeta invalidRunRecordMeta : invalidRunRecords) {
        String runId = invalidRunRecordMeta.getPid();
        ProgramId targetProgramId = runIdToProgramId.get(runId);
        boolean updated = store.compareAndSetStatus(targetProgramId, runId, ProgramController.State.ALIVE.getRunStatus(), ProgramController.State.ERROR.getRunStatus());
        if (updated) {
            LOG.warn("Fixed RunRecord {} for program {} with RUNNING status because the program was not " + "actually running", runId, targetProgramId);
            processedInvalidRunRecordIds.add(runId);
        }
    }
}
Also used : RuntimeInfo(co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo) HashMap(java.util.HashMap) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramId(co.cask.cdap.proto.id.ProgramId) Predicate(co.cask.cdap.api.Predicate) RunId(org.apache.twill.api.RunId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with ProgramId

use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.

the class ProgramLifecycleService method retrieveProgramIdForRunRecord.

/**
   * Helper method to get {@link ProgramId} for a RunRecord for type of program
   *
   * @param programType Type of program to search
   * @param runId The target id of the {@link RunRecord} to find
   * @return the program id of the run record or {@code null} if does not exist.
   */
@Nullable
private ProgramId retrieveProgramIdForRunRecord(ProgramType programType, String runId) {
    // Get list of namespaces (borrow logic from AbstractAppFabricHttpHandler#listPrograms)
    List<NamespaceMeta> namespaceMetas = nsStore.list();
    // For each, get all programs under it
    ProgramId targetProgramId = null;
    for (NamespaceMeta nm : namespaceMetas) {
        NamespaceId namespace = Ids.namespace(nm.getName());
        Collection<ApplicationSpecification> appSpecs = store.getAllApplications(namespace);
        // For each application get the programs checked against run records
        for (ApplicationSpecification appSpec : appSpecs) {
            switch(programType) {
                case FLOW:
                    for (String programName : appSpec.getFlows().keySet()) {
                        ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
                        if (programId != null) {
                            targetProgramId = programId;
                            break;
                        }
                    }
                    break;
                case MAPREDUCE:
                    for (String programName : appSpec.getMapReduce().keySet()) {
                        ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
                        if (programId != null) {
                            targetProgramId = programId;
                            break;
                        }
                    }
                    break;
                case SPARK:
                    for (String programName : appSpec.getSpark().keySet()) {
                        ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
                        if (programId != null) {
                            targetProgramId = programId;
                            break;
                        }
                    }
                    break;
                case SERVICE:
                    for (String programName : appSpec.getServices().keySet()) {
                        ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
                        if (programId != null) {
                            targetProgramId = programId;
                            break;
                        }
                    }
                    break;
                case WORKER:
                    for (String programName : appSpec.getWorkers().keySet()) {
                        ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
                        if (programId != null) {
                            targetProgramId = programId;
                            break;
                        }
                    }
                    break;
                case WORKFLOW:
                    for (String programName : appSpec.getWorkflows().keySet()) {
                        ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
                        if (programId != null) {
                            targetProgramId = programId;
                            break;
                        }
                    }
                    break;
                case CUSTOM_ACTION:
                case WEBAPP:
                    // no-op
                    break;
                default:
                    LOG.debug("Unknown program type: " + programType.name());
                    break;
            }
            if (targetProgramId != null) {
                break;
            }
        }
        if (targetProgramId != null) {
            break;
        }
    }
    return targetProgramId;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ProgramId(co.cask.cdap.proto.id.ProgramId) Nullable(javax.annotation.Nullable)

Aggregations

ProgramId (co.cask.cdap.proto.id.ProgramId)259 Test (org.junit.Test)104 ApplicationId (co.cask.cdap.proto.id.ApplicationId)96 Path (javax.ws.rs.Path)62 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)45 DatasetId (co.cask.cdap.proto.id.DatasetId)40 RunId (org.apache.twill.api.RunId)40 NotFoundException (co.cask.cdap.common.NotFoundException)35 ProgramType (co.cask.cdap.proto.ProgramType)35 NamespaceId (co.cask.cdap.proto.id.NamespaceId)35 StreamId (co.cask.cdap.proto.id.StreamId)32 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)28 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 POST (javax.ws.rs.POST)24 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)23 GET (javax.ws.rs.GET)22 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)21 HttpResponse (org.apache.http.HttpResponse)20 HashMap (java.util.HashMap)19