org.jclouds.scriptbuilder.domain.Statements.exec()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中org.jclouds.scriptbuilder.domain.Statements.exec()方法的一些代码示例,展示了Statements.exec()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Statements.exec()方法的具体详情如下:
包路径:org.jclouds.scriptbuilder.domain.Statements
类名称:Statements
方法名:exec

Statements.exec介绍

[英]interprets and adds a newline to the statement
[中]解释并在语句中添加换行符

代码示例

代码示例来源:origin: jclouds/legacy-jclouds

@Override
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);
}

代码示例来源:origin: org.jclouds/jclouds-scriptbuilder

@Override
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);
}

代码示例来源:origin: jclouds/legacy-jclouds

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

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public String render(OsFamily family) {
 if (family == OsFamily.WINDOWS)
   return exec(String.format("{rm} %s 2{closeFd}", path)).render(family);
 else
   return exec(String.format("{rm} %s", path)).render(family);
}

代码示例来源:origin: jclouds/legacy-jclouds

/**
* This script will be executed as the root user upon system startup. This
* script gets a prologue, so no #!/bin/bash required, path set up, etc
* 
*/
public TemplateOptions runScript(String script) {
 return runScript(Statements.exec(script));
}

代码示例来源:origin: io.cloudsoft.jclouds/jclouds-compute

/**
* This script will be executed as the root user upon system startup. This
* script gets a prologue, so no #!/bin/bash required, path set up, etc
* 
*/
public TemplateOptions runScript(String script) {
 return runScript(Statements.exec(script));
}

代码示例来源:origin: jclouds/legacy-jclouds

@VisibleForTesting
void createSoloConfiguration(ImmutableList.Builder<Statement> statements) {
 statements.add(exec("{md} " + fileCachePath));
 for (String path : cookbookPath) {
   statements.add(exec("{md} " + path));
 }
 String cookbookPathJoined = Joiner.on(',').join(transform(cookbookPath, quote()));
 statements.add(createOrOverwriteFile(
    fileCachePath + "/solo.rb",
    ImmutableSet.of("file_cache_path \"" + fileCachePath + "\"", //
       "cookbook_path [" + cookbookPathJoined + "]", "role_path \"" + rolePath + "\"", "data_bag_path \""
          + databagPath + "\"")));
}

代码示例来源:origin: org.jclouds/jclouds-scriptbuilder

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

代码示例来源:origin: com.amysta.jclouds/jclouds-scriptbuilder

@VisibleForTesting
void createRolesIfNecessary(ImmutableList.Builder<Statement> statements) {
 // The roles directory must contain one file for each role definition
 if (roles.isPresent() && !roles.get().isEmpty()) {
   statements.add(exec("{md} " + rolePath));
   for (Role role : roles.get()) {
    statements.add(createOrOverwriteFile(rolePath + "/" + role.getName() + ".json",
       ImmutableSet.of(role.toJsonString())));
   }
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@VisibleForTesting
void createRolesIfNecessary(ImmutableList.Builder<Statement> statements) {
 // The roles directory must contain one file for each role definition
 if (roles.isPresent() && !roles.get().isEmpty()) {
   statements.add(exec("{md} " + rolePath));
   for (Role role : roles.get()) {
    statements.add(createOrOverwriteFile(rolePath + "/" + role.getName() + ".json",
       ImmutableSet.of(role.toJsonString())));
   }
 }
}

代码示例来源:origin: org.jclouds/jclouds-scriptbuilder

@VisibleForTesting
void createRolesIfNecessary(ImmutableList.Builder<Statement> statements) {
 // The roles directory must contain one file for each role definition
 if (roles.isPresent() && !roles.get().isEmpty()) {
   statements.add(exec("{md} " + rolePath));
   for (Role role : roles.get()) {
    statements.add(createOrOverwriteFile(rolePath + "/" + role.getName() + ".json",
       ImmutableSet.of(role.toJsonString())));
   }
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

public String render(OsFamily family) {
 checkNotNull(family, "family");
 if (family == OsFamily.WINDOWS)
   throw new UnsupportedOperationException("windows not yet implemented");
 Builder<Statement> statements = ImmutableList.builder();
 statements.add(createOrOverwriteFile(sudoers, ImmutableSet.of("root ALL = (ALL) ALL", "%wheel ALL = (ALL) NOPASSWD:ALL")));
 statements.add(exec("chmod 0440 " + sudoers));
 return new StatementList(statements.build()).render(family);
}

代码示例来源:origin: jclouds/legacy-jclouds

private static Statement authorizePortInIpTables() {
 return new StatementList(
    exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"),
    exec("iptables-save"));
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testWhenNotAdminAccess() {
 AdminAccess.Configuration configuration = createMock(AdminAccess.Configuration.class);
 InitAdminAccess initAdminAccess = new InitAdminAccess(configuration);
 replay(configuration);
 initAdminAccess.visit(Statements.exec("echo hello"));
 initAdminAccess.visit(Statements.newStatementList(Statements.exec("echo hello")));
 verify(configuration);
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testWhenNotAdminAccess() {
 Statement statement = Statements.exec("echo hello");
 assertEquals(CredentialsFromAdminAccess.INSTANCE.apply(statement), null);
 Statement statementList = Statements.newStatementList(statement);
 assertEquals(CredentialsFromAdminAccess.INSTANCE.apply(statementList), null);
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testCreateDatabagsIfNecessaryWithOneDatabagAndCustomPath() {
 ImmutableList.Builder<Statement> statements = ImmutableList.builder();
 DataBag databag = DataBag.builder().name("foo").item("item", "{\"foo\":\"bar\"}").build();
 ChefSolo solo = ChefSolo.builder().dataBagPath("/tmp/databags").defineDataBag(databag).build();
 solo.createDatabagsIfNecessary(statements);
 ImmutableList<Statement> statementList = statements.build();
 Statement expected = createOrOverwriteFile("/tmp/databags/foo/item.json", ImmutableSet.of("{\"foo\":\"bar\"}"));
 assertEquals(statementList.size(), 3);
 assertEquals(statementList.get(0), exec("{md} /tmp/databags"));
 assertEquals(statementList.get(1), exec("{md} /tmp/databags/" + databag.getName()));
 assertEquals(statementList.get(2).render(OsFamily.UNIX), expected.render(OsFamily.UNIX));
}

代码示例来源:origin: io.brooklyn/brooklyn-locations-jclouds

public Boolean call() {
    Statement statement = Statements.newStatementList(exec("hostname"));
    // NB this assumes passwordless sudo !
    ExecResponse response = computeService.runScriptOnNode(nodeRef.getId(), statement, 
        overrideLoginCredentials(expectedCredentialsRef).runAsRoot(false));
    return response.getExitStatus() == 0;
  }})
.limitTimeTo(delayMs, MILLISECONDS)

代码示例来源:origin: jclouds/legacy-jclouds

public void simpleTest() {
 RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"),
    wrapInInitScript(false).runAsRoot(false));
 testMe.init();
 sshClient.connect();
 expect(sshClient.getUsername()).andReturn("tester");
 expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
 expect(sshClient.exec("echo $USER\n" + "echo $USER\n")).andReturn(new ExecResponse("tester\ntester\n", null, 0));
 sshClient.disconnect();
 replay(sshClient);
 testMe.call();
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test(expectedExceptions = IllegalStateException.class)
public void testWithoutInitThrowsIllegalStateException() {
 Statement command = exec("doFoo");
 NodeMetadata node = new NodeMetadataBuilder().ids("id").status(Status.RUNNING).credentials(
      LoginCredentials.builder().user("tester").password("notalot").build()).build();
 SshClient sshClient = createMock(SshClient.class);
 replay(sshClient);
 RunScriptOnNodeAsInitScriptUsingSsh testMe = new RunScriptOnNodeAsInitScriptUsingSsh(Functions
      .forMap(ImmutableMap.of(node, sshClient)), eventBus, InitScriptConfigurationForTasks.create()
      .appendIncrementingNumberToAnonymousTaskNames(), node, command, new RunScriptOptions());
 testMe.call();
}

代码示例来源:origin: jclouds/legacy-jclouds

public static Statement install() {
 return new StatementList(
    AdminAccess.builder().adminUsername("web").build(),
    InstallJDK.fromOpenJDK(),
    authorizePortInIpTables(),
    extractTargzAndFlattenIntoDirectory(JETTY_URL, JETTY_HOME),
    exec("chown -R web " + JETTY_HOME));
}

相关文章