Search in sources :

Example 16 with StageEntity

use of pipelite.entity.StageEntity 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 17 with StageEntity

use of pipelite.entity.StageEntity in project pipelite by enasequence.

the class StageService method deleteStageLog.

public static void deleteStageLog(StageLogRepository logRepository, Stage stage) {
    StageEntity stageEntity = stage.getStageEntity();
    StageLogEntityId stageLogEntityId = new StageLogEntityId(stageEntity.getProcessId(), stageEntity.getPipelineName(), stageEntity.getStageName());
    if (logRepository.existsById(stageLogEntityId)) {
        logRepository.deleteById(stageLogEntityId);
    }
}
Also used : StageLogEntityId(pipelite.entity.StageLogEntityId) StageEntity(pipelite.entity.StageEntity)

Example 18 with StageEntity

use of pipelite.entity.StageEntity in project pipelite by enasequence.

the class StageService method prepareSaveStage.

public static void prepareSaveStage(Stage stage) {
    StageExecutor stageExecutor = stage.getExecutor();
    StageEntity stageEntity = stage.getStageEntity();
    stageEntity.setExecutorName(stageExecutor.getClass().getName());
    if (stageExecutor instanceof JsonSerializableExecutor) {
        stageEntity.setExecutorData(((JsonSerializableExecutor) stageExecutor).serialize());
    }
    if (stageExecutor.getExecutorParams() != null) {
        stageEntity.setExecutorParams(stageExecutor.getExecutorParams().serialize());
    }
}
Also used : JsonSerializableExecutor(pipelite.executor.JsonSerializableExecutor) StageEntity(pipelite.entity.StageEntity) StageExecutor(pipelite.stage.executor.StageExecutor)

Example 19 with StageEntity

use of pipelite.entity.StageEntity in project pipelite by enasequence.

the class StageExecutorSerializer method deserializeExecution.

/**
 * Deserialize active stage executor and stage executor parameters. An asynchronous executor must
 * be in the POLL state to be deserialized.
 *
 * @oaran stage the stage being executed
 * @return true if the executor was deserialized
 */
public static <T extends ExecutorParameters> Boolean deserializeExecution(Stage stage, Deserialize deserialize) {
    if (!(stage.getExecutor() instanceof JsonSerializableExecutor)) {
        return false;
    }
    if (stage.getStageEntity().getStageState() != StageState.ACTIVE) {
        return false;
    }
    StageEntity stageEntity = stage.getStageEntity();
    if (stageEntity.getExecutorName() == null || stageEntity.getExecutorData() == null || stageEntity.getExecutorParams() == null) {
        return false;
    }
    StageExecutor deserializedExecutor = deserializeExecutor(stage, deserialize);
    if (deserializedExecutor == null) {
        logContext(log.atSevere(), stage).log("Failed to deserialize executor");
        return false;
    }
    if (deserialize == Deserialize.ASYNC_EXECUTOR) {
        AbstractAsyncExecutor deserializedAsyncExecutor = (AbstractAsyncExecutor) deserializedExecutor;
        if (deserializedAsyncExecutor.getJobId() == null) {
            return false;
        }
    }
    ExecutorParameters deserializedExecutorParams = deserializeExecutorParameters(stage, deserializedExecutor.getExecutorParamsType());
    if (deserializedExecutorParams == null) {
        return false;
    }
    logContext(log.atInfo(), stage).log("Using deserialized executor");
    stage.setExecutor(deserializedExecutor);
    deserializedExecutor.setExecutorParams(deserializedExecutorParams);
    return true;
}
Also used : JsonSerializableExecutor(pipelite.executor.JsonSerializableExecutor) ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) StageEntity(pipelite.entity.StageEntity) AbstractAsyncExecutor(pipelite.executor.AbstractAsyncExecutor)

Example 20 with StageEntity

use of pipelite.entity.StageEntity in project pipelite by enasequence.

the class StageService method endExecution.

/**
 * Called when the stage execution ends. Saves the stage and stage log.
 *
 * @param stage the stage
 * @param result the stage execution result
 */
@Timed("pipelite.transactional")
public void endExecution(Stage stage, StageExecutorResult result) {
    stage.incrementImmediateExecutionCount();
    StageEntity stageEntity = stage.getStageEntity();
    stageEntity.endExecution(result);
    saveStage(stage);
    saveStageLog(StageLogEntity.endExecution(stageEntity, result));
}
Also used : StageEntity(pipelite.entity.StageEntity) Timed(io.micrometer.core.annotation.Timed)

Aggregations

StageEntity (pipelite.entity.StageEntity)32 Stage (pipelite.stage.Stage)15 Test (org.junit.jupiter.api.Test)11 Process (pipelite.process.Process)8 StageState (pipelite.stage.StageState)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Timed (io.micrometer.core.annotation.Timed)3 ProcessEntity (pipelite.entity.ProcessEntity)3 ProcessBuilder (pipelite.process.builder.ProcessBuilder)3 ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)3 StageLogEntity (pipelite.entity.StageLogEntity)2 JsonSerializableExecutor (pipelite.executor.JsonSerializableExecutor)2 SyncTestExecutor (pipelite.executor.SyncTestExecutor)2 StageExecutorResult (pipelite.stage.executor.StageExecutorResult)2 SimpleLsfExecutorParameters (pipelite.stage.parameters.SimpleLsfExecutorParameters)2 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assertions (org.assertj.core.api.Assertions)1