Search in sources :

Example 16 with PipeliteException

use of pipelite.exception.PipeliteException in project pipelite by enasequence.

the class KubernetesExecutor method describeJobsResult.

static StageExecutorResult describeJobsResult(String namespace, String jobId, KubernetesClient client, JobStatus jobStatus) {
    // Only one pod per job.
    StageExecutorResult result = describeJobsResultFromStatus(jobStatus);
    if (result.isActive()) {
        return result;
    }
    // Get exit code.
    Integer exitCode;
    try {
        List<Pod> pods = client.pods().inNamespace(namespace).withLabel("job-name", jobId).list().getItems();
        Pod pod = lastPodToStart(pods);
        if (pod == null || pod.getStatus() == null) {
            throw new PipeliteException("Could not get pod status for completed Kubernetes job: " + jobId);
        }
        List<ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses();
        ContainerStatus containerStatus = lastContainerToFinish(containerStatuses);
        if (containerStatus == null || containerStatus.getState() == null || containerStatus.getState().getTerminated() == null || containerStatus.getState().getTerminated().getExitCode() == null) {
            throw new PipeliteException("Could not get container status for completed Kubernetes job: " + jobId);
        }
        exitCode = containerStatus.getState().getTerminated().getExitCode();
    } catch (KubernetesClientException e) {
        throw new PipeliteException("Kubernetes error", e);
    }
    result.addAttribute(StageExecutorResultAttribute.EXIT_CODE, exitCode != null ? String.valueOf(exitCode) : "");
    result.addAttribute(StageExecutorResultAttribute.JOB_ID, jobId);
    return result;
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) Pod(io.fabric8.kubernetes.api.model.Pod) PipeliteException(pipelite.exception.PipeliteException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 17 with PipeliteException

use of pipelite.exception.PipeliteException in project pipelite by enasequence.

the class KubernetesExecutor method terminate.

@Override
public void terminate() {
    String jobId = getJobId();
    if (jobId == null) {
        return;
    }
    try (KubernetesClient client = kubernetesClient(context)) {
        terminateJob(client);
        describeJobs().removeRequest(jobId);
    } catch (KubernetesClientException e) {
        throw new PipeliteException("Kubernetes error", e);
    }
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PipeliteException(pipelite.exception.PipeliteException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 18 with PipeliteException

use of pipelite.exception.PipeliteException in project pipelite by enasequence.

the class LsfExecutor method prepareSubmit.

@Override
protected void prepareSubmit(StageExecutorRequest request) {
    LsfDefinitionFilePathResolver resolver = new LsfDefinitionFilePathResolver(request, getExecutorParams());
    LsfFilePathResolver.Format format = LsfFilePathResolver.Format.WITHOUT_LSF_PATTERN;
    if (!getCmdRunner().createDir(Paths.get(resolver.getDir(format)))) {
        throw new PipeliteException("Failed to create LSF definition dir");
    }
    definitionFile = resolver.getFile(format);
    URL definitionUrl = ExecutorParametersValidator.validateUrl(getExecutorParams().getDefinition(), "definition");
    final String definition = applyDefinitionParameters(CmdRunnerUtils.read(definitionUrl), getExecutorParams().getParameters());
    RetryTask.DEFAULT.execute(r -> {
        getCmdRunner().writeFile(definition, Paths.get(definitionFile));
        return null;
    });
}
Also used : LsfDefinitionFilePathResolver(pipelite.stage.path.LsfDefinitionFilePathResolver) LsfFilePathResolver(pipelite.stage.path.LsfFilePathResolver) PipeliteException(pipelite.exception.PipeliteException) URL(java.net.URL)

Example 19 with PipeliteException

use of pipelite.exception.PipeliteException in project pipelite by enasequence.

the class LocalCmdRunner method execute.

@Override
public StageExecutorResult execute(String cmd) {
    if (cmd == null || cmd.isEmpty()) {
        throw new PipeliteException("No command to execute");
    }
    try {
        CommandLine commandLine = new CommandLine("/bin/sh");
        commandLine.addArgument("-c");
        commandLine.addArgument(cmd, false);
        OutputStream stdoutStream = new ByteArrayOutputStream();
        OutputStream stderrStream = new ByteArrayOutputStream();
        Executor apacheExecutor = new DefaultExecutor();
        apacheExecutor.setExitValues(null);
        apacheExecutor.setStreamHandler(new PumpStreamHandler(stdoutStream, stderrStream));
        // executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
        Duration timeout = executorParams.getTimeout();
        if (timeout != null) {
            apacheExecutor.setWatchdog(new ExecuteWatchdog(executorParams.getTimeout() != null ? executorParams.getTimeout().toMillis() : ExecuteWatchdog.INFINITE_TIMEOUT));
        }
        log.atInfo().log("Executing local call: %s", cmd);
        int exitCode = apacheExecutor.execute(commandLine, executorParams.getEnv());
        return CmdRunner.result(cmd, exitCode, getStream(stdoutStream), getStream(stderrStream));
    } catch (Exception ex) {
        throw new PipeliteException("Failed to execute local call: " + cmd, ex);
    }
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) Duration(java.time.Duration) PipeliteException(pipelite.exception.PipeliteException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) PipeliteException(pipelite.exception.PipeliteException)

Example 20 with PipeliteException

use of pipelite.exception.PipeliteException in project pipelite by enasequence.

the class AbstractAsyncExecutor method poll.

private void poll(StageExecutorRequest request, StageExecutorResultCallback resultCallback) {
    try {
        StageExecutorResult result = poll(request);
        if (result.isSubmitted()) {
            result = StageExecutorResult.internalError(new PipeliteException("Unexpected state during asynchronous poll: " + result.getExecutorState().name()));
        }
        resultCallback.accept(result);
    } catch (Exception ex) {
        StageExecutorResult result = StageExecutorResult.internalError(ex);
        resultCallback.accept(result);
    }
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) PipeliteException(pipelite.exception.PipeliteException) PipeliteException(pipelite.exception.PipeliteException)

Aggregations

PipeliteException (pipelite.exception.PipeliteException)23 StageExecutorResult (pipelite.stage.executor.StageExecutorResult)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 Pod (io.fabric8.kubernetes.api.model.Pod)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Duration (java.time.Duration)2 ZonedDateTime (java.time.ZonedDateTime)2 TimeoutException (java.util.concurrent.TimeoutException)2 Pipeline (pipelite.Pipeline)2 Schedule (pipelite.Schedule)2 ProcessEntity (pipelite.entity.ProcessEntity)2 ScheduleEntity (pipelite.entity.ScheduleEntity)2 PipeliteMetrics (pipelite.metrics.PipeliteMetrics)2 ProcessBuilder (pipelite.process.builder.ProcessBuilder)2 PipeliteServices (pipelite.service.PipeliteServices)2 AWSBatch (com.amazonaws.services.batch.AWSBatch)1