Search in sources :

Example 1 with Node

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

the class DefaultRuntimeJobTest method testInjector.

@Test
public void testInjector() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().toString());
    LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFile());
    DefaultRuntimeJob defaultRuntimeJob = new DefaultRuntimeJob();
    Arguments systemArgs = new BasicArguments(Collections.singletonMap(SystemArguments.PROFILE_NAME, "test"));
    Node node = new Node("test", Node.Type.MASTER, "127.0.0.1", System.currentTimeMillis(), Collections.emptyMap());
    Cluster cluster = new Cluster("test", ClusterStatus.RUNNING, Collections.singleton(node), Collections.emptyMap());
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("workflow").run(RunIds.generate());
    SimpleProgramOptions programOpts = new SimpleProgramOptions(programRunId.getParent(), systemArgs, new BasicArguments());
    Injector injector = Guice.createInjector(defaultRuntimeJob.createModules(new RuntimeJobEnvironment() {

        @Override
        public LocationFactory getLocationFactory() {
            return locationFactory;
        }

        @Override
        public TwillRunner getTwillRunner() {
            return new NoopTwillRunnerService();
        }

        @Override
        public Map<String, String> getProperties() {
            return Collections.emptyMap();
        }
    }, cConf, programRunId, programOpts));
    injector.getInstance(LogAppenderInitializer.class);
    defaultRuntimeJob.createCoreServices(injector, systemArgs, cluster);
}
Also used : Node(io.cdap.cdap.runtime.spi.provisioner.Node) Arguments(io.cdap.cdap.app.runtime.Arguments) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) NoopTwillRunnerService(io.cdap.cdap.common.twill.NoopTwillRunnerService) Injector(com.google.inject.Injector) RuntimeJobEnvironment(io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Test(org.junit.Test)

Example 2 with Node

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

the class RemoteHadoopProvisioner method getMasterExternalIp.

private String getMasterExternalIp(Cluster cluster) {
    Node masterNode = cluster.getNodes().stream().filter(node -> Node.Type.MASTER == node.getType()).findFirst().orElseThrow(() -> new IllegalArgumentException("Cluster has no node of master type: " + cluster));
    String ip = masterNode.getIpAddress();
    if (ip == null) {
        throw new IllegalArgumentException(String.format("External IP is not defined for node '%s' in cluster %s", masterNode.getId(), cluster));
    }
    return ip;
}
Also used : Node(io.cdap.cdap.runtime.spi.provisioner.Node)

Example 3 with Node

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

the class DataprocClient method getNode.

private Node getNode(Compute compute, Node.Type type, String zone, String nodeName) throws IOException {
    Instance instance;
    try {
        instance = compute.instances().get(conf.getProjectId(), zone, nodeName).execute();
    } catch (GoogleJsonResponseException e) {
        // this can happen right after a cluster is created
        if (e.getStatusCode() == 404) {
            return new Node(nodeName, Node.Type.UNKNOWN, "", -1L, Collections.emptyMap());
        }
        throw e;
    }
    Map<String, String> properties = new HashMap<>();
    // Dataproc cluster node should only have exactly one network
    instance.getNetworkInterfaces().stream().findFirst().ifPresent(networkInterface -> {
        // if the cluster does not have an external ip then then access config is null
        if (networkInterface.getAccessConfigs() != null) {
            for (AccessConfig accessConfig : networkInterface.getAccessConfigs()) {
                if (accessConfig.getNatIP() != null) {
                    properties.put("ip.external", accessConfig.getNatIP());
                    break;
                }
            }
        }
        properties.put("ip.internal", networkInterface.getNetworkIP());
    });
    long ts;
    try {
        // something like 2018-04-16T12:09:03.943-07:00
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSX");
        ts = sdf.parse(instance.getCreationTimestamp()).getTime();
    } catch (ParseException | NumberFormatException e) {
        LOG.debug("Fail to parse creation ts {}", instance.getCreationTimestamp(), e);
        ts = -1L;
    }
    // For internal IP only cluster, nodes only have ip.internal.
    String ip = properties.get("ip.external");
    if (ip == null) {
        ip = properties.get("ip.internal");
    }
    return new Node(nodeName, type, ip, ts, properties);
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Instance(com.google.api.services.compute.model.Instance) HashMap(java.util.HashMap) Node(io.cdap.cdap.runtime.spi.provisioner.Node) ParseException(java.text.ParseException) AccessConfig(com.google.api.services.compute.model.AccessConfig) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with Node

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

the class EMRClient method getCluster.

/**
 * Get information about the specified cluster. The cluster will not be present if it could not be found.
 *
 * @param id the cluster id
 * @return the cluster information if it exists
 */
public Optional<io.cdap.cdap.runtime.spi.provisioner.Cluster> getCluster(String id) {
    Cluster cluster = describeCluster(id);
    List<Node> nodes = new ArrayList<>();
    nodes.add(new Node("id", Node.Type.MASTER, cluster.getMasterPublicDnsName(), System.currentTimeMillis(), Collections.emptyMap()));
    return Optional.of(new io.cdap.cdap.runtime.spi.provisioner.Cluster(cluster.getId(), convertStatus(cluster.getStatus()), nodes, Collections.emptyMap()));
}
Also used : Node(io.cdap.cdap.runtime.spi.provisioner.Node) ArrayList(java.util.ArrayList) Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster)

Example 5 with Node

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

the class ElasticMapReduceProvisioner method getMasterExternalIp.

private String getMasterExternalIp(Cluster cluster) {
    Node masterNode = cluster.getNodes().stream().filter(node -> Node.Type.MASTER == node.getType()).findFirst().orElseThrow(() -> new IllegalArgumentException("Cluster has no node of master type: " + cluster));
    String ip = masterNode.getIpAddress();
    if (ip == null) {
        throw new IllegalArgumentException(String.format("External IP is not defined for node '%s' in cluster %s", masterNode.getId(), cluster));
    }
    return ip;
}
Also used : Node(io.cdap.cdap.runtime.spi.provisioner.Node)

Aggregations

Node (io.cdap.cdap.runtime.spi.provisioner.Node)6 Cluster (io.cdap.cdap.runtime.spi.provisioner.Cluster)2 HashMap (java.util.HashMap)2 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)1 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 AccessConfig (com.google.api.services.compute.model.AccessConfig)1 Instance (com.google.api.services.compute.model.Instance)1 Injector (com.google.inject.Injector)1 Arguments (io.cdap.cdap.app.runtime.Arguments)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 NoopTwillRunnerService (io.cdap.cdap.common.twill.NoopTwillRunnerService)1 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)1 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)1 SystemArguments (io.cdap.cdap.internal.app.runtime.SystemArguments)1 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)1 RuntimeJobEnvironment (io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)1