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