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;
}
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;
}
}
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;
}
}
Aggregations