Search in sources :

Example 6 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project hive by apache.

the class CloudExecutionContextProvider method createNodes.

private Set<NodeMetadata> createNodes(final int numHosts) throws CreateHostsFailedException {
    Set<NodeMetadata> result = Sets.newHashSet();
    int attempts = 0;
    int numRequired = numHosts;
    // pause so we don't get banned
    try {
        TimeUnit.SECONDS.sleep(mRetrySleepInterval);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    do {
        boolean error = false;
        LOG.info("Attempting to create " + numRequired + " nodes");
        try {
            result.addAll(mCloudComputeService.createNodes(Math.min(mMaxHostsPerCreateRequest, numRequired)));
        } catch (RunNodesException e) {
            error = true;
            LOG.warn("Error creating nodes", e);
            terminateInternal(e.getNodeErrors().keySet());
            result.addAll(e.getSuccessfulNodes());
        }
        result = verifyHosts(result);
        for (NodeMetadata node : result) {
            mLiveHosts.put(publicIpOrHostname(node), System.currentTimeMillis());
        }
        LOG.info("Successfully created " + result.size() + " nodes");
        numRequired = numHosts - result.size();
        if (numRequired > 0) {
            long sleepTime = mRetrySleepInterval;
            if (error) {
                sleepTime *= ++attempts;
            }
            LOG.info("Pausing creation process for " + sleepTime + " seconds");
            try {
                TimeUnit.SECONDS.sleep(sleepTime);
            } catch (InterruptedException e) {
                throw new CreateHostsFailedException("Interrupted while trying to create hosts", e);
            }
        }
    } while (numRequired > 0);
    Preconditions.checkState(result.size() >= numHosts, "Results should always be >= numHosts " + numHosts + " => " + result.size());
    return result;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) RunNodesException(org.jclouds.compute.RunNodesException)

Example 7 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project hive by apache.

the class CloudExecutionContextProvider method createExecutionContext.

@Override
public synchronized ExecutionContext createExecutionContext() throws CreateHostsFailedException, ServiceNotAvailableException {
    try {
        Set<NodeMetadata> nodes = createNodes(mNumHosts);
        Set<Host> hosts = Sets.newHashSet();
        for (NodeMetadata node : nodes) {
            hosts.add(new Host(publicIp(node), mUser, mSlaveLocalDirs, mNumThreads));
        }
        return new ExecutionContext(this, hosts, mWorkingDir.getAbsolutePath(), mPrivateKey);
    } finally {
        syncLog();
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Host(org.apache.hive.ptest.execution.conf.Host)

Example 8 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project hive by apache.

the class CloudExecutionContextProvider method getRunningNodes.

private Set<NodeMetadata> getRunningNodes() {
    Set<NodeMetadata> result = Sets.newHashSet();
    Set<NodeMetadata> computes = mCloudComputeService.listRunningNodes();
    for (NodeMetadata node : computes) {
        result.add(node);
    }
    return result;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata)

Example 9 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project whirr by apache.

the class CassandraService method launchCluster.

@Override
public Cluster launchCluster(ClusterSpec clusterSpec) throws IOException {
    ComputeServiceContext computeServiceContext = ComputeServiceContextBuilder.build(clusterSpec);
    ComputeService computeService = computeServiceContext.getComputeService();
    byte[] bootScript = RunUrlBuilder.runUrls("sun/java/install", "apache/cassandra/install");
    TemplateBuilder templateBuilder = computeService.templateBuilder().osFamily(UBUNTU).options(runScript(bootScript).installPrivateKey(clusterSpec.readPrivateKey()).authorizePublicKey(clusterSpec.readPublicKey()));
    // TODO extract this logic elsewhere
    if (clusterSpec.getProvider().equals("ec2"))
        templateBuilder.imageNameMatches(".*10\\.?04.*").osDescriptionMatches("^ubuntu-images.*").architecture(Architecture.X86_32);
    Template template = templateBuilder.build();
    InstanceTemplate instanceTemplate = clusterSpec.getInstanceTemplate(CASSANDRA_ROLE);
    checkNotNull(instanceTemplate);
    int clusterSize = instanceTemplate.getNumberOfInstances();
    Set<? extends NodeMetadata> nodeMap;
    try {
        nodeMap = computeService.runNodesWithTag(clusterSpec.getClusterName(), clusterSize, template);
    } catch (RunNodesException e) {
        // TODO: can we do better here
        throw new IOException(e);
    }
    FirewallSettings.authorizeIngress(computeServiceContext, nodeMap, clusterSpec, CLIENT_PORT);
    List<NodeMetadata> nodes = Lists.newArrayList(nodeMap);
    List<NodeMetadata> seeds = getSeeds(nodes);
    // Pass list of all servers in cluster to configure script.
    String servers = Joiner.on(' ').join(getPrivateIps(seeds));
    byte[] configureScript = RunUrlBuilder.runUrls("apache/cassandra/post-configure " + servers);
    try {
        Map<? extends NodeMetadata, ExecResponse> responses = computeService.runScriptOnNodesMatching(runningWithTag(clusterSpec.getClusterName()), configureScript);
        assert responses.size() > 0 : "no nodes matched " + clusterSpec.getClusterName();
    } catch (RunScriptOnNodesException e) {
        // TODO: retry
        throw new IOException(e);
    }
    return new Cluster(getInstances(nodes));
}
Also used : ExecResponse(org.jclouds.ssh.ExecResponse) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) Cluster(org.apache.whirr.service.Cluster) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) IOException(java.io.IOException) ComputeService(org.jclouds.compute.ComputeService) Template(org.jclouds.compute.domain.Template) InstanceTemplate(org.apache.whirr.service.ClusterSpec.InstanceTemplate) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) RunNodesException(org.jclouds.compute.RunNodesException) RunScriptOnNodesException(org.jclouds.compute.RunScriptOnNodesException) InstanceTemplate(org.apache.whirr.service.ClusterSpec.InstanceTemplate)

Example 10 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project SimianArmy by Netflix.

the class AWSClient method connectSsh.

@Override
public SshClient connectSsh(String instanceId, LoginCredentials credentials) {
    ComputeService computeService = getJcloudsComputeService();
    String jcloudsId = getJcloudsId(instanceId);
    NodeMetadata node = getJcloudsNode(computeService, jcloudsId);
    node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(credentials).build();
    Utils utils = computeService.getContext().utils();
    SshClient ssh = utils.sshForNode().apply(node);
    ssh.connect();
    return ssh;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) SshClient(org.jclouds.ssh.SshClient) Utils(org.jclouds.compute.Utils) ComputeService(org.jclouds.compute.ComputeService)

Aggregations

NodeMetadata (org.jclouds.compute.domain.NodeMetadata)35 RunNodesException (org.jclouds.compute.RunNodesException)11 Template (org.jclouds.compute.domain.Template)9 ComputeService (org.jclouds.compute.ComputeService)7 IOException (java.io.IOException)6 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)6 Test (org.junit.Test)5 Exchange (org.apache.camel.Exchange)4 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)4 RunScriptOnNodesException (org.jclouds.compute.RunScriptOnNodesException)4 Statement (org.jclouds.scriptbuilder.domain.Statement)4 File (java.io.File)3 Set (java.util.Set)3 InstanceTemplate (org.apache.whirr.service.ClusterSpec.InstanceTemplate)3 ComputeMetadata (org.jclouds.compute.domain.ComputeMetadata)3 LoginCredentials (org.jclouds.domain.LoginCredentials)3 Predicate (com.google.common.base.Predicate)2 Properties (java.util.Properties)2 Host (org.apache.hive.ptest.execution.conf.Host)2 RunListBuilder (org.jclouds.chef.util.RunListBuilder)2