Search in sources :

Example 16 with JobStatus

use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.

the class GoogleProviderUtils method openSshTunnel.

static URI openSshTunnel(AccountDeploymentDetails<GoogleAccount> details, String instanceName, ServiceSettings service) throws InterruptedException {
    int port = service.getPort();
    String key = Proxy.buildKey(details.getDeploymentName(), instanceName, port);
    Proxy proxy = proxyMap.getOrDefault(key, new Proxy());
    JobExecutor jobExecutor = DaemonTaskHandler.getJobExecutor();
    if (proxy.getJobId() == null || !jobExecutor.jobExists(proxy.getJobId())) {
        String ip = getInstanceIp(details, instanceName);
        String keyFile = getSshKeyFile();
        log.info("Opening port " + port + " against instance " + instanceName);
        boolean connected = false;
        int tries = 0;
        while (!connected && tries < openSshRetries) {
            tries++;
            proxy = openSshTunnel(ip, port, keyFile);
            connected = checkIfProxyIsOpen(proxy);
            if (!connected) {
                if (!jobExecutor.jobExists(proxy.jobId) || jobExecutor.updateJob(proxy.jobId).getState() == JobStatus.State.COMPLETED) {
                    log.warn("SSH tunnel closed prematurely");
                }
                log.info("SSH tunnel never opened, retrying in case the instance hasn't started yet... (" + tries + "/" + openSshRetries + ")");
                closeSshTunnel(proxy);
                DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10));
            }
        }
        if (!connected) {
            JobStatus status = jobExecutor.updateJob(proxy.getJobId());
            throw new HalException(FATAL, "Unable to connect to instance " + instanceName + ": " + status.getStdErr());
        }
        proxyMap.put(key, proxy);
    }
    try {
        return new URIBuilder().setScheme("http").setHost("localhost").setPort(proxy.getPort()).build();
    } catch (URISyntaxException e) {
        throw new RuntimeException("Failed to build URI for SSH connection", e);
    }
}
Also used : JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) JobExecutor(com.netflix.spinnaker.halyard.core.job.v1.JobExecutor) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 17 with JobStatus

use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.

the class KubernetesV2Executor method delete.

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()));
    }
}
Also used : JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted)

Example 18 with JobStatus

use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.

the class KubernetesV2Executor method deleteSpinnaker.

public void deleteSpinnaker(String namespace) {
    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=app=spin");
    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 spinnaker never completed in " + namespace, status.getStdErr(), status.getStdOut()));
    }
    if (status.getResult() != JobStatus.Result.SUCCESS) {
        throw new HalException(Problem.Severity.FATAL, String.join("\n", "Deleting spinnaker failed in " + namespace, status.getStdErr(), status.getStdOut()));
    }
}
Also used : JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted)

Example 19 with JobStatus

use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.

the class KubernetesV2Executor method isReady.

public boolean isReady(String namespace, String service) {
    log.info("Checking readiness for " + service);
    List<String> command = kubernetesV2Utils.kubectlPrefix(account);
    if (StringUtils.isNotEmpty(namespace)) {
        command.add("-n=" + namespace);
    }
    command.add("get");
    command.add("po");
    command.add("-l=cluster=" + service);
    command.add("-o=jsonpath='{.items[*].status.containerStatuses[*].ready}'");
    // This command returns a space-separated string of true/false values indicating whether each of
    // the pod's containers are READY.
    // e.g., if we are querying two spin-orca pods and both pods' monitoring-daemon containers are
    // READY but the orca containers are not READY, the output may be 'true false true false'.
    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", "Unterminated readiness check for " + service + " in " + namespace, status.getStdErr(), status.getStdOut()));
    }
    if (status.getResult() == JobStatus.Result.SUCCESS) {
        String readyStatuses = status.getStdOut();
        if (readyStatuses.isEmpty()) {
            return false;
        }
        readyStatuses = readyStatuses.substring(1, // Strip leading and trailing single quote
        readyStatuses.length() - 1);
        if (readyStatuses.isEmpty()) {
            return false;
        }
        return Arrays.stream(readyStatuses.split(" ")).allMatch(s -> s.equals("true"));
    } else {
        throw new HalException(Problem.Severity.FATAL, String.join("\n", "Failed readiness check for " + service + " in " + namespace, status.getStdErr(), status.getStdOut()));
    }
}
Also used : JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted)

Example 20 with JobStatus

use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.

the class KubernetesV2Executor method replace.

public void replace(String manifest) {
    manifest = kubernetesV2Utils.prettify(manifest);
    List<String> command = kubernetesV2Utils.kubectlPrefix(account);
    command.add("replace");
    command.add("--force");
    command.add("-f");
    // read from stdin
    command.add("-");
    JobRequest request = new JobRequest().setTokenizedCommand(command);
    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    String jobId = executor.startJob(request, System.getenv(), new ByteArrayInputStream(manifest.getBytes()), stdout, stderr);
    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", "Unterminated deployment of manifest:", manifest, stderr.toString(), stdout.toString()));
    }
    if (status.getResult() != JobStatus.Result.SUCCESS) {
        throw new HalException(Problem.Severity.FATAL, String.join("\n", "Failed to deploy manifest:", manifest, stderr.toString(), stdout.toString()));
    }
}
Also used : JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted)

Aggregations

JobStatus (com.netflix.spinnaker.halyard.core.job.v1.JobStatus)18 JobRequest (com.netflix.spinnaker.halyard.core.job.v1.JobRequest)17 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)16 DaemonTaskInterrupted (com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted)11 JobStatus (io.fabric8.kubernetes.api.model.batch.v1.JobStatus)6 JobExecutor (com.netflix.spinnaker.halyard.core.job.v1.JobExecutor)5 ArrayList (java.util.ArrayList)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)2 JobCondition (io.fabric8.kubernetes.api.model.batch.v1.JobCondition)2 File (java.io.File)2 IOException (java.io.IOException)2 AnsiParagraphBuilder (com.netflix.spinnaker.halyard.cli.ui.v1.AnsiParagraphBuilder)1 AnsiStoryBuilder (com.netflix.spinnaker.halyard.cli.ui.v1.AnsiStoryBuilder)1 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)1 RemoteAction (com.netflix.spinnaker.halyard.core.RemoteAction)1 HasServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings)1