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