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