use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.
the class SshCmdRunnerTest method echo.
@Test
public void echo() {
SshCmdRunner cmdRunner = cmdRunner();
StageExecutorResult result = cmdRunner.execute("echo test");
assertThat(result.isError()).isFalse();
assertThat(result.getAttribute(StageExecutorResultAttribute.EXIT_CODE)).isEqualTo("0");
assertThat(result.getStageLog()).startsWith("test");
}
use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.
the class SshCmdRunnerTest method unknownCommand.
@Test
public void unknownCommand() {
SshCmdRunner cmdRunner = cmdRunner();
StageExecutorResult result = cmdRunner.execute(PipeliteIdCreator.id());
assertThat(result.isError()).isTrue();
assertThat(result.getAttribute(StageExecutorResultAttribute.EXIT_CODE)).isNotEqualTo("0");
}
use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.
the class DescribeJobsTest method error.
@Test
public void error() {
int requestLimit = 10;
int requestCnt = 100;
AtomicInteger actualDescribeJobsCallCnt = new AtomicInteger();
AtomicInteger actualRequestCnt = new AtomicInteger();
DescribeJobsCallback<Integer, String> describeJobsCallback = (requestList, context) -> {
actualDescribeJobsCallCnt.incrementAndGet();
actualRequestCnt.addAndGet(requestList.size());
return requestList.stream().collect(Collectors.toMap(i -> i, i -> StageExecutorResult.error()));
};
String executorContext = "test";
final DescribeJobs<Integer, String> describeJobs = new DescribeJobs(mock(ServiceConfiguration.class), mock(InternalErrorService.class), requestLimit, executorContext, describeJobsCallback);
IntStream.range(0, requestCnt).forEach(i -> describeJobs.addRequest(i));
assertThat(describeJobs.getActiveRequests().size()).isEqualTo(requestCnt);
describeJobs.makeRequests();
assertThat(actualDescribeJobsCallCnt.get()).isEqualTo(requestCnt / requestLimit);
assertThat(actualRequestCnt.get()).isEqualTo(requestCnt);
// Check that there are no active requests.
assertThat(describeJobs.getActiveRequests().size()).isEqualTo(0);
// Check that the results are correct.
IntStream.range(0, requestCnt).forEach(i -> {
StageExecutorResult result = describeJobs.getResult(i, null);
assertThat(result.isError()).isTrue();
});
// Check that the requests have been removed.
IntStream.range(0, requestCnt).forEach(i -> assertThat(describeJobs.isRequest(i)).isFalse());
}
use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.
the class KubernetesExecutor method describeJobs.
public static Map<String, StageExecutorResult> describeJobs(List<String> requests, KubernetesDescribeJobsCache.ExecutorContext executorContext) {
log.atFine().log("Describing Kubernetes job results");
Map<String, StageExecutorResult> results = new HashMap<>();
Set<String> jobIds = new HashSet();
String namespace = executorContext.getNamespace();
try {
KubernetesClient client = executorContext.getKubernetesClient();
JobList jobList = RetryTask.DEFAULT.execute(r -> client.batch().v1().jobs().inNamespace(namespace).list());
for (Job job : jobList.getItems()) {
String jobId = job.getMetadata().getName();
jobIds.add(jobId);
results.put(jobId, describeJobsResult(namespace, jobId, client, job.getStatus()));
}
for (String jobId : requests) {
if (!jobIds.contains(jobId)) {
// Consider jobs that can't be found as failed.
results.put(jobId, StageExecutorResult.error());
}
}
} catch (KubernetesClientException e) {
throw new PipeliteException("Kubernetes error", e);
}
return results;
}
use of pipelite.stage.executor.StageExecutorResult 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;
}
Aggregations