Search in sources :

Example 1 with ClusterStatus

use of io.cdap.cdap.runtime.spi.provisioner.ClusterStatus in project cdap by caskdata.

the class MockProvisioner method getClusterStatus.

@Override
public ClusterStatus getClusterStatus(ProvisionerContext context, Cluster cluster) throws RetryableProvisionException {
    validateContext(context);
    failIfConfigured(context, FAIL_GET);
    failRetryablyEveryN(context);
    ClusterStatus status = cluster.getStatus();
    ClusterStatus newStatus;
    String firstClusterStatus = context.getProperties().get(FIRST_CLUSTER_STATUS);
    if (seenRuns.add(context.getProgramRunInfo()) && firstClusterStatus != null) {
        newStatus = ClusterStatus.valueOf(firstClusterStatus);
    } else {
        switch(status) {
            case CREATING:
                newStatus = ClusterStatus.RUNNING;
                break;
            case DELETING:
                newStatus = ClusterStatus.NOT_EXISTS;
                break;
            default:
                newStatus = status;
                break;
        }
    }
    return newStatus;
}
Also used : ClusterStatus(io.cdap.cdap.runtime.spi.provisioner.ClusterStatus)

Example 2 with ClusterStatus

use of io.cdap.cdap.runtime.spi.provisioner.ClusterStatus in project cdap by caskdata.

the class DataprocProvisioner method getClusterStatus.

@Override
public ClusterStatus getClusterStatus(ProvisionerContext context, Cluster cluster) throws Exception {
    DataprocConf conf = DataprocConf.create(createContextProperties(context));
    String clusterName = cluster.getName();
    ClusterStatus status = cluster.getStatus();
    // if we are skipping the delete, need to avoid checking the real cluster status and pretend like it is deleted.
    if (conf.isSkipDelete() && status == ClusterStatus.DELETING) {
        return ClusterStatus.NOT_EXISTS;
    }
    try (DataprocClient client = getClient(conf)) {
        status = client.getClusterStatus(clusterName);
        DataprocUtils.emitMetric(context, conf.getRegion(), "provisioner.clusterStatus.response.count");
        return status;
    } catch (Exception e) {
        DataprocUtils.emitMetric(context, conf.getRegion(), "provisioner.clusterStatus.response.count", e);
        throw e;
    }
}
Also used : ClusterStatus(io.cdap.cdap.runtime.spi.provisioner.ClusterStatus) GeneralSecurityException(java.security.GeneralSecurityException) RetryableProvisionException(io.cdap.cdap.runtime.spi.provisioner.RetryableProvisionException) IOException(java.io.IOException)

Example 3 with ClusterStatus

use of io.cdap.cdap.runtime.spi.provisioner.ClusterStatus in project cdap by caskdata.

the class SSHRemoteProcessController method isRunning.

@Override
public boolean isRunning() throws Exception {
    // Try to SSH into the host and see if the CDAP runtime process is running or not
    try (SSHSession session = new DefaultSSHSession(sshConfig)) {
        SSHProcess process = session.execute("pgrep -f -- -Dcdap.runid=" + programRunId.getRun());
        // Reading will be blocked until the process finished.
        // The output is not needed, just read it to avoid filling up the network buffer.
        ByteStreams.toByteArray(process.getInputStream());
        ByteStreams.toByteArray(process.getErrorStream());
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            LOG.info("Received exit code {} when checking for remote process for program run {}.", exitCode, programRunId);
        }
        return exitCode == 0;
    } catch (IOException e) {
        // If there is error performing SSH, check if the cluster still exist and running
        LOG.debug("Failed to use SSH to determine if the remote process is running for {}. Check cluster status instead.", programRunId, e);
        Cluster cluster = GSON.fromJson(programOpts.getArguments().getOption(ProgramOptionConstants.CLUSTER), Cluster.class);
        String userId = programOpts.getArguments().getOption(ProgramOptionConstants.USER_ID);
        ClusterStatus clusterStatus = provisioningService.getClusterStatus(programRunId, programOpts, cluster, userId);
        // The cluster status has to be RUNNING in order for the remote process still has a chance that is running
        return clusterStatus == ClusterStatus.RUNNING;
    }
}
Also used : SSHSession(io.cdap.cdap.runtime.spi.ssh.SSHSession) DefaultSSHSession(io.cdap.cdap.common.ssh.DefaultSSHSession) Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) IOException(java.io.IOException) DefaultSSHSession(io.cdap.cdap.common.ssh.DefaultSSHSession) SSHProcess(io.cdap.cdap.runtime.spi.ssh.SSHProcess) ClusterStatus(io.cdap.cdap.runtime.spi.provisioner.ClusterStatus)

Aggregations

ClusterStatus (io.cdap.cdap.runtime.spi.provisioner.ClusterStatus)3 IOException (java.io.IOException)2 DefaultSSHSession (io.cdap.cdap.common.ssh.DefaultSSHSession)1 Cluster (io.cdap.cdap.runtime.spi.provisioner.Cluster)1 RetryableProvisionException (io.cdap.cdap.runtime.spi.provisioner.RetryableProvisionException)1 SSHProcess (io.cdap.cdap.runtime.spi.ssh.SSHProcess)1 SSHSession (io.cdap.cdap.runtime.spi.ssh.SSHSession)1 GeneralSecurityException (java.security.GeneralSecurityException)1