Search in sources :

Example 1 with Stage

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

the class StageServiceTest method lifecycle.

@Test
public void lifecycle() {
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String stageName = PipeliteIdCreator.stageName();
    TestExecutor executor = new TestExecutor(StageState.SUCCESS);
    executor.setExecutorParams(ExecutorParameters.builder().immediateRetries(0).maximumRetries(1).timeout(Duration.ofSeconds(0)).build());
    Stage stage = Stage.builder().stageName(stageName).executor(executor).build();
    // Create execution.
    service.createExecution(pipelineName, processId, stage);
    StageEntity stageEntity = stage.getStageEntity();
    assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(stageName);
    assertThat(stageEntity.getExecutionCount()).isEqualTo(0);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.PENDING);
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"stageState\" : \"SUCCESS\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 1,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    // Start first execution.
    service.startExecution(stage);
    assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(stageName);
    assertThat(stageEntity.getExecutionCount()).isEqualTo(0);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.ACTIVE);
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"stageState\" : \"SUCCESS\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 1,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
    assertThat(service.getSavedStageLog(pipelineName, processId, stageName)).isNotPresent();
    // End first execution.
    StageExecutorResult firstExecutionResult = StageExecutorResult.error();
    service.endExecution(stage, firstExecutionResult);
    assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(stageName);
    assertThat(stageEntity.getExecutionCount()).isEqualTo(1);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNotNull();
    assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"stageState\" : \"SUCCESS\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 1,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
    Optional<StageLogEntity> stageLogEntity = service.getSavedStageLog(pipelineName, processId, stageName);
    assertThat(stageLogEntity).isPresent();
    // Start second execution.
    service.startExecution(stage);
    assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(stageName);
    assertThat(stageEntity.getExecutionCount()).isEqualTo(1);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.ACTIVE);
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"stageState\" : \"SUCCESS\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 1,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
    assertThat(service.getSavedStageLog(pipelineName, processId, stageName)).isNotPresent();
    // End second execution.
    StageExecutorResult secondExecutionResult = StageExecutorResult.success();
    service.endExecution(stage, secondExecutionResult);
    assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(stageName);
    assertThat(stageEntity.getExecutionCount()).isEqualTo(2);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.SUCCESS);
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNotNull();
    assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"stageState\" : \"SUCCESS\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 1,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
    stageLogEntity = service.getSavedStageLog(pipelineName, processId, stageName);
    assertThat(stageLogEntity).isPresent();
    // Reset execution.
    service.resetExecution(stage);
    assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(stageName);
    assertThat(stageEntity.getExecutionCount()).isEqualTo(0);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.PENDING);
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"stageState\" : \"SUCCESS\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 1,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
    assertThat(service.getSavedStageLog(pipelineName, processId, stageName)).isNotPresent();
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) StageLogEntity(pipelite.entity.StageLogEntity) Stage(pipelite.stage.Stage) StageEntity(pipelite.entity.StageEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Stage

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

the class StageExecutorSerializerTest method deserializeExecutionJson.

@Test
public void deserializeExecutionJson() {
    StageExecutorResult result = StageExecutorResult.success();
    StageEntity stageEntity = new StageEntity();
    Stage stage = Stage.builder().stageName("STAGE1").executor(new TestExecutor(StageState.from(result))).build();
    stage.setStageEntity(stageEntity);
    stageEntity.startExecution();
    stageEntity.setExecutorName(TestExecutor.class.getName());
    stageEntity.setExecutorData("{\n" + "  \"stageState\" : \"" + StageState.from(result).name() + "\"\n}");
    stageEntity.setExecutorParams("{\n" + "  \"maximumRetries\" : 3,\n" + "  \"immediateRetries\" : 3\n" + "}");
    assertThat(StageExecutorSerializer.deserializeExecution(stage, StageExecutorSerializer.Deserialize.JSON_EXECUTOR)).isTrue();
    assertThat(stage.getExecutor()).isNotNull();
    assertThat(stage.getExecutor()).isInstanceOf(TestExecutor.class);
    assertThat(((TestExecutor) stage.getExecutor()).getStageState()).isEqualTo(StageState.from(result));
    assertThat(stage.getExecutor().getExecutorParams()).isNotNull();
    assertThat(stage.getExecutor().getExecutorParams().getImmediateRetries()).isEqualTo(3);
    assertThat(stage.getExecutor().getExecutorParams().getMaximumRetries()).isEqualTo(3);
}
Also used : Stage(pipelite.stage.Stage) StageEntity(pipelite.entity.StageEntity) Test(org.junit.jupiter.api.Test)

Example 3 with Stage

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

the class StageExecutorSerializerTest method deserializeExecutionAsync.

@Test
public void deserializeExecutionAsync() {
    SimpleLsfExecutor lsfExecutor = StageExecutor.createSimpleLsfExecutor("test");
    lsfExecutor.setJobId("test");
    SimpleLsfExecutorParameters params = new SimpleLsfExecutorParameters();
    params.setHost("host");
    params.setQueue("queue");
    lsfExecutor.setExecutorParams(params);
    StageEntity stageEntity = new StageEntity();
    Stage stage = Stage.builder().stageName("STAGE1").executor(lsfExecutor).build();
    stage.setStageEntity(stageEntity);
    stageEntity.startExecution();
    StageService.prepareSaveStage(stage);
    assertThat(StageExecutorSerializer.deserializeExecution(stage, StageExecutorSerializer.Deserialize.ASYNC_EXECUTOR)).isTrue();
    assertThat(stage.getExecutor()).isNotNull();
    assertThat(stage.getExecutor()).isInstanceOf(SimpleLsfExecutor.class);
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.executor.SimpleLsfExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"jobId\" : \"test\",\n" + "  \"cmd\" : \"test\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 604800000,\n" + "  \"maximumRetries\" : 3,\n" + "  \"immediateRetries\" : 3,\n" + "  \"logLines\" : 1000,\n" + "  \"host\" : \"host\",\n" + "  \"logTimeout\" : 10000,\n" + "  \"queue\" : \"queue\"\n" + "}");
}
Also used : Stage(pipelite.stage.Stage) StageEntity(pipelite.entity.StageEntity) SimpleLsfExecutor(pipelite.executor.SimpleLsfExecutor) SimpleLsfExecutorParameters(pipelite.stage.parameters.SimpleLsfExecutorParameters) Test(org.junit.jupiter.api.Test)

Example 4 with Stage

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

the class LsfLogFilePathResolverTest method request.

private final StageExecutorRequest request() {
    Stage stage = Mockito.mock(Stage.class);
    when(stage.getStageName()).thenReturn(STAGE_NAME);
    StageExecutorRequest request = new StageExecutorRequest(PIPELITE_NAME, PROCESS_ID, stage);
    return request;
}
Also used : StageExecutorRequest(pipelite.stage.executor.StageExecutorRequest) Stage(pipelite.stage.Stage)

Example 5 with Stage

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

the class DependencyResolverTest method simulatedStageExecution.

private SingleStageProcess simulatedStageExecution(ErrorType errorType, int executionCount, int immediateCount, int maximumRetries, int immediateRetries) {
    StageEntity stageEntity = new StageEntity();
    stageEntity.setExecutionCount(executionCount);
    stageEntity.setStageState(ERROR);
    stageEntity.setErrorType(errorType);
    SyncTestExecutor executor = StageExecutor.createSyncTestExecutor(StageExecutorState.SUCCESS, null);
    executor.setExecutorParams(ExecutorParameters.builder().immediateRetries(immediateRetries).maximumRetries(maximumRetries).build());
    Stage stage = Stage.builder().stageName("STAGE").executor(executor).build();
    stage.setStageEntity(stageEntity);
    for (int i = 0; i < immediateCount; ++i) {
        stage.incrementImmediateExecutionCount();
    }
    return new SingleStageProcess(new Process("TEST", ProcessBuilderHelper.stageGraph(Arrays.asList(new ProcessBuilderHelper.AddedStage(stage)))), stage);
}
Also used : Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity) SyncTestExecutor(pipelite.executor.SyncTestExecutor)

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