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());
}
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;
}
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);
}
}
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();
}
});
}
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);
}
}
Aggregations