Search in sources :

Example 36 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class ProcessRunnerPoolTest method testFailed.

@Test
public void testFailed() {
    AtomicLong lockProcessCnt = new AtomicLong();
    AtomicLong unlockProcessCnt = new AtomicLong();
    ProcessRunnerPool pool = createProcessRunnerPool(lockProcessCnt, unlockProcessCnt);
    AtomicInteger runProcessCnt = new AtomicInteger();
    for (int i = 0; i < PROCESS_CNT; i++) {
        Process process = createProcess((request) -> StageExecutorResult.error());
        pool.runProcess(PIPELINE_NAME, process, (p) -> runProcessCnt.incrementAndGet());
    }
    while (!pool.isIdle()) {
        Time.wait(Duration.ofSeconds(1));
        pool.runOneIteration();
    }
    PipelineMetrics pipelineMetrics = metrics.pipeline(PIPELINE_NAME);
    assertThat(runProcessCnt.get()).isEqualTo(PROCESS_CNT);
    assertThat(pipelineMetrics.process().getCompletedCount()).isZero();
    assertThat(pipelineMetrics.process().getFailedCount()).isEqualTo(PROCESS_CNT);
    assertThat(pipelineMetrics.process().getInternalErrorCount()).isZero();
    assertThat(metrics.getProcessRunnerPoolOneIterationTimer().mean(TimeUnit.SECONDS)).isLessThan(5);
    assertThat(metrics.getProcessRunnerOneIterationTimer().mean(TimeUnit.SECONDS)).isLessThan(5);
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getCompletedTimeSeries())).isZero();
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getFailedTimeSeries())).isEqualTo(PROCESS_CNT);
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getFailedTimeSeries(), ZonedDateTime.now().minusHours(1))).isEqualTo(PROCESS_CNT);
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getFailedTimeSeries(), ZonedDateTime.now().plusHours(1))).isZero();
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getInternalErrorTimeSeries())).isZero();
    assertThat(lockProcessCnt.get()).isEqualTo(PROCESS_CNT);
    assertThat(unlockProcessCnt.get()).isEqualTo(PROCESS_CNT);
    assertThat(pool.getActiveProcessCount()).isZero();
    assertThat(pool.getActiveProcessRunners().size()).isZero();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Process(pipelite.process.Process) PipelineMetrics(pipelite.metrics.PipelineMetrics) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class ProcessRunnerTest method evaluateProcessStateNoRetries.

private void evaluateProcessStateNoRetries(StageState firstStageState, StageState secondStageState, ProcessState state) {
    int firstStageExecutions = firstStageState != null ? 1 : 0;
    int secondStageExecutions = secondStageState != null ? 1 : 0;
    Process process = twoIndependentStagesProcess(firstStageState, secondStageState, firstStageExecutions, secondStageExecutions, 0, 0);
    Assertions.assertThat(ProcessRunner.evaluateProcessState(process)).isEqualTo(state);
}
Also used : Process(pipelite.process.Process)

Example 38 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class ProcessRunnerTest method twoIndependentStagesProcess.

public static Process twoIndependentStagesProcess(StageState firstStageState, StageState secondStageState, int firstStageExecutions, int secondStageExecutions, int maximumRetries, int immediateRetries) {
    ExecutorParameters executorParams = ExecutorParameters.builder().maximumRetries(maximumRetries).immediateRetries(immediateRetries).build();
    Process process = new ProcessBuilder("pipelite-test").execute("STAGE0").withSyncTestExecutor((request) -> null, executorParams).execute("STAGE1").withSyncTestExecutor((request) -> null, executorParams).build();
    List<Stage> stages = new ArrayList<>();
    Stage firstStage = process.getStage("STAGE0").get();
    StageEntity firstStageEntity = new StageEntity();
    firstStage.setStageEntity(firstStageEntity);
    firstStageEntity.setStageState(firstStageState);
    firstStageEntity.setExecutionCount(firstStageExecutions);
    for (int i = 0; i < firstStageExecutions; ++i) {
        firstStage.incrementImmediateExecutionCount();
    }
    stages.add(firstStage);
    Stage secondStage = process.getStage("STAGE1").get();
    StageEntity secondStageEntity = new StageEntity();
    secondStage.setStageEntity(secondStageEntity);
    secondStageEntity.setStageState(secondStageState);
    secondStageEntity.setExecutionCount(secondStageExecutions);
    for (int i = 0; i < secondStageExecutions; ++i) {
        secondStage.incrementImmediateExecutionCount();
    }
    stages.add(secondStage);
    return process;
}
Also used : StageState(pipelite.stage.StageState) Test(org.junit.jupiter.api.Test) List(java.util.List) ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) ProcessBuilder(pipelite.process.builder.ProcessBuilder) StageEntity(pipelite.entity.StageEntity) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions(org.assertj.core.api.Assertions) Process(pipelite.process.Process) ProcessState(pipelite.process.ProcessState) ArrayList(java.util.ArrayList) Stage(pipelite.stage.Stage) ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) ProcessBuilder(pipelite.process.builder.ProcessBuilder) ArrayList(java.util.ArrayList) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity)

Example 39 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class ProcessController method getProcesses.

private static List<ProcessInfo> getProcesses(ProcessRunnerPool processRunnerPool, String pipelineName) {
    List<ProcessInfo> processes = new ArrayList<>();
    for (ProcessRunner processRunner : processRunnerPool.getActiveProcessRunners()) {
        Process process = processRunner.getProcess();
        ProcessEntity processEntity = process.getProcessEntity();
        if (pipelineName == null || pipelineName.equals(processRunner.getPipelineName())) {
            ProcessInfo processInfo = getProcess(processEntity);
            processes.add(processInfo);
        }
    }
    return processes;
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) ArrayList(java.util.ArrayList) Process(pipelite.process.Process) ProcessInfo(pipelite.controller.api.info.ProcessInfo) ProcessRunner(pipelite.runner.process.ProcessRunner)

Example 40 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class StageController method stages.

@GetMapping("/{pipelineName}/{processId}")
@ResponseStatus(HttpStatus.OK)
@Operation(description = "Process stages")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "500", description = "Internal Server error") })
public List<StageInfo> stages(@PathVariable(value = "pipelineName") String pipelineName, @PathVariable(value = "processId") String processId) {
    List<StageInfo> list = new ArrayList<>();
    AtomicReference<Process> process = new AtomicReference<>();
    try {
        RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(pipelineName);
        ProcessBuilder processBuilder = new ProcessBuilder(processId);
        registeredPipeline.configureProcess(processBuilder);
        process.set(processBuilder.build());
    } catch (Exception ex) {
        log.atSevere().withCause(ex).log(ex.getMessage());
    }
    stageService.getSavedStages(pipelineName, processId).forEach(stageEntity -> list.add(getStage(stageEntity, process.get())));
    return list;
}
Also used : StageInfo(pipelite.controller.api.info.StageInfo) ProcessBuilder(pipelite.process.builder.ProcessBuilder) ArrayList(java.util.ArrayList) Process(pipelite.process.Process) AtomicReference(java.util.concurrent.atomic.AtomicReference) RegisteredPipeline(pipelite.RegisteredPipeline) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

Process (pipelite.process.Process)40 Test (org.junit.jupiter.api.Test)29 Stage (pipelite.stage.Stage)27 ProcessBuilder (pipelite.process.builder.ProcessBuilder)24 ProcessEntity (pipelite.entity.ProcessEntity)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 StageState (pipelite.stage.StageState)14 StageEntity (pipelite.entity.StageEntity)8 StageLogEntity (pipelite.entity.StageLogEntity)4 ArrayList (java.util.ArrayList)3 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)3 ZonedDateTime (java.time.ZonedDateTime)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 RegisteredPipeline (pipelite.RegisteredPipeline)2 ScheduleEntity (pipelite.entity.ScheduleEntity)2 SyncTestExecutor (pipelite.executor.SyncTestExecutor)2 PipelineMetrics (pipelite.metrics.PipelineMetrics)2 ProcessState (pipelite.process.ProcessState)2 ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)2