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