Search in sources :

Example 31 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class ProcessRunner method evaluateProcessState.

/**
 * Evaluates the process state using the stage execution result types.
 *
 * @param process the process
 * @return the process state
 */
public static ProcessState evaluateProcessState(Process process) {
    int errorCount = 0;
    for (Stage stage : process.getStages()) {
        StageEntity stageEntity = stage.getStageEntity();
        StageState stageState = stageEntity.getStageState();
        if (stageState == SUCCESS) {
            continue;
        }
        if (DependencyResolver.isEventuallyExecutableStage(process, stage)) {
            return ProcessState.ACTIVE;
        } else {
            errorCount++;
        }
    }
    if (errorCount > 0) {
        return ProcessState.FAILED;
    }
    return ProcessState.COMPLETED;
}
Also used : StageState(pipelite.stage.StageState) Stage(pipelite.stage.Stage) StageEntity(pipelite.entity.StageEntity)

Example 32 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class StageRunner method executeStage.

private void executeStage(StageExecutorResultCallback processRunnerResultCallback) {
    StageExecutorResultCallback stageRunnerResultCallback = (executorResult) -> internalErrorHandler.execute(() -> {
        if (executorResult == null) {
            throw new PipeliteException("Missing executor result");
        }
        if (executorResult.isSubmitted()) {
            logContext(log.atFine()).log("Submitted asynchronous stage execution");
            pipeliteServices.stage().saveStage(stage);
        } else if (executorResult.isActive()) {
            if (ZonedDateTime.now().isAfter(timeout)) {
                logContext(log.atSevere()).log("Maximum stage execution time exceeded.");
                // Terminate executor.
                internalErrorHandler.execute(() -> stage.getExecutor().terminate());
                endStageExecution(processRunnerResultCallback, StageExecutorResult.timeoutError());
            } else {
                logContext(log.atFiner()).log("Waiting asynchronous stage execution to complete");
            }
        } else if (executorResult.isSuccess() || executorResult.isError()) {
            endStageExecution(processRunnerResultCallback, executorResult);
        }
    }, (ex) -> endStageExecution(processRunnerResultCallback, StageExecutorResult.internalError(ex)));
    executeStage(processRunnerResultCallback, stageRunnerResultCallback);
}
Also used : ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) PipeliteMetrics(pipelite.metrics.PipeliteMetrics) StageExecutorResult(pipelite.stage.executor.StageExecutorResult) InternalErrorHandler(pipelite.error.InternalErrorHandler) ZonedDateTime(java.time.ZonedDateTime) LogKey(pipelite.log.LogKey) StageExecutor(pipelite.stage.executor.StageExecutor) StageExecutorSerializer(pipelite.stage.executor.StageExecutorSerializer) StageExecutorResultCallback(pipelite.stage.executor.StageExecutorResultCallback) PipeliteException(pipelite.exception.PipeliteException) Process(pipelite.process.Process) AbstractAsyncExecutor(pipelite.executor.AbstractAsyncExecutor) PipeliteServices(pipelite.service.PipeliteServices) Stage(pipelite.stage.Stage) Flogger(lombok.extern.flogger.Flogger) Duration(java.time.Duration) FluentLogger(com.google.common.flogger.FluentLogger) Assert(org.springframework.util.Assert) StageExecutorResultCallback(pipelite.stage.executor.StageExecutorResultCallback) PipeliteException(pipelite.exception.PipeliteException)

Example 33 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class AbstractAsyncExecutorTest method executeSubmitMissingJobId.

@Test
public void executeSubmitMissingJobId() {
    AbstractAsyncExecutor executor = executor();
    doReturn(new AbstractAsyncExecutor.SubmitResult(null, StageExecutorResult.submitted())).when(executor).submit(any());
    Stage stage = new Stage(STAGE_NAME, executor);
    StageExecutorRequest request = new StageExecutorRequest(PIPELINE_NAME, PROCESS_ID, stage);
    AtomicReference<StageExecutorResult> result = new AtomicReference<>();
    executor.execute(request, (r) -> result.set(r));
    while (result.get() == null) {
        Time.wait(Duration.ofSeconds(1));
    }
    assertThat(result.get().isError()).isTrue();
    assertThat(result.get().isErrorType(ErrorType.INTERNAL_ERROR)).isTrue();
    assertThat(result.get().getStageLog()).contains("PipeliteException: Missing job id after asynchronous submit");
}
Also used : Stage(pipelite.stage.Stage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 34 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class AbstractAsyncExecutorTest method executeSubmitUnexpectedState.

@Test
public void executeSubmitUnexpectedState() {
    for (StageExecutorState stageExecutorState : EnumSet.of(StageExecutorState.ACTIVE, StageExecutorState.SUCCESS)) {
        AbstractAsyncExecutor executor = executor();
        doReturn(new AbstractAsyncExecutor.SubmitResult("jobId", StageExecutorResult.from(stageExecutorState))).when(executor).submit(any());
        Stage stage = new Stage(STAGE_NAME, executor);
        StageExecutorRequest request = new StageExecutorRequest(PIPELINE_NAME, PROCESS_ID, stage);
        AtomicReference<StageExecutorResult> result = new AtomicReference<>();
        executor.execute(request, (r) -> result.set(r));
        while (result.get() == null) {
            Time.wait(Duration.ofSeconds(1));
        }
        assertThat(result.get().isError()).isTrue();
        assertThat(result.get().isErrorType(ErrorType.INTERNAL_ERROR)).isTrue();
        assertThat(result.get().getStageLog()).contains("PipeliteException: Unexpected state after asynchronous submit");
    }
}
Also used : Stage(pipelite.stage.Stage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 35 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class AbstractAsyncExecutorTest method executeSubmitError.

@Test
public void executeSubmitError() {
    AbstractAsyncExecutor executor = executor();
    doReturn(new AbstractAsyncExecutor.SubmitResult(null, StageExecutorResult.error())).when(executor).submit(any());
    Stage stage = new Stage(STAGE_NAME, executor);
    StageExecutorRequest request = new StageExecutorRequest(PIPELINE_NAME, PROCESS_ID, stage);
    AtomicReference<StageExecutorResult> result = new AtomicReference<>();
    executor.execute(request, (r) -> result.set(r));
    while (result.get() == null) {
        Time.wait(Duration.ofSeconds(1));
    }
    assertThat(result.get().isError()).isTrue();
}
Also used : Stage(pipelite.stage.Stage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Aggregations

Stage (pipelite.stage.Stage)62 Test (org.junit.jupiter.api.Test)49 Process (pipelite.process.Process)28 ProcessBuilder (pipelite.process.builder.ProcessBuilder)21 StageEntity (pipelite.entity.StageEntity)15 StageState (pipelite.stage.StageState)15 StageExecutorRequest (pipelite.stage.executor.StageExecutorRequest)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 ProcessEntity (pipelite.entity.ProcessEntity)9 SimpleLsfExecutorParameters (pipelite.stage.parameters.SimpleLsfExecutorParameters)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 StageExecutorResult (pipelite.stage.executor.StageExecutorResult)6 StageLogEntity (pipelite.entity.StageLogEntity)5 ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)3 ZonedDateTime (java.time.ZonedDateTime)2 Flogger (lombok.extern.flogger.Flogger)2 InternalErrorHandler (pipelite.error.InternalErrorHandler)2 SimpleLsfExecutor (pipelite.executor.SimpleLsfExecutor)2 SyncTestExecutor (pipelite.executor.SyncTestExecutor)2 ProcessState (pipelite.process.ProcessState)2