Search in sources :

Example 6 with ProgramRunCluster

use of co.cask.cdap.proto.ProgramRunCluster in project cdap by caskdata.

the class AppMetadataStore method recordProgramProvisioning.

/**
 * Record that the program run is provisioning compute resources for the run. If the current status has
 * a higher source id, this call will be ignored.
 *
 * @param programRunId program run
 * @param startTs start time of the run
 * @param runtimeArgs runtime arguments
 * @param systemArgs system arguments
 * @param sourceId unique id representing the source of program run status, such as the message id of the program
 *                 run status notification in TMS. The source id must increase as the recording time of the program
 *                 run status increases, so that the attempt to persist program run status older than the existing
 *                 program run status will be ignored
 * @return {@link ProgramRunClusterStatus#PROVISIONING} if it is successfully persisted, {@code null} otherwise.
 */
@Nullable
public ProgramRunClusterStatus recordProgramProvisioning(ProgramRunId programRunId, long startTs, Map<String, String> runtimeArgs, Map<String, String> systemArgs, byte[] sourceId) {
    MDSKey key = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTING, programRunId).build();
    RunRecordMeta existing = getRun(programRunId);
    // for some reason, there is an existing run record.
    if (existing != null) {
        // runtime args, and system args of the existing run record.
        if (!isValid(existing, sourceId, "provisioning")) {
            return null;
        }
        return null;
    }
    String workflowRunId = null;
    if (systemArgs != null && systemArgs.containsKey(ProgramOptionConstants.WORKFLOW_NAME)) {
        workflowRunId = systemArgs.get(ProgramOptionConstants.WORKFLOW_RUN_ID);
    }
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.put("runtimeArgs", GSON.toJson(runtimeArgs, MAP_STRING_STRING_TYPE));
    if (workflowRunId != null) {
        builder.put("workflowrunid", workflowRunId);
    }
    ProgramRunCluster cluster = new ProgramRunCluster(ProgramRunClusterStatus.PROVISIONING, null, null);
    RunRecordMeta meta = RunRecordMeta.builder().setProgramRunId(programRunId).setStartTime(startTs).setStatus(ProgramRunStatus.STARTING).setProperties(builder.build()).setSystemArgs(systemArgs).setCluster(cluster).setSourceId(sourceId).build();
    write(key, meta);
    return ProgramRunClusterStatus.PROVISIONING;
}
Also used : ProgramRunCluster(co.cask.cdap.proto.ProgramRunCluster) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) ImmutableMap(com.google.common.collect.ImmutableMap) Nullable(javax.annotation.Nullable)

Aggregations

ProgramRunCluster (co.cask.cdap.proto.ProgramRunCluster)6 MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)4 Nullable (javax.annotation.Nullable)4 ProgramRunClusterStatus (co.cask.cdap.proto.ProgramRunClusterStatus)3 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)2 RunId (org.apache.twill.api.RunId)2 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)1 LogEvent (co.cask.cdap.logging.read.LogEvent)1 LogOffset (co.cask.cdap.logging.read.LogOffset)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Test (org.junit.Test)1