Search in sources :

Example 1 with ProgramRunClusterStatus

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

the class AppMetadataStore method recordProgramProvisioned.

/**
 * Record that the program run has completed 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 numNodes number of cluster nodes provisioned
 * @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#PROVISIONED} if it is successfully persisted, {@code null} otherwise.
 */
@Nullable
public ProgramRunClusterStatus recordProgramProvisioned(ProgramRunId programRunId, int numNodes, byte[] sourceId) {
    MDSKey key = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTING, programRunId).build();
    RunRecordMeta existing = getRun(programRunId);
    if (existing == null) {
        LOG.warn("Ignoring unexpected request to transition program run {} from non-existent state to cluster state {}.", programRunId, ProgramRunClusterStatus.PROVISIONED);
        return null;
    } else if (!isValid(existing, sourceId, "provisioned")) {
        return null;
    }
    ProgramRunClusterStatus clusterState = existing.getCluster().getStatus();
    if (clusterState != ProgramRunClusterStatus.PROVISIONING) {
        LOG.warn("Ignoring unexpected request to transition program run {} from cluster state {} to cluster state {}.", programRunId, existing.getCluster().getStatus(), ProgramRunClusterStatus.PROVISIONED);
        return null;
    }
    ProgramRunCluster cluster = new ProgramRunCluster(ProgramRunClusterStatus.PROVISIONED, null, numNodes);
    RunRecordMeta meta = RunRecordMeta.builder(existing).setStatus(ProgramRunStatus.STARTING).setCluster(cluster).setSourceId(sourceId).build();
    write(key, meta);
    return ProgramRunClusterStatus.PROVISIONED;
}
Also used : ProgramRunClusterStatus(co.cask.cdap.proto.ProgramRunClusterStatus) ProgramRunCluster(co.cask.cdap.proto.ProgramRunCluster) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) Nullable(javax.annotation.Nullable)

Example 2 with ProgramRunClusterStatus

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

the class AppMetadataStore method recordProgramDeprovisioning.

/**
 * Record that the program run has started de-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 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#DEPROVISIONING} if it is successfully persisted, {@code null} otherwise.
 */
@Nullable
public ProgramRunClusterStatus recordProgramDeprovisioning(ProgramRunId programRunId, byte[] sourceId) {
    MDSKey.Builder key = getProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programRunId.getParent());
    RunRecordMeta existing = getRun(programRunId);
    if (existing == null) {
        LOG.debug("Ignoring unexpected transition of program run {} to cluster state {} with no existing run record.", programRunId, ProgramRunClusterStatus.DEPROVISIONING);
        return null;
    } else if (!isValid(existing, sourceId, "deprovisioning")) {
        return null;
    }
    ProgramRunClusterStatus clusterStatus = existing.getCluster().getStatus();
    if (clusterStatus != ProgramRunClusterStatus.PROVISIONED) {
        LOG.warn("Ignoring unexpected request to transition program run {} from cluster state {} to cluster state {}.", programRunId, clusterStatus, ProgramRunClusterStatus.DEPROVISIONING);
        return null;
    }
    if (!existing.getStatus().isEndState()) {
        LOG.warn("Ignoring unexpected request to transition program run {} from program state {} to cluster state {}.", programRunId, existing.getStatus(), ProgramRunClusterStatus.DEPROVISIONING);
        return null;
    }
    key.add(getInvertedTsKeyPart(existing.getStartTs())).add(programRunId.getRun()).build();
    ProgramRunCluster cluster = new ProgramRunCluster(ProgramRunClusterStatus.DEPROVISIONING, null, existing.getCluster().getNumNodes());
    RunRecordMeta meta = RunRecordMeta.builder(existing).setCluster(cluster).setSourceId(sourceId).build();
    write(key.build(), meta);
    return ProgramRunClusterStatus.DEPROVISIONING;
}
Also used : ProgramRunClusterStatus(co.cask.cdap.proto.ProgramRunClusterStatus) ProgramRunCluster(co.cask.cdap.proto.ProgramRunCluster) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) Nullable(javax.annotation.Nullable)

Example 3 with ProgramRunClusterStatus

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

the class AppMetadataStore method recordProgramDeprovisioned.

/**
 * Record that the program run has deprovisioned compute resources for the run. If the current status has
 * a higher source id, this call will be ignored.
 *
 * @param programRunId program run
 * @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#DEPROVISIONED} if it is successfully persisted, {@code null} otherwise.
 */
@Nullable
public ProgramRunClusterStatus recordProgramDeprovisioned(ProgramRunId programRunId, byte[] sourceId) {
    MDSKey.Builder key = getProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programRunId.getParent());
    RunRecordMeta existing = getRun(programRunId);
    if (existing == null) {
        LOG.debug("Ignoring unexpected transition of program run {} to cluster state {} with no existing run record.", programRunId, ProgramRunClusterStatus.DEPROVISIONED);
        return null;
    } else if (!isValid(existing, sourceId, "deprovisioned")) {
        return null;
    }
    ProgramRunClusterStatus clusterStatus = existing.getCluster().getStatus();
    if (clusterStatus != ProgramRunClusterStatus.DEPROVISIONING) {
        LOG.warn("Ignoring unexpected request to transition program run {} from cluster state {} to cluster state {}.", programRunId, clusterStatus, ProgramRunClusterStatus.DEPROVISIONED);
        return null;
    }
    if (!existing.getStatus().isEndState()) {
        LOG.warn("Ignoring unexpected request to transition program run {} from program state {} to cluster state {}.", programRunId, existing.getStatus(), ProgramRunClusterStatus.DEPROVISIONED);
        return null;
    }
    key.add(getInvertedTsKeyPart(existing.getStartTs())).add(programRunId.getRun()).build();
    ProgramRunCluster cluster = new ProgramRunCluster(ProgramRunClusterStatus.DEPROVISIONED, null, existing.getCluster().getNumNodes());
    RunRecordMeta meta = RunRecordMeta.builder(existing).setCluster(cluster).setSourceId(sourceId).build();
    write(key.build(), meta);
    return ProgramRunClusterStatus.DEPROVISIONED;
}
Also used : ProgramRunClusterStatus(co.cask.cdap.proto.ProgramRunClusterStatus) ProgramRunCluster(co.cask.cdap.proto.ProgramRunCluster) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) Nullable(javax.annotation.Nullable)

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)3 ProgramRunCluster (co.cask.cdap.proto.ProgramRunCluster)3 ProgramRunClusterStatus (co.cask.cdap.proto.ProgramRunClusterStatus)3 Nullable (javax.annotation.Nullable)3