Search in sources :

Example 6 with Cluster

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

the class DataprocProvisionerTest method testClusterCreateNoReuse.

@Test
public void testClusterCreateNoReuse() throws Exception {
    context.addProperty("accountKey", "testKey");
    context.addProperty(DataprocConf.PROJECT_ID_KEY, "testProject");
    context.addProperty("region", "testRegion");
    context.addProperty("idleTTL", "5");
    context.addProperty(DataprocConf.SKIP_DELETE, "true");
    context.setProfileName("testProfile");
    ProgramRunInfo programRunInfo = new ProgramRunInfo.Builder().setNamespace("ns").setApplication("app").setVersion("1.0").setProgramType("workflow").setProgram("program").setRun("runId").build();
    context.setProgramRunInfo(programRunInfo);
    context.setSparkCompat(SparkCompat.SPARK2_2_11);
    context.addProperty(DataprocConf.CLUSTER_REUSE_ENABLED, "false");
    Mockito.when(dataprocClient.getCluster("cdap-app-runId")).thenReturn(Optional.empty());
    Mockito.when(dataprocClient.createCluster(Mockito.eq("cdap-app-runId"), Mockito.eq("1.3"), addedLabelsCaptor.capture(), Mockito.eq(false))).thenReturn(ClusterOperationMetadata.getDefaultInstance());
    Cluster expectedCluster = new Cluster("cdap-app-runId", ClusterStatus.CREATING, Collections.emptyList(), Collections.emptyMap());
    Assert.assertEquals(expectedCluster, provisioner.createCluster(context));
    Assert.assertEquals(Collections.singletonMap("cdap-version", "6_4"), addedLabelsCaptor.getValue());
}
Also used : Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) ProgramRunInfo(io.cdap.cdap.runtime.spi.ProgramRunInfo) Test(org.junit.Test)

Example 7 with Cluster

use of io.cdap.cdap.runtime.spi.provisioner.Cluster in project cdap by cdapio.

the class ProvisioningServiceTest method testGetClusterStatusFailure.

@Test(expected = Exception.class)
public void testGetClusterStatusFailure() throws Exception {
    TaskFields taskFields = createTaskInfo(new MockProvisioner.PropertyBuilder().setFirstClusterStatus(ClusterStatus.RUNNING).failGet().setExpectedAppCDAPVersion(APP_CDAP_VERSION).build());
    Cluster cluster = new Cluster("test", ClusterStatus.NOT_EXISTS, Collections.emptyList(), Collections.emptyMap());
    provisioningService.getClusterStatus(taskFields.programRunId, taskFields.programOptions, cluster, "cdap");
}
Also used : Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) Test(org.junit.Test)

Example 8 with Cluster

use of io.cdap.cdap.runtime.spi.provisioner.Cluster in project cdap by cdapio.

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)

Example 9 with Cluster

use of io.cdap.cdap.runtime.spi.provisioner.Cluster in project cdap by cdapio.

the class ClusterInitializeSubtask method execute.

@Override
public Cluster execute(Cluster cluster) throws Exception {
    // get the full details, since many times, information like ip addresses is not available until we're done
    // polling for status and are ready to initialize. Up until now, the cluster object is what we got from
    // the original createCluster() call, except with the status updated.
    Cluster fullClusterDetails = provisioner.getClusterDetail(provisionerContext, cluster);
    provisioner.initializeCluster(provisionerContext, fullClusterDetails);
    Map<String, String> properties = new HashMap<>(cluster.getProperties());
    properties.putAll(fullClusterDetails.getProperties());
    return new Cluster(fullClusterDetails.getName(), ClusterStatus.RUNNING, fullClusterDetails.getNodes(), properties);
}
Also used : HashMap(java.util.HashMap) Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster)

Example 10 with Cluster

use of io.cdap.cdap.runtime.spi.provisioner.Cluster in project cdap by cdapio.

the class DataprocProvisioner method getClusterDetail.

@Override
public Cluster getClusterDetail(ProvisionerContext context, Cluster cluster) throws Exception {
    DataprocConf conf = DataprocConf.create(createContextProperties(context));
    String clusterName = cluster.getName();
    try (DataprocClient client = getClient(conf)) {
        Optional<Cluster> existing = client.getCluster(clusterName);
        DataprocUtils.emitMetric(context, conf.getRegion(), "provisioner.clusterDetail.response.count");
        return existing.orElseGet(() -> new Cluster(cluster, ClusterStatus.NOT_EXISTS));
    } catch (Exception e) {
        DataprocUtils.emitMetric(context, conf.getRegion(), "provisioner.clusterDetail.response.count", e);
        throw e;
    }
}
Also used : Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) GeneralSecurityException(java.security.GeneralSecurityException) RetryableProvisionException(io.cdap.cdap.runtime.spi.provisioner.RetryableProvisionException) IOException(java.io.IOException)

Aggregations

Cluster (io.cdap.cdap.runtime.spi.provisioner.Cluster)36 HashMap (java.util.HashMap)16 IOException (java.io.IOException)12 SSHKeyPair (io.cdap.cdap.runtime.spi.ssh.SSHKeyPair)10 Test (org.junit.Test)10 ClusterStatus (io.cdap.cdap.runtime.spi.provisioner.ClusterStatus)8 RetryableProvisionException (io.cdap.cdap.runtime.spi.provisioner.RetryableProvisionException)8 SSHContext (io.cdap.cdap.runtime.spi.ssh.SSHContext)8 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)6 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)6 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)6 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)6 SystemArguments (io.cdap.cdap.internal.app.runtime.SystemArguments)6 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)6 RuntimeMonitorType (io.cdap.cdap.runtime.spi.RuntimeMonitorType)6 ProvisionerContext (io.cdap.cdap.runtime.spi.provisioner.ProvisionerContext)6 ProvisionerSpecification (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification)6 GeneralSecurityException (java.security.GeneralSecurityException)6 Map (java.util.Map)6 Optional (java.util.Optional)6