Package org.jclouds.scriptbuilder.domain

Examples of org.jclouds.scriptbuilder.domain.Statement


   * {@link ClusterActionEvent}.
   */
  public static void addRunUrl(ClusterActionEvent event, String runUrl,
      String... args)
      throws IOException {
    Statement statement = new RunUrlStatement(
        event.getClusterSpec().getRunUrlBase(), runUrl, args);
    addStatement(event, statement);
  }
View Full Code Here


      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() {

            LOG.info("Running {} phase script on: {}", phaseName,
                instance.getId());
            if (LOG.isDebugEnabled()) {
              LOG.debug("{} phase script on: {}\n{}", new Object[] { phaseName,
                  instance.getId(), statement.render(OsFamily.UNIX) });
            }

            try {
              return computeService.runScriptOnNode(
                  instance.getId(),
View Full Code Here

          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());

            if (LOG.isDebugEnabled()) {
              LOG.debug("Running script:\n{}", statement.render(OsFamily.UNIX));
            }

            computeService.runScriptOnNode(instance.getId(), statement);
            LOG.info("Script run completed on: {}", instance.getId());
View Full Code Here

    }
  }

  @Test
  public void testBinMahout() throws Exception {
    Statement binMahout = Statements.exec("source /etc/profile; $MAHOUT_HOME/bin/mahout");

    Cluster.Instance mahoutInstance = findMahoutInstance();
    Predicate<NodeMetadata> mahoutClientRole = and(alwaysTrue(), withIds(mahoutInstance.getId()));

    Map<? extends NodeMetadata, ExecResponse> responses = controller.runScriptOnNodesMatching(clusterSpec, mahoutClientRole, binMahout);
View Full Code Here

     */
    public NodeMetadata createDummyAWSEC2Node(ConnectionResponseDTO cloud, String securityGroup) throws Exception {
        ComputeService computeService = getComputeService(cloud);

        // Create a node
        Statement bootInstructions = AdminAccess.standard();
        NodeMetadata newNode = getOnlyElement(computeService.createNodesInGroup(securityGroup, 1,
                runScript(bootInstructions)));

        return newNode;
    }
View Full Code Here

         String shadowPasswordEntry = cryptFunction.apply(password);
         String shadowFile = "/etc/shadow";
         // note we are using awk variables so that the user can be defined as a
         // shell variable (ex. $USER) As the block is in single quotes,
         // shell interpolation wouldn't work otherwise
         Statement replaceEntryInTempFile = exec(format(
               "awk -v user=^%1$s: -v password='%2$s' 'BEGIN { FS=OFS=\":\" } $0 ~ user { $2 = password } 1' %3$s >%3$s.%1$s",
               login, shadowPasswordEntry, shadowFile));
         // would have preferred to use exec <>3 && style, but for some reason
         // the sha512 line breaks in both awk and sed during an inline
         // expansion. unfortunately, we have to save a temp file. In this case,
         // somewhat avoiding collisions by naming the file .user, conceding it
         // isn't using any locks to prevent overlapping changes
         Statement replaceShadowFile = exec(format("test -f %2$s.%1$s && mv %2$s.%1$s %2$s", login, shadowFile));
         return new StatementList(ImmutableList.of(replaceEntryInTempFile, replaceShadowFile)).render(family);
      } catch (Exception e) {
         propagate(e);
         return null;
      }
View Full Code Here

   public String render(OsFamily family) {
      if (family == OsFamily.WINDOWS) {
         throw new UnsupportedOperationException("windows not yet implemented");
      }

      Statement statement = version.isPresent() ? exec(String.format("gem install chef -v '%s' --no-rdoc --no-ri",
            version.get())) : exec("gem install chef --no-rdoc --no-ri");

      return statement.render(family);
   }
View Full Code Here

      this.params = checkNotNull(params, "params");
   }

   public String render(OsFamily family) {
      String linesToPrepend = Joiner.on('\n').withKeyValueSeparator(" ").join(params);
      Statement prependSshdConfig = exec(String.format(
               "exec 3<> %1$s && awk -v TEXT=\"%2$s\n\" 'BEGIN {print TEXT}{print}' %1$s >&3", sshdConfig,
               linesToPrepend));
      Statement reloadSshdConfig = exec("hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload");
      return newStatementList(prependSshdConfig, reloadSshdConfig).render(family);
   }
View Full Code Here

  @Test
  public void testRecipesWereRanInServiceBootstrap() throws Exception {

    // and shoudl be installed by the main handlers
    Statement testAnt = Statements.exec("ant -version");

    Map<? extends NodeMetadata, ExecResponse> responses = controller
        .runScriptOnNodesMatching(clusterSpec, allNodes, testAnt);

    printResponses(testAnt, responses);

    assertResponsesContain(responses, testAnt, "Apache Ant");

    Statement testMaven = Statements.exec("mvn --version");

    responses = controller.runScriptOnNodesMatching(clusterSpec, allNodes,
        testMaven);

    printResponses(testMaven, responses);
View Full Code Here

    Map<? extends NodeMetadata, ExecResponse> responses = runRecipe(java);

    printResponses(java, responses);

    Statement stmt = Statements.exec("java -version");

    responses = controller
        .runScriptOnNodesMatching(clusterSpec, allNodes, stmt);

    assertResponsesContain(responses, stmt, "Runtime Environment");
View Full Code Here

TOP

Related Classes of org.jclouds.scriptbuilder.domain.Statement

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.