public static TaskFactory<?> buildChefFile(String runDirectory, String chefDirectory, String phase, Iterable<? extends String> runList, Map<String, Object> optionalAttributes) { // TODO if it's server, try knife first // TODO configure add'l properties String phaseRb = "root = " + "'"+runDirectory+"'" // recommended alternate to runDir is the following, but it is not available in some rubies //+ File.absolute_path(File.dirname(__FILE__))"+ + "\n"+ "file_cache_path root\n"+ // "cookbook_path root + '/cookbooks'\n"; "cookbook_path '"+chefDirectory+"'\n"; Map<String,Object> phaseJsonMap = MutableMap.of(); if (optionalAttributes!=null) phaseJsonMap.putAll(optionalAttributes); if (runList!=null) phaseJsonMap.put("run_list", ImmutableList.copyOf(runList)); Gson json = new GsonBuilder().create(); String phaseJson = json.toJson(phaseJsonMap); return Tasks.sequential("build chef files for "+phase, SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".rb").contents(phaseRb).createDirectory(), SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".json").contents(phaseJson)); }
public static TaskFactory<?> buildChefFile(String runDirectory, String chefDirectory, String phase, Iterable<? extends String> runList, Map<String, Object> optionalAttributes) { // TODO if it's server, try knife first // TODO configure add'l properties String phaseRb = "root = " + "'"+runDirectory+"'" // recommended alternate to runDir is the following, but it is not available in some rubies //+ File.absolute_path(File.dirname(__FILE__))"+ + "\n"+ "file_cache_path root\n"+ // "cookbook_path root + '/cookbooks'\n"; "cookbook_path '"+chefDirectory+"'\n"; Map<String,Object> phaseJsonMap = MutableMap.of(); if (optionalAttributes!=null) phaseJsonMap.putAll(optionalAttributes); if (runList!=null) phaseJsonMap.put("run_list", ImmutableList.copyOf(runList)); Gson json = new GsonBuilder().create(); String phaseJson = json.toJson(phaseJsonMap); return Tasks.sequential("build chef files for "+phase, SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".rb").contents(phaseRb).createDirectory(), SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".json").contents(phaseJson)); }
@Test(groups="Integration") public void testSshPut() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "f1"); SshPutTaskWrapper t = submit(SshEffectorTasks.put(fn).contents("hello world")); t.block(); Assert.assertEquals(FileUtils.readFileToString(new File(fn)), "hello world"); // and make sure this doesn't throw Assert.assertTrue(t.isDone()); Assert.assertTrue(t.isSuccessful()); Assert.assertEquals(t.get(), null); Assert.assertEquals(t.getExitCode(), (Integer)0); }
@Override public ProcessTaskWrapper<Integer> executeScriptAsync(String commands) { String filename = "mariadb-commands-"+Identifiers.makeRandomId(8); DynamicTasks.queue(SshEffectorTasks.put(Urls.mergePaths(getRunDir(), filename)).contents(commands).summary("copying datastore script to execute "+filename)); return executeScriptFromInstalledFileAsync(filename); }
@Override public void customizeService() { DynamicTasks.queue( SshEffectorTasks.put("/tmp/" + getServiceScriptFileName()) .contents(TemplateProcessor.processTemplateContents( ResourceUtils.create().getResourceAsString(config().get(CustomService.SERVICE_SCRIPT_TEMPLATE_URL)), this, ImmutableMap.<String,String>of())), SshEffectorTasks.put("/tmp/" + getMetaInfoXmlFileName()) .contents(TemplateProcessor.processTemplateContents( ResourceUtils.create().getResourceAsString(config().get(CustomService.SERVICE_METAINFO_TEMPLATE_URL)), this, ImmutableMap.<String,String>of())), SshEffectorTasks.ssh( sudo(format("mkdir -p %s", getServiceDirectory())), sudo(format("mv /tmp/%s %s", getMetaInfoXmlFileName(), getServiceDirectory())), sudo(format("mkdir -p %s", getServiceScriptDirectory())), sudo(format("mv /tmp/%s %s/",getServiceScriptFileName(), getServiceScriptDirectory())), sudo(format("mkdir -p %s", getServiceConfigDirectory())))); Map<String, ?> serviceConf = getConfig(CustomService.CUSTOM_SERVICE_CONF); for (Entry<String, ?> entry: serviceConf.entrySet()) { DynamicTasks.queue( SshEffectorTasks.put("/tmp/" + getServicePropertyFileName(entry.getKey())) .contents(prepareServiceConfigurationXmlContent(entry.getKey(), (Map) entry.getValue())), SshEffectorTasks.ssh( sudo(format("mv %s %s/", "/tmp/" + getServicePropertyFileName(entry.getKey()), getServiceConfigDirectory())))); } DynamicTasks.waitForLast(); }
@Override public ProcessTaskWrapper<Integer> executeScriptAsync(String commands) { String filename = "mysql-commands-"+Identifiers.makeRandomId(8); DynamicTasks.queue(SshEffectorTasks.put(Urls.mergePaths(getRunDir(), filename)).contents(commands).summary("copying datastore script to execute "+filename)); return executeScriptFromInstalledFileAsync(filename); }
@Override protected String startProcessesAtMachine(Supplier<MachineLocation> machineS) { DynamicTasks.queue( SshEffectorTasks.ssh( "mkdir "+dir(entity), "cd "+dir(entity), BashCommands.downloadToStdout(downloadUrl(entity, isLocalhost(machineS)))+" | tar xvz" ).summary("download mysql").returning(SshTasks.returningStdoutLoggingInfo(log, true))); if (isLinux(machineS)) { DynamicTasks.queue(SshEffectorTasks.ssh(BashCommands.installPackage("libaio1"))); } DynamicTasks.queue( SshEffectorTasks.put(".my.cnf") .contents(String.format("[mysqld]\nbasedir=%s/%s\n", dir(entity), installDir(entity, isLocalhost(machineS)))), SshEffectorTasks.ssh( "cd "+dir(entity)+"/*", "./scripts/mysql_install_db", "./support-files/mysql.server start > out.log 2> err.log < /dev/null" ).summary("setup and run mysql").returning(SshTasks.returningStdoutLoggingInfo(log, true))); return "submitted start"; } @Override
String contents = processTemplate(configUrl); DynamicTasks.queue( SshEffectorTasks.put("/tmp/postgresql.conf").contents(contents), SshEffectorTasks.ssh(sudoAsUser("postgres", "cp /tmp/postgresql.conf " + getDataDir() + "/postgresql.conf"))); String contents = processTemplate(authConfigUrl); DynamicTasks.queue( SshEffectorTasks.put("/tmp/pg_hba.conf").contents(contents), SshEffectorTasks.ssh(sudoAsUser("postgres", "cp /tmp/pg_hba.conf " + getDataDir() + "/pg_hba.conf")));