Search in sources :

Example 6 with StageEntity

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

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

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

the class ScheduleRunnerTest method assertStageEntities.

private void assertStageEntities(TestSchedule f, String processId) {
    String pipelineName = f.pipelineName();
    TestProcessConfiguration t = f.getTestProcessConfiguration();
    for (int i = 0; i < t.stageCnt; ++i) {
        StageEntity stageEntity = stageService.getSavedStage(f.pipelineName(), processId, "STAGE" + i).get();
        StageLogEntity stageLogEntity = stageService.getSavedStageLog(f.pipelineName(), processId, "STAGE" + i).get();
        assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
        assertThat(stageEntity.getProcessId()).isEqualTo(processId);
        assertThat(stageEntity.getExecutionCount()).isEqualTo(1);
        assertThat(stageEntity.getStartTime()).isNotNull();
        assertThat(stageEntity.getEndTime()).isNotNull();
        assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
        assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.executor.SyncTestExecutor");
        assertThat(stageEntity.getExecutorData()).isNull();
        assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 10000,\n" + "  \"maximumRetries\" : 0,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
        if (t.stageTestResult == StageTestResult.ERROR) {
            assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
            assertThat(stageEntity.getResultParams()).isNull();
        } else if (t.stageTestResult == StageTestResult.EXCEPTION) {
            assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
            assertThat(stageLogEntity.getStageLog()).contains("java.lang.RuntimeException: Expected exception");
        } else {
            assertThat(stageEntity.getStageState()).isEqualTo(StageState.SUCCESS);
            assertThat(stageEntity.getResultParams()).isNull();
        }
    }
}
Also used : StageLogEntity(pipelite.entity.StageLogEntity) StageEntity(pipelite.entity.StageEntity)

Example 9 with StageEntity

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

the class DependencyResolverTest method simulateStageExecution.

private static void simulateStageExecution(Stage stage, StageState stageState) {
    StageEntity stageEntity = new StageEntity();
    stage.setStageEntity(stageEntity);
    stageEntity.setStageState(PENDING);
    if (stageState == PENDING) {
        return;
    }
    stageEntity.startExecution();
    if (stageState == ACTIVE) {
        return;
    }
    stage.incrementImmediateExecutionCount();
    if (stageState == SUCCESS) {
        stageEntity.endExecution(StageExecutorResult.success());
    } else if (stageState == ERROR) {
        stageEntity.endExecution(StageExecutorResult.error());
    }
}
Also used : StageEntity(pipelite.entity.StageEntity)

Example 10 with StageEntity

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

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