use of com.netflix.spinnaker.halyard.core.job.v1.JobExecutor in project halyard by spinnaker.
the class AbstractRemoteActionCommand method runRemoteAction.
protected void runRemoteAction(OperationHandler<RemoteAction> operation) {
RemoteAction action = operation.get();
String scriptPath = action.getScriptPath();
if (StringUtils.isEmpty(scriptPath)) {
return;
}
boolean shouldRun;
if (autoRun == null) {
shouldRun = action.isAutoRun();
} else {
shouldRun = action.isAutoRun() && autoRun;
}
if (!shouldRun) {
AnsiStoryBuilder storyBuilder = new AnsiStoryBuilder();
AnsiParagraphBuilder paragraphBuilder = storyBuilder.addParagraph();
paragraphBuilder.addSnippet(action.getScriptDescription());
storyBuilder.addNewline();
paragraphBuilder = storyBuilder.addParagraph();
paragraphBuilder.addSnippet("Please run the following script:");
storyBuilder.addNewline();
paragraphBuilder = storyBuilder.addParagraph();
paragraphBuilder.addSnippet(action.getScriptPath()).addStyle(AnsiStyle.UNDERLINE);
AnsiUi.raw(storyBuilder.toString());
} else {
List<String> command = new ArrayList<>();
command.add(scriptPath);
JobRequest request = new JobRequest().setTokenizedCommand(command);
JobExecutor executor = getJobExecutor();
String jobId = executor.startJobFromStandardStreams(request);
JobStatus status = null;
try {
status = executor.backoffWait(jobId);
} catch (InterruptedException e) {
AnsiUi.failure("Interrupted.");
System.exit(1);
}
if (status.getResult() != JobStatus.Result.SUCCESS) {
AnsiUi.error("Error encountered running script. See above output for more details.");
System.exit(1);
}
}
}
use of com.netflix.spinnaker.halyard.core.job.v1.JobExecutor in project halyard by spinnaker.
the class KubernetesV1ProviderUtils method storeInstanceLogs.
static void storeInstanceLogs(JobExecutor jobExecutor, AccountDeploymentDetails<KubernetesAccount> details, String namespace, String instanceName, String containerName, File outputFile) {
List<String> command = kubectlAccountCommand(details);
command.add("--namespace");
command.add(namespace);
command.add("logs");
command.add(instanceName);
command.add(containerName);
JobRequest request = new JobRequest().setTokenizedCommand(command);
JobStatus status;
try {
status = jobExecutor.backoffWait(jobExecutor.startJob(request));
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
try {
IOUtils.write(status.getStdOut().getBytes(), new FileOutputStream(new File(outputFile, containerName)));
} catch (IOException e) {
throw new HalException(Severity.FATAL, "Unable to store logs: " + e.getMessage(), e);
}
}
use of com.netflix.spinnaker.halyard.core.job.v1.JobExecutor in project halyard by spinnaker.
the class KubernetesV1ProviderUtils method kubectlDeleteNamespaceCommand.
static void kubectlDeleteNamespaceCommand(JobExecutor jobExecutor, AccountDeploymentDetails<KubernetesAccount> details, String namespace) {
List<String> command = kubectlAccountCommand(details);
command.add("delete");
command.add("namespace");
command.add(namespace);
JobRequest request = new JobRequest().setTokenizedCommand(command);
try {
jobExecutor.backoffWait(jobExecutor.startJob(request));
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
}
use of com.netflix.spinnaker.halyard.core.job.v1.JobExecutor in project halyard by spinnaker.
the class GoogleProviderUtils method closeSshTunnel.
private static void closeSshTunnel(Proxy proxy) {
JobExecutor jobExecutor = DaemonTaskHandler.getJobExecutor();
jobExecutor.cancelJob(proxy.getJobId());
}
use of com.netflix.spinnaker.halyard.core.job.v1.JobExecutor in project halyard by spinnaker.
the class GoogleProviderUtils method openSshTunnel.
private static Proxy openSshTunnel(String ip, int port, String keyFile) throws InterruptedException {
JobExecutor jobExecutor = DaemonTaskHandler.getJobExecutor();
List<String> command = new ArrayList<>();
// Make sure we don't have an entry for this host already (GCP recycles IPs).
command.add("ssh-keygen");
command.add("-R");
command.add(ip);
JobRequest request = new JobRequest().setTokenizedCommand(command);
JobStatus status = jobExecutor.backoffWait(jobExecutor.startJob(request));
if (status.getResult() != JobStatus.Result.SUCCESS) {
if (status.getStdErr().contains("No such file")) {
log.info("No ssh known_hosts file exists yet");
} else {
throw new HalException(FATAL, "Unable to remove old host entry " + status.getStdErr());
}
}
int localPort = SocketUtils.findAvailableTcpPort();
command.clear();
command.add("ssh");
command.add("ubuntu@" + ip);
command.add("-o");
command.add("StrictHostKeyChecking=no");
command.add("-i");
command.add(keyFile);
command.add("-N");
command.add("-L");
command.add(String.format("%d:localhost:%d", localPort, port));
request = new JobRequest().setTokenizedCommand(command);
String jobId = jobExecutor.startJob(request);
status = jobExecutor.updateJob(jobId);
while (status == null) {
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(1));
status = jobExecutor.updateJob(jobId);
}
return new Proxy().setJobId(jobId).setPort(localPort);
}
Aggregations