public static void safeSleep(Long millis) { if (Thread.interrupted()) { throw new DaemonTaskInterrupted(); } try { Thread.sleep(millis); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } } }
public static void message(String message) { if (Thread.interrupted()) { throw new DaemonTaskInterrupted(); } DaemonTask task = getTask(); if (task != null) { log.info("Message by " + task + ": " + message); task.writeMessage(message); } }
public static void newStage(String name) { if (Thread.interrupted()) { throw new DaemonTaskInterrupted(); } DaemonTask task = getTask(); if (task != null) { log.info("Stage change by " + task + ": " + name); task.newStage(name); } }
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); } }
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); } }
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); } }
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); } }
@Override default <S> S connectToInstance(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar, String instanceId) { try { return getServiceInterfaceFactory().createService(GoogleProviderUtils.openSshTunnel(details, instanceId, runtimeSettings.getServiceSettings(sidecar)).toString(), sidecar); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } }
@Override default <S> S connectToInstance(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar, String instanceId) { try { return getServiceInterfaceFactory().createService(GoogleProviderUtils.openSshTunnel(details, instanceId, runtimeSettings.getServiceSettings(sidecar)).toString(), sidecar); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } }
status = executor.backoffWait(jobId); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e);
status = DaemonTaskHandler.getJobExecutor().backoffWait(jobId); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e);
status = jobExecutor.backoffWait(jobExecutor.startJob(request)); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); status = jobExecutor.backoffWait(jobExecutor.startJob(request)); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e);
status = jobExecutor.backoffWait(jobExecutor.startJob(request)); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); status = jobExecutor.backoffWait(jobExecutor.startJob(request)); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e);
status = executor.backoffWait(jobId); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e);
public void ensureKubectlExists(ConfigProblemSetBuilder p) { JobExecutor jobExecutor = DaemonTaskHandler.getJobExecutor(); JobRequest request = new JobRequest() .setTokenizedCommand(Collections.singletonList("kubectl")) .setTimeoutMillis(TimeUnit.SECONDS.toMillis(10)); JobStatus status; try { status = jobExecutor.backoffWait(jobExecutor.startJob(request)); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } if (status.getResult() != JobStatus.Result.SUCCESS) { p.addProblem(FATAL, String.join(" ", "`kubectl` not installed, or can't be found by Halyard. It is needed for", "opening connections to your Kubernetes cluster to send commands to the Spinnaker deployment running there.")) .setRemediation(String.join(" ", "Visit https://kubernetes.io/docs/tasks/kubectl/install/.", "If you've already installed kubectl via gcloud, it's possible updates to your $PATH aren't visible to Halyard. ", "You might have to restart Halyard for it to pick up the new $PATH.")); } } }
public void ensureKubectlExists(ConfigProblemSetBuilder p) { JobExecutor jobExecutor = DaemonTaskHandler.getJobExecutor(); JobRequest request = new JobRequest() .setTokenizedCommand(Collections.singletonList("kubectl")) .setTimeoutMillis(TimeUnit.SECONDS.toMillis(10)); JobStatus status; try { status = jobExecutor.backoffWait(jobExecutor.startJob(request)); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } if (status.getResult() != JobStatus.Result.SUCCESS) { p.addProblem(FATAL, String.join(" ", "`kubectl` not installed, or can't be found by Halyard. It is needed for", "opening connections to your Kubernetes cluster to send commands to the Spinnaker deployment running there.")) .setRemediation(String.join(" ", "Visit https://kubernetes.io/docs/tasks/kubectl/install/.", "If you've already installed kubectl via gcloud, it's possible updates to your $PATH aren't visible to Halyard. ", "You might have to restart Halyard for it to pick up the new $PATH.")); } } }
status = executor.backoffWait(jobId); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e);
default <S> URI sshTunnelIntoService(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar) { ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar); RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings); Integer enabledVersion = runningServiceDetails.getLatestEnabledVersion(); if (enabledVersion == null) { throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no server groups have been deployed yet"); } List<RunningServiceDetails.Instance> instances = runningServiceDetails.getInstances().get(enabledVersion); if (instances == null || instances.isEmpty()) { throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no instances have been deployed yet"); } try { return GoogleProviderUtils.openSshTunnel(details, instances.get(0).getId(), settings); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } }
public void delete(String namespace, String service) { List<String> command = KubernetesV2Utils.kubectlPrefix(account); if (StringUtils.isNotEmpty(namespace)) { command.add("-n=" + namespace); } command.add("delete"); command.add("deploy,svc,secret"); command.add("-l=cluster=" + service); JobRequest request = new JobRequest().setTokenizedCommand(command); String jobId = executor.startJob(request); JobStatus status; try { status = executor.backoffWait(jobId); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } if (status.getState() != JobStatus.State.COMPLETED) { throw new HalException(Problem.Severity.FATAL, String.join("\n", "Deleting service " + service + " never completed", status.getStdErr(), status.getStdOut())); } if (status.getResult() != JobStatus.Result.SUCCESS) { throw new HalException(Problem.Severity.FATAL, String.join("\n", "Deleting service " + service + " failed", status.getStdErr(), status.getStdOut())); } }
default <S> URI sshTunnelIntoService(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar) { ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar); RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings); Integer enabledVersion = runningServiceDetails.getLatestEnabledVersion(); if (enabledVersion == null) { throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no server groups have been deployed yet"); } List<RunningServiceDetails.Instance> instances = runningServiceDetails.getInstances().get(enabledVersion); if (instances == null || instances.isEmpty()) { throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no instances have been deployed yet"); } try { return GoogleProviderUtils.openSshTunnel(details, instances.get(0).getId(), settings); } catch (InterruptedException e) { throw new DaemonTaskInterrupted(e); } }