Search in sources :

Example 26 with StageExecutorResult

use of pipelite.stage.executor.StageExecutorResult 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)

Example 27 with StageExecutorResult

use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.

the class AbstractLsfExecutor method submit.

@Override
protected SubmitResult submit(StageExecutorRequest request) {
    outFile = getExecutorParams().resolveLogFile(request, LsfFilePathResolver.Format.WITHOUT_LSF_PATTERN);
    StageExecutorResult result = RetryTask.DEFAULT.execute(r -> getCmdRunner().execute(getSubmitCmd(request)));
    String jobId = null;
    if (!result.isError()) {
        jobId = extractSubmittedJobIdFromBsubOutput(result.getStageLog());
        logContext(log.atInfo(), request).log("Submitted LSF job " + jobId);
        result.setSubmitted();
    }
    return new SubmitResult(jobId, result);
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult)

Example 28 with StageExecutorResult

use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.

the class AbstractLsfExecutor method extractResultFromBjobsOutput.

/**
 * Extracts job result from a single line of bjobs output.
 */
public static JobResult extractResultFromBjobsOutput(String str) {
    String[] column = str.split("\\|");
    if (column.length != 7) {
        log.atWarning().log("Unexpected bjobs output line: " + str);
        return null;
    }
    StageExecutorResult result;
    if (column[BJOBS_COLUMN_STATUS].equals(BJOBS_STATUS_DONE)) {
        result = StageExecutorResult.success();
        result.addAttribute(StageExecutorResultAttribute.EXIT_CODE, String.valueOf(0));
    } else if (column[BJOBS_COLUMN_STATUS].equals(BJOBS_STATUS_EXIT)) {
        result = StageExecutorResult.error();
        result.addAttribute(StageExecutorResultAttribute.EXIT_CODE, String.valueOf(column[BJOBS_COLUMN_EXIT_CODE]));
    } else {
        result = StageExecutorResult.active();
    }
    String jobId = column[BJOBS_COLUMN_JOB_ID];
    result.addAttribute(StageExecutorResultAttribute.JOB_ID, jobId);
    if (result.isSuccess() || result.isError()) {
        result.addAttribute(StageExecutorResultAttribute.EXEC_HOST, column[BJOBS_COLUMN_HOST]);
        result.addAttribute(StageExecutorResultAttribute.CPU_TIME, column[BJOBS_COLUMN_CPU_TIME]);
        result.addAttribute(StageExecutorResultAttribute.MAX_MEM, column[BJOBS_COLUMN_MAX_MEM]);
        result.addAttribute(StageExecutorResultAttribute.AVG_MEM, column[BJOBS_COLUMN_AVG_MEM]);
    }
    JobResult jobResult = new JobResult();
    jobResult.jobId = jobId;
    jobResult.result = result;
    return jobResult;
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult)

Example 29 with StageExecutorResult

use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.

the class AbstractLsfExecutor method bjobs.

private static String bjobs(CmdRunner cmdRunner, List<String> jobIds) {
    String str = String.join(" ", jobIds);
    log.atFine().log("Checking LSF job results using bjobs: " + str);
    // Ignore exit code as bjobs returns 255 if some of the jobs are not found.
    StageExecutorResult result = cmdRunner.execute(BJOBS_CMD + str);
    return result.getStageLog();
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult)

Example 30 with StageExecutorResult

use of pipelite.stage.executor.StageExecutorResult in project pipelite by enasequence.

the class AbstractLsfExecutor method extractResultFromBhistOutputOrOutFile.

/**
 * Extracts stage execution result from bhist output or out file. Returns null if the result could
 * not be extracted.
 */
public static StageExecutorResult extractResultFromBhistOutputOrOutFile(String str) {
    if (str == null) {
        return null;
    }
    if (// bhist -f result
    str.contains("Done successfully") || // output file result
    str.contains("Successfully completed")) {
        StageExecutorResult result = StageExecutorResult.success();
        result.addAttribute(StageExecutorResultAttribute.EXIT_CODE, "0");
        return result;
    }
    Integer exitCode = extractExitCodeFromBhistOutputOrOutFile(str);
    if (exitCode != null) {
        StageExecutorResult result = StageExecutorResult.error();
        result.addAttribute(StageExecutorResultAttribute.EXIT_CODE, String.valueOf(exitCode));
        return result;
    }
    return null;
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

StageExecutorResult (pipelite.stage.executor.StageExecutorResult)33 Test (org.junit.jupiter.api.Test)14 PipeliteException (pipelite.exception.PipeliteException)5 Stage (pipelite.stage.Stage)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3 AssertionsForClassTypes.assertThat (org.assertj.core.api.AssertionsForClassTypes.assertThat)3 Mockito.mock (org.mockito.Mockito.mock)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ServiceConfiguration (pipelite.configuration.ServiceConfiguration)3 InternalErrorService (pipelite.service.InternalErrorService)3 Pod (io.fabric8.kubernetes.api.model.Pod)2 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 ZonedDateTime (java.time.ZonedDateTime)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 StageEntity (pipelite.entity.StageEntity)2 ContainerStatus (io.fabric8.kubernetes.api.model.ContainerStatus)1