/** convenience for generating an {@link PlainSshExecTaskFactory} which can be further customised if desired, and then (it must be explicitly) queued */ public ProcessTaskFactory<Integer> ssh(String ...commands) { return SshTasks.newSshExecTaskFactory(machine(), commands); } }
protected WindowsPerformanceCounterFeed(Builder builder) { super(checkNotNull(builder.entity, "builder.entity")); entity = builder.entity; period = builder.period; periodUnits = builder.periodUnits; attributeSensors = builder.sensors; SshMachineLocation machine = EffectorTasks.getSshMachine(getEntity()); Iterable<String> allParams = ImmutableList.<String>builder() .add("typeperf") .addAll(Iterables.transform(attributeSensors.keySet(), QuoteStringFunction.INSTANCE)) .add("-sc") .add("1") .build(); String command = JOINER_ON_SPACE.join(allParams); log.debug("Windows performance counter poll command will be: {}", command); taskFactory = SshTasks.newSshExecTaskFactory(machine, command) .allowingNonZeroExitCode() .runAsCommand(); }
/** creates a task which returns modifies sudoers to ensure non-tty access is permitted; * also gives nice warnings if sudo is not permitted */ public static ProcessTaskFactory<Boolean> dontRequireTtyForSudo(SshMachineLocation machine, final boolean requireSuccess) { return newSshExecTaskFactory(machine, BashCommands.dontRequireTtyForSudo()) .summary("setting up sudo") .configure(SshTool.PROP_ALLOCATE_PTY, true) .allowingNonZeroExitCode() .returning(new Function<ProcessTaskWrapper<?>,Boolean>() { public Boolean apply(ProcessTaskWrapper<?> task) { if (task.getExitCode()==0) return true; Entity entity = BrooklynTasks.getTargetOrContextEntity(Tasks.current()); log.warn("Error setting up sudo for "+task.getMachine().getUser()+"@"+task.getMachine().getAddress().getHostName()+" "+ " (exit code "+task.getExitCode()+(entity!=null ? ", entity "+entity : "")+")"); Streams.logStreamTail(log, "STDERR of sudo setup problem", Streams.byteArrayOfString(task.getStderr()), 1024); if (requireSuccess) { throw new IllegalStateException("Passwordless sudo is required for "+task.getMachine().getUser()+"@"+task.getMachine().getAddress().getHostName()+ (entity!=null ? " ("+entity+")" : "")); } return true; } }); }