Search in sources :

Example 1 with ScheduleRunner

use of pipelite.runner.schedule.ScheduleRunner in project pipelite by enasequence.

the class TestTypeScheduleRunner method assertSchedule.

private <T extends SingleStageTestProcessConfiguration> void assertSchedule(StageService stageServiceSpy, ConfigurableTestSchedule<T> f, int processCnt) {
    ScheduleRunner scheduleRunner = runnerService.getScheduleRunner();
    assertThat(scheduleRunner.getActiveProcessRunners().size()).isEqualTo(0);
    SingleStageTestProcessConfiguration testProcessConfiguration = f.getTestProcessConfiguration();
    assertThat(testProcessConfiguration.configuredProcessIds().size()).isEqualTo(processCnt);
    testProcessConfiguration.assertCompleted(processService, stageServiceSpy, metrics, processCnt);
    testProcessConfiguration.assertCompletedScheduleEntity(scheduleService, serviceConfiguration.getName(), processCnt);
}
Also used : SingleStageTestProcessConfiguration(pipelite.tester.process.SingleStageTestProcessConfiguration) ScheduleRunner(pipelite.runner.schedule.ScheduleRunner)

Example 2 with ScheduleRunner

use of pipelite.runner.schedule.ScheduleRunner in project pipelite by enasequence.

the class TestTypeScheduleRunner method runSchedules.

public <T extends SingleStageTestProcessConfiguration> void runSchedules(StageService stageServiceSpy, int schedulerSeconds, int processCnt, Function<TestType, T> testProcessConfigurationFactory) {
    // Register test pipelines.
    List<ConfigurableTestSchedule<T>> testSchedules = new ArrayList<>();
    for (TestType testType : TestType.tests) {
        ConfigurableTestSchedule<T> schedule = new ConfigurableTestSchedule<>("0/" + schedulerSeconds + " * * * * ?", testProcessConfigurationFactory.apply(testType));
        testSchedules.add(schedule);
        registeredPipelineService.registerPipeline(schedule);
    }
    registeredScheduleService.saveSchedules();
    // Spy stage service.
    TestType.spyStageService(stageServiceSpy);
    try {
        processRunnerPoolManager.createPools();
        ScheduleRunner scheduleRunner = runnerService.getScheduleRunner();
        for (ConfigurableTestSchedule<T> f : testSchedules) {
            scheduleRunner.setMaximumExecutions(f.pipelineName(), processCnt);
        }
        processRunnerPoolManager.startPools();
        processRunnerPoolManager.waitPoolsToStop();
        for (ConfigurableTestSchedule<T> f : testSchedules) {
            assertSchedule(stageServiceSpy, f, processCnt);
        }
    } finally {
        for (ConfigurableTestSchedule<T> f : testSchedules) {
            deleteSchedule(f);
        }
    }
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) ArrayList(java.util.ArrayList) ConfigurableTestSchedule(pipelite.tester.pipeline.ConfigurableTestSchedule)

Example 3 with ScheduleRunner

use of pipelite.runner.schedule.ScheduleRunner in project pipelite by enasequence.

the class ProcessRunnerPoolManagerTest method test.

@Test
public void test() {
    processRunnerPoolManager.createPools();
    assertThat(runnerService.isScheduleRunner()).isTrue();
    assertThat(runnerService.getPipelineRunners().size()).isEqualTo(1);
    ScheduleRunner scheduleRunner = runnerService.getScheduleRunner();
    scheduleRunner.setMaximumExecutions(testSchedule.pipelineName(), PROCESS_CNT);
    processRunnerPoolManager.startPools();
    processRunnerPoolManager.waitPoolsToStop();
    assertThat(pipeliteMetrics.pipeline(testSchedule.pipelineName()).stage().getSuccessCount()).isEqualTo(1);
    assertThat(pipeliteMetrics.pipeline(testPipeline.pipelineName()).stage().getSuccessCount()).isEqualTo(1);
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ScheduleRunner

use of pipelite.runner.schedule.ScheduleRunner in project pipelite by enasequence.

the class RetryService method retry.

/**
 * Retries a failed process.
 *
 * @param pipelineName the pipeline name
 * @param processId the processId
 * @throws PipeliteProcessRetryException if the process can't be retried
 */
public void retry(String pipelineName, String processId) {
    processService.isRetryProcess(pipelineName, processId);
    boolean isRetrySchedule = scheduleService.isRetrySchedule(pipelineName, processId);
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(pipelineName);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Retry stages
    for (Stage stage : process.getStages()) {
        stage.setStageEntity(getSavedStage(pipelineName, processId, stage.getStageName()));
        if (DependencyResolver.isPermanentlyFailedStage(stage)) {
            stage.getStageEntity().resetExecution();
            stageService.saveStage(stage);
        }
    }
    // Retry process
    process.setProcessEntity(getSavedProcess(pipelineName, processId));
    processService.startExecution(process.getProcessEntity());
    // Retry schedule
    if (isRetrySchedule) {
        ScheduleRunner scheduler = runnerService.getScheduleRunner();
        if (scheduler == null) {
            throw new PipeliteProcessRetryException(pipelineName, processId, "missing scheduler");
        }
        scheduler.retrySchedule(pipelineName, processId);
    }
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Stage(pipelite.stage.Stage) RegisteredPipeline(pipelite.RegisteredPipeline) Process(pipelite.process.Process)

Example 5 with ScheduleRunner

use of pipelite.runner.schedule.ScheduleRunner 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)

Aggregations

ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)6 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Process (pipelite.process.Process)2 Stage (pipelite.stage.Stage)2 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 RegisteredPipeline (pipelite.RegisteredPipeline)1 Schedule (pipelite.Schedule)1 ProcessEntity (pipelite.entity.ProcessEntity)1 ScheduleEntity (pipelite.entity.ScheduleEntity)1 StageEntity (pipelite.entity.StageEntity)1 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)1 ConfigurableTestSchedule (pipelite.tester.pipeline.ConfigurableTestSchedule)1 SingleStageTestProcessConfiguration (pipelite.tester.process.SingleStageTestProcessConfiguration)1