Package org.jclouds.compute

Examples of org.jclouds.compute.ComputeService


 
  @Override
  public ZooKeeperCluster launchCluster(ClusterSpec clusterSpec) throws IOException {
    ComputeServiceContext computeServiceContext =
      ComputeServiceContextBuilder.build(clusterSpec);
    ComputeService computeService = computeServiceContext.getComputeService();

    byte[] bootScript = RunUrlBuilder.runUrls(
      "sun/java/install",
      "apache/zookeeper/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(ZOOKEEPER_ROLE);
    checkNotNull(instanceTemplate);
    int ensembleSize = instanceTemplate.getNumberOfInstances();
    Set<? extends NodeMetadata> nodeMap;
    try {
      nodeMap = computeService.runNodesWithTag(clusterSpec.getClusterName(), ensembleSize,
      template);
    } catch (RunNodesException e) {
      // TODO: can we do better here - proceed if ensemble is big enough?
      throw new IOException(e);
    }
   
    FirewallSettings.authorizeIngress(computeServiceContext, nodeMap, clusterSpec, CLIENT_PORT);
   
    List<NodeMetadata> nodes = Lists.newArrayList(nodeMap);
   
    // Pass list of all servers in ensemble to configure script.
    // Position is significant: i-th server has id i.
    String servers = Joiner.on(' ').join(getPrivateIps(nodes));
    byte[] configureScript = RunUrlBuilder.runUrls(
      "apache/zookeeper/post-configure " + servers);
    try {
      computeService.runScriptOnNodesMatching(runningWithTag(clusterSpec.getClusterName()), configureScript);
    } catch (RunScriptOnNodesException e) {
      // TODO: retry
      throw new IOException(e);
    }
   
View Full Code Here


  @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) {
View Full Code Here

   * Stop the cluster and destroy all resources associated with it.
   * @throws IOException if there is a problem while stopping the cluster. The
   * cluster may or may not have been stopped.
   */
  public void destroyCluster(ClusterSpec clusterSpec) throws IOException {
    ComputeService computeService =
      ComputeServiceContextBuilder.build(clusterSpec).getComputeService();
    computeService.destroyNodesMatching(withTag(clusterSpec.getClusterName()));
  }
View Full Code Here

 
  @Override
  public HadoopCluster launchCluster(ClusterSpec clusterSpec) throws IOException {
    ComputeServiceContext computeServiceContext =
      ComputeServiceContextBuilder.build(clusterSpec);
    ComputeService computeService = computeServiceContext.getComputeService();
   
    // Launch Hadoop "master" (NN and JT)
    // deal with user packages and autoshutdown with extra runurls
    String hadoopInstallRunUrl = clusterSpec.getConfiguration().getString(
        "whirr.hadoop-install-runurl", "apache/hadoop/install");
    byte[] nnjtBootScript = RunUrlBuilder.runUrls(
      "sun/java/install",
      String.format("%s nn,jt -c %s", hadoopInstallRunUrl,
          clusterSpec.getProvider()));

    TemplateBuilder masterTemplateBuilder = computeService.templateBuilder()
      .osFamily(UBUNTU)
      .options(runScript(nnjtBootScript)
      .installPrivateKey(clusterSpec.readPrivateKey())
      .authorizePublicKey(clusterSpec.readPublicKey()));
   
    // TODO extract this logic elsewhere
    if (clusterSpec.getProvider().equals("ec2"))
      masterTemplateBuilder.imageNameMatches(".*10\\.?04.*")
      .osDescriptionMatches("^ubuntu-images.*")
      .architecture(Architecture.X86_32);
   
    Template masterTemplate = masterTemplateBuilder.build();
   
    InstanceTemplate instanceTemplate = clusterSpec.getInstanceTemplate(MASTER_ROLE);
    checkNotNull(instanceTemplate);
    checkArgument(instanceTemplate.getNumberOfInstances() == 1);
    Set<? extends NodeMetadata> nodes;
    try {
      nodes = computeService.runNodesWithTag(
          clusterSpec.getClusterName(), 1, masterTemplate);
    } catch (RunNodesException e) {
      // TODO: can we do better here (retry?)
      throw new IOException(e);
    }
    NodeMetadata node = Iterables.getOnlyElement(nodes);
    InetAddress namenodePublicAddress = InetAddress.getByName(Iterables.get(node.getPublicAddresses(),0));
    InetAddress jobtrackerPublicAddress = InetAddress.getByName(Iterables.get(node.getPublicAddresses(),0));
   
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        WEB_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        NAMENODE_WEB_UI_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        JOBTRACKER_WEB_UI_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        namenodePublicAddress.getHostAddress(), NAMENODE_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        namenodePublicAddress.getHostAddress(), JOBTRACKER_PORT);
    if (!namenodePublicAddress.equals(jobtrackerPublicAddress)) {
      FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
          jobtrackerPublicAddress.getHostAddress(), NAMENODE_PORT);
      FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
          jobtrackerPublicAddress.getHostAddress(), JOBTRACKER_PORT);
    }

    // Launch slaves (DN and TT)
    byte[] slaveBootScript = RunUrlBuilder.runUrls(
      "sun/java/install",
      String.format("%s dn,tt -n %s -j %s",
          hadoopInstallRunUrl,
          namenodePublicAddress.getHostName(),
          jobtrackerPublicAddress.getHostName()));

    TemplateBuilder slaveTemplateBuilder = computeService.templateBuilder()
      .osFamily(UBUNTU)
      .options(runScript(slaveBootScript)
      .installPrivateKey(clusterSpec.readPrivateKey())
      .authorizePublicKey(clusterSpec.readPublicKey()));

    // TODO extract this logic elsewhere
    if (clusterSpec.getProvider().equals("ec2"))
      slaveTemplateBuilder.imageNameMatches(".*10\\.?04.*")
      .osDescriptionMatches("^ubuntu-images.*")
      .architecture(Architecture.X86_32);
   
    Template slaveTemplate = slaveTemplateBuilder.build();
   
    instanceTemplate = clusterSpec.getInstanceTemplate(WORKER_ROLE);
    checkNotNull(instanceTemplate);

    Set<? extends NodeMetadata> workerNodes;
    try {
      workerNodes = computeService.runNodesWithTag(clusterSpec.getClusterName(),
        instanceTemplate.getNumberOfInstances(), slaveTemplate);
    } catch (RunNodesException e) {
      // TODO: don't bail out if only a few have failed to start
      throw new IOException(e);
    }
View Full Code Here

  public void destroyInstance(ClusterSpec clusterSpec, String instanceId) throws IOException {
    LOG.info("Destroying instance {}", instanceId);

    /* Destroy the instance */
    ComputeService computeService = getCompute().apply(clusterSpec).getComputeService();
    computeService.destroyNode(instanceId);

    /* .. and update the cluster state storage */
    ClusterStateStore store = getClusterStateStore(clusterSpec);
    Cluster cluster = store.load();
    cluster.removeInstancesMatching(withIds(instanceId));
View Full Code Here

  }

  @Deprecated
  public Set<? extends NodeMetadata> getNodes(ClusterSpec clusterSpec)
    throws IOException, InterruptedException {
    ComputeService computeService = getCompute().apply(clusterSpec).getComputeService();
    return computeService.listNodesDetailsMatching(
      runningInGroup(clusterSpec.getClusterName()));
  }
View Full Code Here

 
  public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(final ClusterSpec spec,
      Predicate<NodeMetadata> condition, final Statement statement) throws IOException, RunScriptOnNodesException {
   
    ComputeServiceContext computeServiceContext = getCompute().apply(spec);
    ComputeService computeService = computeServiceContext.getComputeService();
    Cluster cluster = getClusterStateStore(spec).load();

    RunScriptOptions options = RunScriptOptions.Builder.runAsRoot(false).wrapInInitScript(false);
    return computeService.runScriptOnNodesMatching(Predicates.<NodeMetadata>and(condition, runningIn(cluster)), statement, options);
  }
View Full Code Here

 
  @Override
  public Set<? extends NodeMetadata> getNodes(ClusterSpec clusterSpec)
      throws IOException, InterruptedException {
    ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
    ComputeService computeService = computeServiceContext.getComputeService();
    return computeService.listNodesDetailsMatching(Predicates.in(computeService.listNodes()));
  }
View Full Code Here

 
  public ListenableFuture<ExecResponse> runStatementOnInstanceInCluster(StatementBuilder statementBuilder,
      Instance instance, ClusterSpec clusterSpec, RunScriptOptions options) {
    Statement statement = statementBuilder.name(getAction() + "-"
          + Joiner.on('_').join(instance.getRoles())).build(clusterSpec, instance);
    ComputeService compute = getCompute().apply(clusterSpec).getComputeService();
    return compute.submitScriptOnNode(
              instance.getId(),
              statement,
              options);
  }
View Full Code Here

  protected void postRunScriptsActions(
      Map<InstanceTemplate, ClusterActionEvent> eventMap) throws IOException {
    ClusterSpec clusterSpec = eventMap.values().iterator().next()
        .getClusterSpec();
    LOG.info("Destroying " + clusterSpec.getClusterName() + " cluster");
    ComputeService computeService = getCompute().apply(clusterSpec)
        .getComputeService();
    computeService.destroyNodesMatching(inGroup(clusterSpec.getClusterName()));
    LOG.info("Cluster {} destroyed", clusterSpec.getClusterName());
  }
View Full Code Here

TOP

Related Classes of org.jclouds.compute.ComputeService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.