Search in sources :

Example 31 with ProcessEntity

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

the class RetryServiceTest method retryFailedProcessThrowsBecauseNotFailed.

@Test
public void retryFailedProcessThrowsBecauseNotFailed() {
    String processId = PipeliteIdCreator.processId();
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(PIPELINE_NAME);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Save completed process
    process.setProcessEntity(processService.createExecution(PIPELINE_NAME, processId, 1));
    processService.startExecution(process.getProcessEntity());
    processService.endExecution(process, ProcessState.COMPLETED);
    // Check completed process
    ProcessEntity processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
    assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.COMPLETED);
    // Retry
    Exception exception = assertThrows(PipeliteProcessRetryException.class, () -> retryService.retry(PIPELINE_NAME, processId));
    assertThat(exception.getMessage()).contains("process is not failed");
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with ProcessEntity

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

the class RetryServiceTest method retryFailedSchedule.

@Test
public void retryFailedSchedule() {
    String serviceName = PipeliteIdCreator.serviceName();
    String processId = PipeliteIdCreator.processId();
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(SCHEDULE_NAME);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Failed process
    process.setProcessEntity(processService.createExecution(SCHEDULE_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(SCHEDULE_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);
    // Failed schedule
    scheduleService.createSchedule(serviceName, SCHEDULE_NAME, CRON);
    ScheduleEntity scheduleEntity = scheduleService.startExecution(SCHEDULE_NAME, processId);
    ZonedDateTime nextTime = CronUtils.launchTime(CRON, ZonedDateTime.now().plusHours(1));
    scheduleEntity = scheduleService.endExecution(processEntity, nextTime);
    assertThat(scheduleEntity.isFailed()).isTrue();
    // Create schedule runner
    processRunnerPoolManager._createScheduleRunner();
    ScheduleRunner scheduleRunner = runnerService.getScheduleRunner();
    scheduleRunner.setMaximumExecutions(SCHEDULE_NAME, 1);
    assertThat(scheduleRunner.getScheduleCrons().size()).isOne();
    assertThat(scheduleRunner.getScheduleCrons().get(0).getPipelineName()).isEqualTo(SCHEDULE_NAME);
    // Check schedule state
    assertSetupSchedule(serviceName, SCHEDULE_NAME, processId, CRON, nextTime);
    ZonedDateTime retryTime = ZonedDateTime.now();
    Time.wait(Duration.ofMillis(1000));
    scheduleRunner.startUp();
    // Retry
    retryService.retry(SCHEDULE_NAME, processId);
    while (!scheduleRunner.isIdle()) {
        scheduleRunner.runOneIteration();
        Time.wait(Duration.ofMillis(100));
    }
    // Check schedule state
    assertRetriedSchedule(serviceName, SCHEDULE_NAME, processId, CRON, retryTime);
    // Check process state
    processEntity = processService.getSavedProcess(SCHEDULE_NAME, processId).get();
    assertThat(processEntity.getPipelineName()).isEqualTo(SCHEDULE_NAME);
    assertThat(processEntity.getProcessId()).isEqualTo(processId);
    assertThat(processEntity.getStartTime()).isNotNull();
    assertThat(processEntity.getEndTime()).isNotNull();
    assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.COMPLETED);
    // Check stage state
    stageEntity = stageService.getSavedStage(SCHEDULE_NAME, processId, STAGE_NAME).get();
    assertThat(stageEntity.getPipelineName()).isEqualTo(SCHEDULE_NAME);
    assertThat(stageEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageEntity.getStageName()).isEqualTo(STAGE_NAME);
    assertThat(stageEntity.getStageState()).isEqualTo(StageState.SUCCESS);
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNotNull();
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) ZonedDateTime(java.time.ZonedDateTime) ProcessEntity(pipelite.entity.ProcessEntity) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with ProcessEntity

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

the class RetryServiceTest method retryFailedProcessThrowsUnknownStage.

@Test
public void retryFailedProcessThrowsUnknownStage() {
    String processId = PipeliteIdCreator.processId();
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(PIPELINE_NAME);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Save completed process
    process.setProcessEntity(processService.createExecution(PIPELINE_NAME, processId, 1));
    processService.startExecution(process.getProcessEntity());
    processService.endExecution(process, ProcessState.FAILED);
    // Check completed process
    ProcessEntity processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
    assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.FAILED);
    // Retry
    Exception exception = assertThrows(PipeliteProcessRetryException.class, () -> retryService.retry(PIPELINE_NAME, processId));
    assertThat(exception.getMessage()).contains("unknown stage");
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with ProcessEntity

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

the class ScheduleServiceTest method lifecycle.

@Test
public void lifecycle() {
    String serviceName = PipeliteIdCreator.serviceName();
    String pipelineName = PipeliteIdCreator.pipelineName();
    String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
    String description = CronUtils.describe(cron);
    ScheduleEntity s = scheduleService.createSchedule(serviceName, pipelineName, cron);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isZero();
    assertThat(s.getProcessId()).isNull();
    assertThat(s.getStartTime()).isNull();
    assertThat(s.getEndTime()).isNull();
    assertThat(s.getNextTime()).isNull();
    assertThat(s.getLastCompleted()).isNull();
    assertThat(s.getLastFailed()).isNull();
    assertThat(s.getStreakCompleted()).isEqualTo(0);
    assertThat(s.getStreakFailed()).isEqualTo(0);
    assertThat(s.isFailed()).isEqualTo(false);
    assertThat(s.isActive()).isEqualTo(false);
    // Get all schedules.
    List<ScheduleEntity> schedules = scheduleService.getSchedules(serviceName);
    assertThat(schedules.size()).isEqualTo(1);
    assertThat(schedules.get(0)).isEqualTo(s);
    // Get active schedules.
    List<ScheduleEntity> activeSchedules = scheduleService.getSchedules(serviceName);
    assertThat(activeSchedules.size()).isEqualTo(1);
    assertThat(activeSchedules.get(0)).isEqualTo(s);
    // Schedule first execution.
    ZonedDateTime nextTime1 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
    s = scheduleService.scheduleExecution(s, nextTime1);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isEqualTo(0);
    assertThat(s.getNextTime()).isEqualTo(nextTime1);
    assertThat(s.getStartTime()).isNull();
    assertThat(s.getEndTime()).isNull();
    assertThat(s.getLastCompleted()).isNull();
    assertThat(s.getLastFailed()).isNull();
    assertThat(s.getStreakCompleted()).isEqualTo(0);
    assertThat(s.getStreakFailed()).isEqualTo(0);
    assertThat(s.getProcessId()).isNull();
    assertThat(s.isFailed()).isEqualTo(false);
    assertThat(s.isActive()).isEqualTo(false);
    // Start first execution.
    String processId1 = "test1";
    s = scheduleService.startExecution(pipelineName, processId1);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isEqualTo(0);
    assertThat(s.getNextTime()).isNull();
    assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime1);
    assertThat(s.getEndTime()).isNull();
    assertThat(s.getLastCompleted()).isNull();
    assertThat(s.getLastFailed()).isNull();
    assertThat(s.getStreakCompleted()).isEqualTo(0);
    assertThat(s.getStreakFailed()).isEqualTo(0);
    assertThat(s.getProcessId()).isEqualTo(processId1);
    assertThat(s.isFailed()).isEqualTo(false);
    assertThat(s.isActive()).isEqualTo(true);
    // End first execution.
    ZonedDateTime endTime1 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
    ProcessEntity processEntity1 = new ProcessEntity();
    processEntity1.setPipelineName(pipelineName);
    processEntity1.setProcessId(processId1);
    processEntity1.setProcessState(ProcessState.COMPLETED);
    ZonedDateTime nextTime2 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
    s = scheduleService.endExecution(processEntity1, nextTime2);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isEqualTo(1);
    assertThat(s.getNextTime()).isEqualTo(nextTime2);
    assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime1);
    assertThat(s.getEndTime()).isAfterOrEqualTo(endTime1);
    assertThat(s.getLastCompleted()).isEqualTo(endTime1);
    assertThat(s.getLastFailed()).isNull();
    assertThat(s.getStreakCompleted()).isEqualTo(1);
    assertThat(s.getStreakFailed()).isEqualTo(0);
    assertThat(s.getProcessId()).isEqualTo(processId1);
    assertThat(s.isFailed()).isEqualTo(false);
    assertThat(s.isActive()).isEqualTo(false);
    // Start second execution.
    String processId2 = "test2";
    s = scheduleService.startExecution(pipelineName, processId2);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isEqualTo(1);
    assertThat(s.getNextTime()).isNull();
    assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime2);
    assertThat(s.getEndTime()).isNull();
    assertThat(s.getLastCompleted()).isEqualTo(endTime1);
    assertThat(s.getLastFailed()).isNull();
    assertThat(s.getStreakCompleted()).isEqualTo(1);
    assertThat(s.getStreakFailed()).isEqualTo(0);
    assertThat(s.getProcessId()).isEqualTo(processId2);
    assertThat(s.isFailed()).isEqualTo(false);
    assertThat(s.isActive()).isEqualTo(true);
    // End second execution.
    ZonedDateTime endTime2 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
    ProcessEntity processEntity2 = new ProcessEntity();
    processEntity2.setPipelineName(pipelineName);
    processEntity2.setProcessId(processId2);
    processEntity2.setProcessState(ProcessState.COMPLETED);
    ZonedDateTime nextTime3 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
    s = scheduleService.endExecution(processEntity2, nextTime3);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isEqualTo(2);
    assertThat(s.getNextTime()).isEqualTo(nextTime3);
    assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime2);
    assertThat(s.getEndTime()).isAfterOrEqualTo(endTime2);
    assertThat(s.getLastCompleted()).isEqualTo(s.getEndTime());
    assertThat(s.getLastFailed()).isNull();
    assertThat(s.getStreakCompleted()).isEqualTo(2);
    assertThat(s.getStreakFailed()).isEqualTo(0);
    assertThat(s.getProcessId()).isEqualTo(processId2);
    assertThat(s.isFailed()).isEqualTo(false);
    assertThat(s.isActive()).isEqualTo(false);
    // Start third execution.
    String processId3 = "test3";
    s = scheduleService.startExecution(pipelineName, processId3);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isEqualTo(2);
    assertThat(s.getNextTime()).isNull();
    assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime3);
    assertThat(s.getEndTime()).isNull();
    assertThat(s.getLastCompleted()).isAfterOrEqualTo(endTime2);
    assertThat(s.getLastFailed()).isNull();
    assertThat(s.getStreakCompleted()).isEqualTo(2);
    assertThat(s.getStreakFailed()).isEqualTo(0);
    assertThat(s.getProcessId()).isEqualTo(processId3);
    assertThat(s.isFailed()).isEqualTo(false);
    assertThat(s.isActive()).isEqualTo(true);
    // End third execution (FAILED).
    ZonedDateTime endTime3 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
    ProcessEntity processEntity3 = new ProcessEntity();
    processEntity3.setPipelineName(pipelineName);
    processEntity3.setProcessId(processId3);
    processEntity3.setProcessState(ProcessState.FAILED);
    ZonedDateTime nextTime4 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
    s = scheduleService.endExecution(processEntity3, nextTime4);
    assertThat(s.getServiceName()).isEqualTo(serviceName);
    assertThat(s.getPipelineName()).isEqualTo(pipelineName);
    assertThat(s.getCron()).isEqualTo(cron);
    assertThat(s.getDescription()).isEqualTo(description);
    assertThat(s.getExecutionCount()).isEqualTo(3);
    assertThat(s.getNextTime()).isEqualTo(nextTime4);
    assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime3);
    assertThat(s.getEndTime()).isAfterOrEqualTo(endTime3);
    assertThat(s.getLastCompleted()).isAfterOrEqualTo(endTime2);
    assertThat(s.getLastFailed()).isEqualTo(s.getEndTime());
    assertThat(s.getStreakCompleted()).isEqualTo(0);
    assertThat(s.getStreakFailed()).isEqualTo(1);
    assertThat(s.getProcessId()).isEqualTo(processId3);
    assertThat(s.isFailed()).isEqualTo(true);
    assertThat(s.isActive()).isEqualTo(false);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 35 with ProcessEntity

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

the class PipelineRunnerFailureTest method assertProcessEntity.

private void assertProcessEntity(TestPipeline f, String processId) {
    String pipelineName = f.pipelineName();
    ProcessEntity processEntity = processService.getSavedProcess(f.pipelineName(), processId).get();
    assertThat(processEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(processEntity.getProcessId()).isEqualTo(processId);
    assertThat(processEntity.getExecutionCount()).isEqualTo(1);
    TestProcess t = f.testProcessConfiguration();
    if (t.stageTestResult == StageTestResult.NO_ERROR) {
        assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.COMPLETED);
    } else {
        assertThat(processEntity.getProcessState()).isEqualTo(// no re-executions allowed
        ProcessState.FAILED);
    }
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity)

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