Search in sources :

Example 1 with PipeliteException

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

the class KubernetesExecutor method submit.

@Override
protected SubmitResult submit(StageExecutorRequest request) {
    KubernetesExecutorParameters executorParams = getExecutorParams();
    context = executorParams.getContext();
    namespace = executorParams.getNamespace() != null ? executorParams.getNamespace() : "default";
    String jobId = createJobId();
    logContext(log.atFine(), request).log("Submitting Kubernetes job " + jobId);
    // Map<String, String> labelMap = new HashMap<>();
    // labelMap.put(..., ...);
    Map<String, Quantity> requestsMap = new HashMap<>();
    requestsMap.put("cpu", executorParams.getMemory());
    requestsMap.put("memory", executorParams.getCpu());
    Map<String, Quantity> limitsMap = new HashMap<>();
    limitsMap.put("cpu", executorParams.getMemoryLimit());
    limitsMap.put("memory", executorParams.getCpuLimit());
    try (KubernetesClient client = kubernetesClient(context)) {
        Job job = new JobBuilder().withApiVersion("batch/v1").withNewMetadata().withName(jobId).endMetadata().withNewSpec().withBackoffLimit(1).withTtlSecondsAfterFinished(KUBERNETES_TTL_SECONDS_AFTER_FINISHED).withNewTemplate().withNewSpec().addNewContainer().withName(jobId).withImage(image).withArgs(imageArgs).withNewResources().withRequests(requestsMap).withLimits(limitsMap).endResources().endContainer().withRestartPolicy("Never").endSpec().endTemplate().endSpec().build();
        RetryTask.DEFAULT.execute(r -> client.batch().v1().jobs().inNamespace(namespace).create(job));
        logContext(log.atInfo(), request).log("Submitted Kubernetes job " + jobId);
    } catch (KubernetesClientException e) {
        throw new PipeliteException("Kubernetes error", e);
    }
    return new SubmitResult(jobId, StageExecutorResult.submitted());
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Quantity(io.fabric8.kubernetes.api.model.Quantity) PipeliteException(pipelite.exception.PipeliteException) KubernetesExecutorParameters(pipelite.stage.parameters.KubernetesExecutorParameters) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 2 with PipeliteException

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

the class KubernetesExecutor method poll.

@Override
protected StageExecutorResult poll(StageExecutorRequest request) {
    String jobId = getJobId();
    logContext(log.atFine(), request).log("Polling Kubernetes job result " + jobId);
    StageExecutorResult result = describeJobs().getResult(jobId, getExecutorParams().getPermanentErrors());
    if (result.isActive()) {
        return StageExecutorResult.active();
    }
    try (KubernetesClient client = kubernetesClient(context)) {
        if (isSaveLogFile(result)) {
            List<Pod> pods = client.pods().inNamespace(namespace).withLabel("job-name", jobId).list().getItems();
            Pod pod = lastPodToStart(pods);
            String log = client.pods().inNamespace(namespace).withName(pod.getMetadata().getName()).tailingLines(getExecutorParams().getLogLines()).getLog();
            result.setStageLog(log);
        }
        terminateJob(client);
    } catch (KubernetesClientException e) {
        throw new PipeliteException("Kubernetes error", e);
    }
    return result;
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) PipeliteException(pipelite.exception.PipeliteException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 3 with PipeliteException

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

the class SshCmdRunner method execute.

@Override
public StageExecutorResult execute(String cmd) {
    if (cmd == null || cmd.trim().isEmpty()) {
        throw new PipeliteException("No command to execute");
    }
    log.atInfo().log("Executing ssh call: %s", cmd);
    try (ClientSession session = createSession(executorParams)) {
        authSession(session);
        ClientChannel channel = session.createExecChannel(cmd, null, executorParams.getEnv());
        OutputStream stdoutStream = new ByteArrayOutputStream();
        OutputStream stderrStream = new ByteArrayOutputStream();
        channel.setOut(stdoutStream);
        channel.setErr(stderrStream);
        channel.open().verify(SSH_VERIFY_TIMEOUT, TimeUnit.SECONDS);
        Set<ClientChannelEvent> events = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), executorParams.getTimeout());
        if (events.contains(ClientChannelEvent.TIMEOUT)) {
            throw new PipeliteException("Failed to execute ssh call because of timeout: " + cmd);
        }
        int exitCode = channel.getExitStatus();
        log.atInfo().log("Finished executing ssh call: %s", cmd);
        return CmdRunner.result(cmd, exitCode, getStream(stdoutStream), getStream(stderrStream));
    } catch (PipeliteException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new PipeliteException("Failed to execute ssh call: " + cmd, ex);
    }
}
Also used : ClientChannelEvent(org.apache.sshd.client.channel.ClientChannelEvent) ClientSession(org.apache.sshd.client.session.ClientSession) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PipeliteException(pipelite.exception.PipeliteException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) PipeliteException(pipelite.exception.PipeliteException) ClientChannel(org.apache.sshd.client.channel.ClientChannel)

Example 4 with PipeliteException

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

the class AbstractAsyncExecutor method submit.

private void submit(StageExecutorRequest request, StageExecutorResultCallback resultCallback) {
    submitExecutorService.submit(() -> {
        try {
            ZonedDateTime submitStartTime = ZonedDateTime.now();
            prepareSubmit(request);
            SubmitResult submitResult = submit(request);
            jobId = submitResult.getJobId();
            StageExecutorResult result = submitResult.getResult();
            if (stageMetrics != null) {
                stageMetrics.getAsyncSubmitTimer().record(Duration.between(submitStartTime, ZonedDateTime.now()));
                stageMetrics.endAsyncSubmit();
            }
            if (!result.isError()) {
                if (!result.isSubmitted()) {
                    result = StageExecutorResult.internalError(new PipeliteException("Unexpected state after asynchronous submit: " + result.getExecutorState().name()));
                } else if (jobId == null) {
                    result = StageExecutorResult.internalError(new PipeliteException("Missing job id after asynchronous submit"));
                }
            }
            resultCallback.accept(result);
        } catch (Exception ex) {
            StageExecutorResult result = StageExecutorResult.internalError(ex);
            resultCallback.accept(result);
        } finally {
            submitLock.unlock();
        }
    });
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) ZonedDateTime(java.time.ZonedDateTime) PipeliteException(pipelite.exception.PipeliteException) PipeliteException(pipelite.exception.PipeliteException)

Example 5 with PipeliteException

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

the class RegisteredScheduleService method createSchedule.

private void createSchedule(Schedule schedule) {
    log.atInfo().log("Creating pipeline schedule: " + schedule.pipelineName());
    try {
        String cron = schedule.configurePipeline().cron();
        scheduleService.createSchedule(serviceName, schedule.pipelineName(), cron);
    } catch (Exception ex) {
        throw new PipeliteException("Failed to create pipeline schedule: " + schedule.pipelineName(), ex);
    }
}
Also used : 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