public static TaskFactory<?> installChef(String chefDirectory, boolean force) { // TODO check on entity whether it is chef _server_ String installCmd = cdAndRun(chefDirectory, ChefBashCommands.INSTALL_FROM_OPSCODE); if (!force) installCmd = BashCommands.alternatives("which chef-solo", installCmd); return SshEffectorTasks.ssh(installCmd).summary("install chef"); }
public static TaskFactory<?> runChef(String runDir, String phase) { // TODO chef server return SshEffectorTasks.ssh(cdAndRun(runDir, "sudo chef-solo -c "+phase+".rb -j "+phase+".json -ldebug")). summary("run chef for "+phase).requiringExitCodeZero(); }
@Override public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) { JcloudsSshMachineLocation ssh = (JcloudsSshMachineLocation) machine; String name = ssh.getOptionalNode().get().getName(); List<String> commands = ImmutableList.of( String.format("echo %s | ( %s )", name, BashCommands.sudo("tee /etc/hostname")), String.format("echo 127.0.0.1 localhost | ( %s )", BashCommands.sudo("tee /etc/hosts"))); DynamicTasks.queue(SshEffectorTasks.ssh(commands) .machine(ssh) .requiringExitCodeZero()).block(); LOG.debug("Set {} hostname to {}", new Object[] { ssh, name }); } }
protected ProcessTaskWrapper<Integer> exec(SshMachineLocation machine, boolean asRoot, String... cmds) { SshEffectorTaskFactory<Integer> taskFactory = SshEffectorTasks.ssh(machine, cmds); if (asRoot) taskFactory.runAsRoot(); ProcessTaskWrapper<Integer> result = DynamicTasks.queue(taskFactory).block(); if (result.get() != 0) { throw new IllegalStateException("SetHostnameCustomizer got exit code "+result.get()+" executing on machine "+machine +"; cmds="+Arrays.asList(cmds)+"; stdout="+result.getStdout()+"; stderr="+result.getStderr()); } return result; } }
/** see {@link ChefConfig#CHEF_RUN_CONVERGE_TWICE} for background on why 'twice' is available */ public static TaskFactory<?> runChef(String runDir, String phase, Boolean twice) { String cmd = "sudo chef-solo -c "+phase+".rb -j "+phase+".json -ldebug"; if (twice!=null && twice) cmd = BashCommands.alternatives(cmd, cmd); return SshEffectorTasks.ssh(cdAndRun(runDir, cmd)). summary("run chef for "+phase).requiringExitCodeZero(); }
/** see {@link ChefConfig#CHEF_RUN_CONVERGE_TWICE} for background on why 'twice' is available */ public static TaskFactory<?> runChef(String runDir, String phase, Boolean twice) { String cmd = "sudo chef-solo -c "+phase+".rb -j "+phase+".json -ldebug"; if (twice!=null && twice) cmd = BashCommands.alternatives(cmd, cmd); return SshEffectorTasks.ssh(cdAndRun(runDir, cmd)). summary("run chef for "+phase).requiringExitCodeZero(); }
protected boolean tryCheckStartWindowsService() { if (getWindowsServiceName()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!((Integer)0).equals(DynamicTasks.queue(SshEffectorTasks.ssh("sc query \""+getWindowsServiceName()+"\" | find \"RUNNING\"").runAsCommand()).get())) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (windowsService "+getWindowsServiceName()+")"); } return true; }
protected boolean tryCheckStartService() { if (getServiceName()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!((Integer)0).equals(DynamicTasks.queue(SshEffectorTasks.ssh("/etc/init.d/"+getServiceName()+" status").runAsRoot()).get())) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (service "+getServiceName()+")"); } return true; }
protected boolean tryCheckStartWindowsService() { if (getWindowsServiceName()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!((Integer)0).equals(DynamicTasks.queue(SshEffectorTasks.ssh("sc query \""+getWindowsServiceName()+"\" | find \"RUNNING\"").runAsCommand()).get())) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (windowsService "+getWindowsServiceName()+")"); } return true; }
@Override public Task<Integer> sshTaskApply(AmbariAgent ambariAgent) { return SshEffectorTasks .ssh(installPackageOr(ImmutableMap.of(), "mysql-connector-java", installPackageOrFail(ImmutableMap.of(), "libmysql-java"))) .summary("Initialise Ranger requirements on " + ambariAgent.getId()) .machine(EffectorTasks.getSshMachine(ambariAgent)) .newTask() .asTask(); } }
protected boolean tryCheckStartService() { if (getServiceName()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!((Integer)0).equals(DynamicTasks.queue(SshEffectorTasks.ssh("/etc/init.d/"+getServiceName()+" status").runAsRoot()).get())) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (service "+getServiceName()+")"); } return true; }
@Override public Task<Integer> sshTaskApply(AmbariServer ambariServer) { return SshEffectorTasks .ssh( installPackageOr(ImmutableMap.of(), "mysql-connector-java", installPackageOrFail(ImmutableMap.of(), "libmysql-java")), sudo("ambari-server setup --jdbc-db=mysql --jdbc-driver=/usr/share/java/mysql-connector-java.jar")) .summary("Initialise Ranger requirements on " + ambariServer.getId()) .machine(EffectorTasks.getSshMachine(ambariServer)) .newTask() .asTask(); } }
@Override protected Integer getPid(Entity mysql) { ProcessTaskWrapper<Integer> t = Entities.submit(mysql, SshEffectorTasks.ssh("sudo cat "+ChefSoloDriverToyMySqlEntity.PID_FILE)); return Integer.parseInt(t.block().getStdout().trim()); }
@Override protected Integer getPid(Entity mysql) { ProcessTaskWrapper<Integer> t = Entities.submit(mysql, SshEffectorTasks.ssh("sudo cat "+ChefSoloDriverToyMySqlEntity.PID_FILE)); return Integer.parseInt(t.block().getStdout().trim()); }
@Test(groups="Integration") public void testSshEchoHello() { ProcessTaskWrapper<Integer> t = submit(SshEffectorTasks.ssh("sleep 1 ; echo hello world")); Assert.assertFalse(t.isDone()); Assert.assertEquals(t.get(), (Integer)0); Assert.assertEquals(t.getTask().getUnchecked(), (Integer)0); Assert.assertEquals(t.getStdout().trim(), "hello world"); }
protected boolean tryStopWindowsService() { if (getWindowsServiceName()==null) return false; int result = DynamicTasks.queue(SshEffectorTasks.ssh("sc query \""+getWindowsServiceName()+"\"").runAsCommand()).get(); if (0==result) return true; if (entity().getAttribute(Attributes.SERVICE_STATE_ACTUAL)!=Lifecycle.RUNNING) return true; throw new IllegalStateException("The process for "+entity()+" appears could not be stopped (exit code "+result+" to service stop)"); }
@Override public String call(ConfigBag parameters) { return DynamicTasks.queue(SshEffectorTasks.ssh( BashCommands.pipeTextTo( parameters.get(SCRIPT), BashCommands.sudoAsUser("postgres", "psql --file -"))) .requiringExitCodeZero()).getStdout(); } }
@Override public void changePassword(String oldPass, String newPass) { DynamicTasks.queue( SshEffectorTasks.ssh( "cd "+getRunDir(), getBaseDir()+"/bin/mysqladmin --defaults-file="+getConfigFile()+" --password=" + oldPass + " password "+newPass) .summary("setting password") .requiringExitCodeZero()); }
public ProcessTaskWrapper<Integer> executeScriptFromInstalledFileAsync(String filenameAlreadyInstalledAtServer) { return DynamicTasks.queue( SshEffectorTasks.ssh( "cd "+getRunDir(), sudoAsUser("postgres", getInstallDir() + "/bin/psql -p " + entity.getAttribute(PostgreSqlNode.POSTGRESQL_PORT) + " -v ON_ERROR_STOP=1 --file " + filenameAlreadyInstalledAtServer)) .requiringExitCodeZero() .summary("executing datastore script "+filenameAlreadyInstalledAtServer)); }
protected boolean tryCheckStartPid() { if (getPidFile()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!DynamicTasks.queue(SshEffectorTasks.isPidFromFileRunning(getPidFile()).runAsRoot()).get()) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (pid file "+getPidFile()+")"); } // and set the PID entity().sensors().set(Attributes.PID, Integer.parseInt(DynamicTasks.queue(SshEffectorTasks.ssh("cat "+getPidFile()).runAsRoot()).block().getStdout().trim())); return true; }