Search in sources :

Example 21 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta in project cdap by caskdata.

the class ProgramLifecycleService method shouldCorrectForWorkflowChildren.

/**
   * Helper method to check if the run record is a child program of a Workflow
   *
   * @param runRecordMeta The target {@link RunRecordMeta} to check
   * @param processedInvalidRunRecordIds the {@link Set} of processed invalid run record ids.
   * @return {@code true} of we should check and {@code false} otherwise
   */
private boolean shouldCorrectForWorkflowChildren(RunRecordMeta runRecordMeta, Set<String> processedInvalidRunRecordIds) {
    // check if it is part of workflow because it may not have actual runtime info
    if (runRecordMeta.getProperties() != null && runRecordMeta.getProperties().get("workflowrunid") != null) {
        // Get the parent Workflow info
        String workflowRunId = runRecordMeta.getProperties().get("workflowrunid");
        if (!processedInvalidRunRecordIds.contains(workflowRunId)) {
            // If the parent workflow has not been processed, then check if it still valid
            ProgramId workflowProgramId = retrieveProgramIdForRunRecord(ProgramType.WORKFLOW, workflowRunId);
            if (workflowProgramId != null) {
                // lets see if the parent workflow run records state is still running
                RunRecordMeta wfRunRecord = store.getRun(workflowProgramId, workflowRunId);
                RuntimeInfo wfRuntimeInfo = runtimeService.lookup(workflowProgramId, RunIds.fromString(workflowRunId));
                // then do not update it
                if (wfRunRecord != null && wfRunRecord.getStatus() == ProgramRunStatus.RUNNING && wfRuntimeInfo != null) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : RuntimeInfo(co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramId(co.cask.cdap.proto.id.ProgramId)

Example 22 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta in project cdap by caskdata.

the class ProgramLifecycleService method validateProgramForRunRecord.

/**
   * Helper method to get program id for a run record if it exists in the store.
   *
   * @return instance of {@link ProgramId} if exist for the runId or null if does not
   */
@Nullable
private ProgramId validateProgramForRunRecord(String namespaceName, String appName, String appVersion, ProgramType programType, String programName, String runId) {
    ProgramId programId = Ids.namespace(namespaceName).app(appName, appVersion).program(programType, programName);
    RunRecordMeta runRecord = store.getRun(programId, runId);
    if (runRecord == null) {
        return null;
    }
    return programId;
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramId(co.cask.cdap.proto.id.ProgramId) Nullable(javax.annotation.Nullable)

Example 23 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta in project cdap by caskdata.

the class LogHandler method getRunRecordMeta.

private RunRecordMeta getRunRecordMeta(String namespace, String app, ProgramType programType, String programName, String run) throws NotFoundException {
    ProgramRunId programRunId = new ProgramRunId(namespace, app, programType, programName, run);
    RunRecordMeta runRecord = programStore.getRun(programRunId.getParent(), programRunId.getRun());
    if (runRecord == null) {
        throw new NotFoundException(programRunId);
    }
    return runRecord;
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId)

Example 24 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta in project cdap by caskdata.

the class LogHandler method getRunIdLogs.

@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/logs")
public void getRunIdLogs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId, @PathParam("run-id") String runId, @QueryParam("start") @DefaultValue("-1") long fromTimeSecsParam, @QueryParam("stop") @DefaultValue("-1") long toTimeSecsParam, @QueryParam("escape") @DefaultValue("true") boolean escape, @QueryParam("filter") @DefaultValue("") String filterStr, @QueryParam("format") @DefaultValue("text") String format, @QueryParam("suppress") List<String> suppress) throws NotFoundException {
    ProgramType type = ProgramType.valueOfCategoryName(programType);
    RunRecordMeta runRecord = getRunRecordMeta(namespaceId, appId, type, programId, runId);
    LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(namespaceId, appId, programId, type, runId, runRecord.getSystemArgs());
    doGetLogs(responder, loggingContext, fromTimeSecsParam, toTimeSecsParam, escape, filterStr, runRecord, format, suppress);
}
Also used : LoggingContext(co.cask.cdap.common.logging.LoggingContext) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramType(co.cask.cdap.proto.ProgramType) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 25 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta in project cdap by caskdata.

the class AppMetadataStore method getRun.

// TODO: getRun is duplicated from cdap-app-fabric AppMetadataStore class.
// Any changes made here will have to be made over there too.
// JIRA https://issues.cask.co/browse/CDAP-2172
public RunRecordMeta getRun(ProgramId program, final String runid) {
    // Query active run record first
    RunRecordMeta running = getUnfinishedRun(program, TYPE_RUN_RECORD_STARTED, runid);
    // If program is running, this will be non-null
    if (running != null) {
        return running;
    }
    // If program is not running, query completed run records
    RunRecordMeta complete = getCompletedRun(program, runid);
    if (complete != null) {
        return complete;
    }
    // Else query suspended run records
    return getUnfinishedRun(program, TYPE_RUN_RECORD_SUSPENDED, runid);
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta)

Aggregations

RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)25 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)11 ProgramId (co.cask.cdap.proto.id.ProgramId)9 GET (javax.ws.rs.GET)8 Path (javax.ws.rs.Path)8 LoggingContext (co.cask.cdap.common.logging.LoggingContext)6 RuntimeInfo (co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo)4 NotFoundException (co.cask.cdap.common.NotFoundException)4 ProgramType (co.cask.cdap.proto.ProgramType)4 MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)3 RunId (org.apache.twill.api.RunId)3 Test (org.junit.Test)3 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 Relation (co.cask.cdap.data2.metadata.lineage.Relation)2 SimpleRuntimeInfo (co.cask.cdap.internal.app.runtime.service.SimpleRuntimeInfo)2 RunRecord (co.cask.cdap.proto.RunRecord)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 TwillController (org.apache.twill.api.TwillController)2