@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(); } }
@Override public Task<Integer> sshTaskApply(AmbariAgent ambariAgent) { return SshEffectorTasks .ssh( installExecutable("mysql-server"), installPackageOr(ImmutableMap.of(), "mysql", installPackageOrFail(ImmutableMap.of(), "mysql-client")), alternatives(sudo("service mysqld restart"), sudo("service mysql restart")), String.format("mysql -u root -e 'create user `%s`@`%s` identified by \"%s\";'", getConfig(DB_USER), DB_HOST, getConfig(DB_PASSWORD)), String.format("mysql -u root -e 'grant all privileges on *.* to `%s`@`%s` identified by \"%s\" with grant option; flush privileges;'", getConfig(DB_USER), DB_HOST, getConfig(DB_PASSWORD))) .summary("Initialise MySQL requirements on " + ambariAgent.getId()) .machine(EffectorTasks.getSshMachine(ambariAgent)) .newTask() .asTask(); } }
@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(); } }
.machine(sourceMachine) .summary("copy database dump to slave") .newTask();
.environmentVariable("BASE_DIR", base) .requiringExitCodeZero() .summary("initializing on-box base dir "+base).newTask(); DynamicTasks.queueIfPossible(baseTask).orSubmitAsync(entity); resolvedBase = Strings.getFragmentBetween(baseTask.block().getStdout(), "BASE_DIR_RESULT:", ":BASE_DIR_RESULT");
.environmentVariables(serializer.serialize(env)); Task<String> taskI = DynamicTasks.submit(task.newTask(), target); if (highlight) { highlightAction("Run at "+machine.get().getAddress().getHostAddress(), taskI);
tb.add(SshEffectorTasks.ssh(installCmd).summary("renaming cookbook dir").requiringExitCodeZero().newTask());
ProcessTaskWrapper<Integer> task = SshEffectorTasks.ssh(format("mkdir -p %s", imageDir)) .machine(getMachine()) .newTask(); DynamicTasks.queueIfPossible(task).executionContext(getEntity()).orSubmitAndBlock(); int result = task.get();
tb.add(SshEffectorTasks.ssh(installCmd).summary("renaming cookbook dir").requiringExitCodeZero().newTask());
@Override public String execCommandTimeout(String command, Duration timeout) { AbstractSoftwareProcessSshDriver driver = (AbstractSoftwareProcessSshDriver) getDriver(); if (driver == null) { throw new NullPointerException("No driver for "+this); } ProcessTaskWrapper<String> task = SshEffectorTasks.ssh(command) .environmentVariables(driver.getShellEnvironment()) .requiringZeroAndReturningStdout() .machine(getMachine()) .summary(command) .newTask(); try { String result = DynamicTasks.queueIfPossible(task) .executionContext(this) .orSubmitAsync() .asTask() .get(timeout); return result; } catch (TimeoutException te) { throw new IllegalStateException("Timed out running command: " + command); } catch (Exception e) { Integer exitCode = task.getExitCode(); LOG.warn("Command failed, return code {}: {}", exitCode == null ? -1 : exitCode, task.getStderr()); throw Exceptions.propagate(e); } }
@Override public String execCommandTimeout(String command, Duration timeout) { ProcessTaskWrapper<String> task = SshEffectorTasks.ssh(command) .environmentVariables(((AbstractSoftwareProcessSshDriver) getDriver()).getShellEnvironment()) .configure(SshTool.PROP_ALLOCATE_PTY, true) // TODO configure globally .requiringZeroAndReturningStdout() .machine(getMachine()) .summary(command) .newTask(); try { String result = DynamicTasks.queueIfPossible(task) .executionContext(this) .orSubmitAsync() .asTask() .get(timeout); return result; } catch (TimeoutException te) { throw new IllegalStateException("Timed out running command: " + command); } catch (Exception e) { Integer exitCode = task.getExitCode(); LOG.warn("Command failed, return code {}: {}", exitCode == null ? -1 : exitCode, task.getStderr()); throw Exceptions.propagate(e); } }
@Override public int execCommandStatusTimeout(String command, Duration timeout) { ProcessTaskWrapper<Object> task = SshEffectorTasks.ssh(command) .environmentVariables(((AbstractSoftwareProcessSshDriver) getDriver()).getShellEnvironment()) .returning(ScriptReturnType.EXIT_CODE) .allowingNonZeroExitCode() .machine(getMachine()) .summary(command) .newTask(); try { Object result = DynamicTasks.queueIfPossible(task) .executionContext(this) .orSubmitAsync() .asTask() .get(timeout); return (Integer) result; } catch (TimeoutException te) { throw new IllegalStateException("Timed out running command: " + command); } catch (Exception e) { Integer exitCode = task.getExitCode(); LOG.warn("Command failed, return code {}: {}", exitCode == null ? -1 : exitCode, task.getStderr()); throw Exceptions.propagate(e); } }
public String callMany(Collection<Entity> targets, ConfigBag params) { TaskBuilder<Object> ptb = Tasks.builder().parallel(true).displayName("effector "+effector.getName()+" ssh to targets"); for (Entity target: targets) { if (Entities.isNoLongerManaged(target)) continue; Lifecycle state = target.getAttribute(Attributes.SERVICE_STATE_ACTUAL); if (state==Lifecycle.STOPPING || state==Lifecycle.STOPPED) continue; Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(target.getLocations()); if (machine.isAbsent()) continue; SshEffectorTaskFactory<String> t = makePartialTaskFactory(params, target); t.summary("effector "+effector.getName()+" at "+target); t.machine( machine.get() ); ptb.add(t.newTask()); } queue(ptb.build()).getUnchecked(); return null; }
protected void checkIsRunningAndStops(Entity mysql, SshMachineLocation lh) { Integer pid = getPid(mysql); Assert.assertNotNull(pid, "PID should be set as an attribute (or getPid() overridden to supply)"); Entities.submit(app, SshEffectorTasks.requirePidRunning(pid).machine(lh).newTask() ).get(); app.stop(); // let the kill -1 take effect Time.sleep(Duration.ONE_SECOND); // and assert it has died log.info("mysql in pid "+pid+" should be dead now"); // (app has stopped, so submit on mgmt context) ProcessTaskWrapper<Integer> t = SshEffectorTasks.codePidRunning(pid).machine(lh).newTask(); mgmt.getExecutionManager().submit(t); Assert.assertNotEquals(t.block().getExitCode(), 0); } }
@Override public String execCalicoCommand(MesosSlave slave, String command) { String etcdUrl = sensors().get(ETCD_CLUSTER_URL); Maybe<SshMachineLocation> machine = Machines.findUniqueMachineLocation(slave.getLocations(), SshMachineLocation.class); TaskWrapper<String> process = SshEffectorTasks.ssh(BashCommands.sudo(command)) .environmentVariable("ETCD_AUTHORITY", etcdUrl) .machine(machine.get()) .configure(SshTool.PROP_ALLOCATE_PTY, true) .requiringZeroAndReturningStdout() .newTask(); String output = DynamicTasks.queue(process).asTask().getUnchecked(); return output; }
@Override public ProcessTaskWrapper<RET> newTask(Entity entity, Effector<RET> effector, ConfigBag parameters) { markDirty(); if (summary==null) summary(effector.getName()+" (ssh)"); machine(EffectorTasks.getSshMachine(entity)); return newTask(); } @Override