Search in sources :

Example 11 with ProcessEntity

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

the class RetryServiceTest method retryFailedProcessNoPermanentlyFailedStages.

@Test
public void retryFailedProcessNoPermanentlyFailedStages() {
    String processId = PipeliteIdCreator.processId();
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(PIPELINE_NAME);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Save failed process
    process.setProcessEntity(processService.createExecution(PIPELINE_NAME, processId, 1));
    processService.startExecution(process.getProcessEntity());
    processService.endExecution(process, ProcessState.FAILED);
    // Check failed process
    ProcessEntity processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
    assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.FAILED);
    // Save completed stage
    Stage stage = process.getStage(STAGE_NAME).get();
    stageService.createExecution(PIPELINE_NAME, processId, stage);
    stageService.startExecution(stage);
    stageService.endExecution(stage, StageExecutorResult.success());
    // Check completed stage
    StageEntity stageEntity = stageService.getSavedStage(PIPELINE_NAME, processId, STAGE_NAME).get();
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.SUCCESS);
    // Retry
    retryService.retry(PIPELINE_NAME, processId);
    processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
    assertThat(processEntity.getPipelineName()).isEqualTo(PIPELINE_NAME);
    assertThat(processEntity.getProcessId()).isEqualTo(processId);
    assertThat(processEntity.getPriority()).isEqualTo(1);
    assertThat(processEntity.getExecutionCount()).isEqualTo(1);
    assertThat(processEntity.getStartTime()).isNotNull();
    // Made null
    assertThat(processEntity.getEndTime()).isNull();
    assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.ACTIVE);
    // Check that stage state is unchanged
    stageEntity.equals(stageService.getSavedStage(PIPELINE_NAME, processId, STAGE_NAME).get());
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with ProcessEntity

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

the class RetryServiceTest method retryFailedProcess.

@Test
public void retryFailedProcess() {
    String processId = PipeliteIdCreator.processId();
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(PIPELINE_NAME);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Failed process
    process.setProcessEntity(processService.createExecution(PIPELINE_NAME, processId, 1));
    processService.startExecution(process.getProcessEntity());
    ProcessEntity processEntity = processService.endExecution(process, ProcessState.FAILED);
    // Failed stage
    Stage stage = process.getStage(STAGE_NAME).get();
    stageService.createExecution(PIPELINE_NAME, processId, stage);
    stageService.startExecution(stage);
    stageService.endExecution(stage, StageExecutorResult.error());
    StageEntity stageEntity = stage.getStageEntity();
    assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.FAILED);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
    // Retry
    retryService.retry(PIPELINE_NAME, processId);
    // Check process state
    processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
    assertThat(processEntity.getPipelineName()).isEqualTo(PIPELINE_NAME);
    assertThat(processEntity.getProcessId()).isEqualTo(processId);
    assertThat(processEntity.getStartTime()).isNotNull();
    assertThat(processEntity.getEndTime()).isNull();
    assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.ACTIVE);
    // Check stage state
    stageEntity = stageService.getSavedStage(PIPELINE_NAME, processId, STAGE_NAME).get();
    assertThat(stageEntity.getPipelineName()).isEqualTo(PIPELINE_NAME);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(STAGE_NAME);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.PENDING);
    assertThat(stageEntity.getStartTime()).isNull();
    assertThat(stageEntity.getEndTime()).isNull();
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with ProcessEntity

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

the class ScheduleServiceTest method isRetryScheduleWithNewExecutionWithinRetryMargin.

@Test
public void isRetryScheduleWithNewExecutionWithinRetryMargin() {
    String serviceName = PipeliteIdCreator.serviceName();
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
    ScheduleEntity scheduleEntity = scheduleService.createSchedule(serviceName, pipelineName, cron);
    assertThat(scheduleEntity.isFailed()).isFalse();
    scheduleEntity = scheduleService.startExecution(pipelineName, processId);
    assertThat(scheduleEntity.isFailed()).isFalse();
    ProcessEntity processEntity = ProcessEntity.createExecution(pipelineName, processId, 1);
    processEntity.endExecution(ProcessState.FAILED);
    scheduleEntity = scheduleService.endExecution(processEntity, ZonedDateTime.now());
    assertThat(scheduleEntity.isFailed()).isTrue();
    PipeliteProcessRetryException ex = assertThrows(PipeliteProcessRetryException.class, () -> scheduleService.isRetrySchedule(pipelineName, processId));
    assertThat(ex.getMessage()).contains("the next process for the schedule will be executed in less than");
}
Also used : PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with ProcessEntity

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

the class ScheduleServiceTest method isRetryScheduleWithFailedSchedule.

@Test
public void isRetryScheduleWithFailedSchedule() {
    String serviceName = PipeliteIdCreator.serviceName();
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
    ScheduleEntity scheduleEntity = scheduleService.createSchedule(serviceName, pipelineName, cron);
    assertThat(scheduleEntity.isFailed()).isFalse();
    scheduleEntity = scheduleService.startExecution(pipelineName, processId);
    assertThat(scheduleEntity.isFailed()).isFalse();
    ProcessEntity processEntity = ProcessEntity.createExecution(pipelineName, processId, 1);
    processEntity.endExecution(ProcessState.FAILED);
    scheduleEntity = scheduleService.endExecution(processEntity, ZonedDateTime.now().plusDays(1));
    assertThat(scheduleEntity.isFailed()).isTrue();
    assertThat(scheduleService.isRetrySchedule(pipelineName, processId)).isTrue();
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with ProcessEntity

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

the class ScheduleServiceTest method isRetryScheduleWithDifferentProcessId.

@Test
public void isRetryScheduleWithDifferentProcessId() {
    String serviceName = PipeliteIdCreator.serviceName();
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String differentProcessId = PipeliteIdCreator.processId();
    String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
    ScheduleEntity scheduleEntity = scheduleService.createSchedule(serviceName, pipelineName, cron);
    assertThat(scheduleEntity.isFailed()).isFalse();
    scheduleEntity = scheduleService.startExecution(pipelineName, processId);
    assertThat(scheduleEntity.isFailed()).isFalse();
    ProcessEntity processEntity = ProcessEntity.createExecution(pipelineName, processId, 1);
    processEntity.endExecution(ProcessState.FAILED);
    scheduleEntity = scheduleService.endExecution(processEntity, ZonedDateTime.now());
    assertThat(scheduleEntity.isFailed()).isTrue();
    PipeliteProcessRetryException ex = assertThrows(PipeliteProcessRetryException.class, () -> scheduleService.isRetrySchedule(pipelineName, differentProcessId));
    assertThat(ex.getMessage()).contains("a newer process execution exists for the schedule");
}
Also used : PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProcessEntity (pipelite.entity.ProcessEntity)39 Test (org.junit.jupiter.api.Test)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 Process (pipelite.process.Process)14 ProcessBuilder (pipelite.process.builder.ProcessBuilder)10 ScheduleEntity (pipelite.entity.ScheduleEntity)8 Stage (pipelite.stage.Stage)8 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)4 ZonedDateTime (java.time.ZonedDateTime)3 Pipeline (pipelite.Pipeline)3 StageEntity (pipelite.entity.StageEntity)3 StageLogEntity (pipelite.entity.StageLogEntity)3 PipeliteException (pipelite.exception.PipeliteException)2 Timed (io.micrometer.core.annotation.Timed)1 ArrayList (java.util.ArrayList)1 ProcessInfo (pipelite.controller.api.info.ProcessInfo)1 ProcessState (pipelite.process.ProcessState)1 ProcessRunner (pipelite.runner.process.ProcessRunner)1 ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)1 ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)1