Search in sources :

Example 6 with JobStatus

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

the class KubernetesV2Utils method exists.

private static boolean exists(KubernetesAccount account, String namespace, String kind, String name) {
    log.info("Checking for " + kind + "/" + name);
    List<String> command = kubectlPrefix(account);
    if (StringUtils.isNotEmpty(namespace)) {
        command.add("-n");
        command.add(namespace);
    }
    command.add("get");
    command.add(kind);
    command.add(name);
    JobRequest request = new JobRequest().setTokenizedCommand(command);
    String jobId = DaemonTaskHandler.getJobExecutor().startJob(request);
    JobStatus status;
    try {
        status = DaemonTaskHandler.getJobExecutor().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 check for " + kind + "/" + name + " in " + namespace, status.getStdErr(), status.getStdOut()));
    }
    if (status.getResult() == JobStatus.Result.SUCCESS) {
        return true;
    } else if (status.getStdErr().contains("NotFound")) {
        return false;
    } else {
        throw new HalException(Problem.Severity.FATAL, String.join("\n", "Failed check for " + kind + "/" + name + " 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 7 with JobStatus

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

the class KubernetesV1RedisService method connectToPrimaryService.

@Override
public Jedis connectToPrimaryService(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
    ServiceSettings settings = runtimeSettings.getServiceSettings(this);
    List<String> command = Arrays.stream(connectCommand(details, runtimeSettings).split(" ")).collect(Collectors.toList());
    JobRequest request = new JobRequest().setTokenizedCommand(command);
    String jobId = getJobExecutor().startJob(request);
    // Wait for the proxy to spin up.
    DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
    JobStatus status = getJobExecutor().updateJob(jobId);
    // This should be a long-running job.
    if (status.getState() == JobStatus.State.COMPLETED) {
        throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against Redis:\n" + status.getStdOut() + "\n" + status.getStdErr());
    }
    return new Jedis("localhost", settings.getPort());
}
Also used : JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) Jedis(redis.clients.jedis.Jedis) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) KubernetesSharedServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)

Example 8 with JobStatus

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

the class JobUtils method waitForJobRunning.

/**
 * Wait for specific Job Running active status
 * @param jobName job name
 * @param namespace namespace
 */
public static boolean waitForJobRunning(String jobName, String namespace) {
    LOGGER.info("Waiting for job: {} will be in active state", jobName);
    TestUtils.waitFor("job active", Constants.GLOBAL_POLL_INTERVAL, ResourceOperation.getTimeoutForResourceReadiness(Constants.JOB), () -> {
        JobStatus jb = kubeClient().namespace(namespace).getJobStatus(jobName);
        return jb.getActive() > 0;
    });
    return true;
}
Also used : JobStatus(io.fabric8.kubernetes.api.model.batch.v1.JobStatus)

Example 9 with JobStatus

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

the class KubernetesAccountValidator method ensureKubectlExists.

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

Example 10 with JobStatus

use of com.google.cloud.dataproc.v1beta2.JobStatus 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);
        }
    }
}
Also used : AnsiParagraphBuilder(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiParagraphBuilder) JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) JobExecutor(com.netflix.spinnaker.halyard.core.job.v1.JobExecutor) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) ArrayList(java.util.ArrayList) AnsiStoryBuilder(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiStoryBuilder)

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