Search in sources :

Example 1 with ExecutorParameters

use of pipelite.stage.parameters.ExecutorParameters in project pipelite by enasequence.

the class ProcessRunnerPoolTest method createProcess.

private Process createProcess(Function<StageExecutorRequest, StageExecutorResult> callback) {
    String processId = PipeliteIdCreator.processId();
    ExecutorParameters executorParams = new ExecutorParameters();
    executorParams.setMaximumRetries(0);
    Process process = new ProcessBuilder(processId).execute("STAGE1").withAsyncTestExecutor(callback, executorParams).build();
    ProcessEntity processEntity = ProcessEntity.createExecution(PIPELINE_NAME, processId, ProcessEntity.DEFAULT_PRIORITY);
    process.setProcessEntity(processEntity);
    return process;
}
Also used : ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) ProcessBuilder(pipelite.process.builder.ProcessBuilder) ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process)

Example 2 with ExecutorParameters

use of pipelite.stage.parameters.ExecutorParameters in project pipelite by enasequence.

the class StageRunner method getImmediateRetries.

/**
 * Returns the maximum number of immediate retries for the stage.
 *
 * @return The maximum number of immediate retries.
 */
public static int getImmediateRetries(Stage stage) {
    ExecutorParameters executorParams = stage.getExecutor().getExecutorParams();
    int immediateRetries = ExecutorParameters.DEFAULT_IMMEDIATE_RETRIES;
    if (executorParams.getImmediateRetries() != null) {
        immediateRetries = executorParams.getImmediateRetries();
    }
    return Math.min(Math.max(0, immediateRetries), getMaximumRetries(stage));
}
Also used : ExecutorParameters(pipelite.stage.parameters.ExecutorParameters)

Example 3 with ExecutorParameters

use of pipelite.stage.parameters.ExecutorParameters 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 4 with ExecutorParameters

use of pipelite.stage.parameters.ExecutorParameters in project pipelite by enasequence.

the class StageRunner method getMaximumRetries.

/**
 * Returns the maximum number of retries for the stage.
 *
 * @return The maximum number of retries.
 */
public static int getMaximumRetries(Stage stage) {
    ExecutorParameters executorParams = stage.getExecutor().getExecutorParams();
    int maximumRetries = ExecutorParameters.DEFAULT_MAX_RETRIES;
    if (executorParams.getMaximumRetries() != null) {
        maximumRetries = executorParams.getMaximumRetries();
    }
    return Math.max(0, maximumRetries);
}
Also used : ExecutorParameters(pipelite.stage.parameters.ExecutorParameters)

Example 5 with ExecutorParameters

use of pipelite.stage.parameters.ExecutorParameters in project pipelite by enasequence.

the class ProcessRunnerTest method twoIndependentStagesProcess.

public static Process twoIndependentStagesProcess(StageState firstStageState, StageState secondStageState, int firstStageExecutions, int secondStageExecutions, int maximumRetries, int immediateRetries) {
    ExecutorParameters executorParams = ExecutorParameters.builder().maximumRetries(maximumRetries).immediateRetries(immediateRetries).build();
    Process process = new ProcessBuilder("pipelite-test").execute("STAGE0").withSyncTestExecutor((request) -> null, executorParams).execute("STAGE1").withSyncTestExecutor((request) -> null, executorParams).build();
    List<Stage> stages = new ArrayList<>();
    Stage firstStage = process.getStage("STAGE0").get();
    StageEntity firstStageEntity = new StageEntity();
    firstStage.setStageEntity(firstStageEntity);
    firstStageEntity.setStageState(firstStageState);
    firstStageEntity.setExecutionCount(firstStageExecutions);
    for (int i = 0; i < firstStageExecutions; ++i) {
        firstStage.incrementImmediateExecutionCount();
    }
    stages.add(firstStage);
    Stage secondStage = process.getStage("STAGE1").get();
    StageEntity secondStageEntity = new StageEntity();
    secondStage.setStageEntity(secondStageEntity);
    secondStageEntity.setStageState(secondStageState);
    secondStageEntity.setExecutionCount(secondStageExecutions);
    for (int i = 0; i < secondStageExecutions; ++i) {
        secondStage.incrementImmediateExecutionCount();
    }
    stages.add(secondStage);
    return process;
}
Also used : StageState(pipelite.stage.StageState) Test(org.junit.jupiter.api.Test) List(java.util.List) ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) ProcessBuilder(pipelite.process.builder.ProcessBuilder) StageEntity(pipelite.entity.StageEntity) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions(org.assertj.core.api.Assertions) Process(pipelite.process.Process) ProcessState(pipelite.process.ProcessState) ArrayList(java.util.ArrayList) Stage(pipelite.stage.Stage) ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) ProcessBuilder(pipelite.process.builder.ProcessBuilder) ArrayList(java.util.ArrayList) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity)

Aggregations

ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)6 StageEntity (pipelite.entity.StageEntity)3 Test (org.junit.jupiter.api.Test)2 Process (pipelite.process.Process)2 ProcessBuilder (pipelite.process.builder.ProcessBuilder)2 Stage (pipelite.stage.Stage)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ProcessEntity (pipelite.entity.ProcessEntity)1 AbstractAsyncExecutor (pipelite.executor.AbstractAsyncExecutor)1 JsonSerializableExecutor (pipelite.executor.JsonSerializableExecutor)1 ProcessState (pipelite.process.ProcessState)1 StageState (pipelite.stage.StageState)1 SimpleLsfExecutorParameters (pipelite.stage.parameters.SimpleLsfExecutorParameters)1