Package org.apache.whirr.service.jclouds

Examples of org.apache.whirr.service.jclouds.StatementBuilder


      eventSpecificActions(entry);

      Cluster cluster = entry.getValue().getCluster();

      StatementBuilder statementBuilder = entry.getValue()
          .getStatementBuilder();

      Set<Instance> instances = cluster.getInstancesMatching(onlyRolesIn(entry
          .getKey().getRoles()));

      String instanceIds = Joiner.on(", ").join(
          Iterables.transform(instances, new Function<Instance, String>() {
            @Override
            public String apply(@Nullable Instance instance) {
              return instance == null ? "<null>" : instance.getId();
            }
          }));

      LOG.info("Starting to run scripts on cluster for phase {}"
          + "instances: {}", phaseName, instanceIds);

      for (final Instance instance : instances) {
        final Statement statement = statementBuilder.build(clusterSpec,
            instance);

        futures.add(executorService.submit(new Callable<ExecResponse>() {
          @Override
          public ExecResponse call() {
View Full Code Here


    Set<Instance> allInstances = Sets.newLinkedHashSet();

    for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {

      final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      final StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();

      final ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
      final ComputeService computeService = computeServiceContext.getComputeService();

      Credentials credentials = new Credentials(clusterSpec.getIdentity(), clusterSpec.getCredential());
     
      if (numberAllocated == 0) {
        for (ComputeMetadata compute : computeService.listNodes()) {
          if (!(compute instanceof NodeMetadata)) {
            throw new IllegalArgumentException("Not an instance of NodeMetadata: " + compute);
          }
          nodes.add((NodeMetadata) compute);
        }
      }

      int num = entry.getKey().getNumberOfInstances();
      final List<NodeMetadata> templateNodes =
        nodes.subList(numberAllocated, numberAllocated + num);
      numberAllocated += num;
     
      final Set<Instance> templateInstances = getInstances(
          credentials, entry.getKey().getRoles(), templateNodes
      );
      allInstances.addAll(templateInstances);
     
      for (final Instance instance : templateInstances) {
        final Statement statement = statementBuilder.build(clusterSpec, instance);

        futures.add(executorService.submit(new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            LOG.info("Running script on: {}", instance.getId());
View Full Code Here

    for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
      final InstanceTemplate instanceTemplate = entry.getKey();
      final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();

      final int maxNumberOfRetries = clusterSpec.getMaxStartupRetries();
      StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();

      ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
      final ComputeService computeService =
        computeServiceContext.getComputeService();
View Full Code Here

        final Set<String> hostset = new HashSet<String>();

        for (InetAddress host : hosts)
            hostset.add(host.getHostAddress());

        StatementBuilder statementBuilder = new StatementBuilder();
        statementBuilder.addStatement(Statements.call(functionName, functionArgs));
        Credentials credentials = new Credentials(clusterSpec.getClusterUser(), clusterSpec.getPrivateKey());

        Map<? extends NodeMetadata,ExecResponse> results;
        try
        {
View Full Code Here

  private StatementBuilder statementBuilder;

  @Before
  public void setUp() throws Exception {
    statementBuilder = new StatementBuilder();
  }
View Full Code Here

  public Cluster execute(ClusterSpec clusterSpec, Cluster cluster) throws IOException, InterruptedException {
   
    Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap();
    Cluster newCluster = cluster;
    for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) {
      StatementBuilder statementBuilder = new StatementBuilder();
      statementBuilder.addStatement(Statements.call("install_runurl"));
      ClusterActionEvent event = new ClusterActionEvent(getAction(),
          clusterSpec, newCluster, statementBuilder);
      eventMap.put(instanceTemplate, event);
      for (String role : instanceTemplate.getRoles()) {
        ClusterActionHandler handler = handlerMap.get(role);
View Full Code Here

    // initialize startup processes per InstanceTemplates
    for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
      final InstanceTemplate instanceTemplate = entry.getKey();
      final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      final int maxNumberOfRetries = clusterSpec.getMaxStartupRetries();
      StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
      ComputeServiceContext computeServiceContext =
        ComputeServiceContextBuilder.build(getComputeServiceContextFactory(), clusterSpec);
      final ComputeService computeService =
        computeServiceContext.getComputeService();
      final Template template = buildTemplate(clusterSpec, computeService,
View Full Code Here

      throws IOException {
   
    for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
      ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      Cluster cluster = entry.getValue().getCluster();
      StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
      ComputeServiceContext computeServiceContext =
        ComputeServiceContextBuilder.build(getComputeServiceContextFactory(), clusterSpec);
      ComputeService computeService = computeServiceContext.getComputeService();
      Credentials credentials = new Credentials(
          clusterSpec.getClusterUser(),
          clusterSpec.getPrivateKey());
      try {
        LOG.info("Running configuration script");
        if (LOG.isDebugEnabled())
          LOG.debug("Running script:\n{}", statementBuilder.render(OsFamily.UNIX));
        computeService.runScriptOnNodesMatching(
            toNodeMetadataPredicate(clusterSpec, cluster, entry.getKey().getRoles()),
            statementBuilder,
            RunScriptOptions.Builder.overrideCredentialsWith(credentials));
        LOG.info("Configuration script run completed");
View Full Code Here

TOP

Related Classes of org.apache.whirr.service.jclouds.StatementBuilder

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.