Search in sources :

Example 1 with ProcessQueue

use of pipelite.runner.process.ProcessQueue in project pipelite by enasequence.

the class PipelineRunnerProcessQueueTest method test.

private void test(Pipeline pipeline) {
    ProcessEntityCreator processEntityCreator = new ProcessEntityCreator(pipeline, pipeliteServices.process());
    ProcessQueue processQueue = spy(new ProcessQueue(pipeliteConfiguration, pipeliteServices, pipeline));
    // Queue should be filled
    assertThat(processQueue.isRefreshQueue()).isTrue();
    // Queue should be empty
    assertThat(processQueue.getProcessQueueSize()).isZero();
    boolean lockProcess = true;
    PipelineRunner pipelineRunner = PipelineRunnerFactory.create(pipeliteConfiguration, pipeliteServices, pipeliteMetrics, pipeline, processEntityCreator, (pipeline1) -> processQueue, (pipelineName1, process1) -> new ProcessRunner(pipeliteConfiguration, pipeliteServices, pipeliteMetrics, pipelineName1, process1, lockProcess));
    // Wait for the processes to execute
    while (!pipelineRunner.isIdle()) {
        Time.wait(Duration.ofSeconds(1));
        pipelineRunner.runOneIteration();
    }
    // Refresh is called two times. Once before creating processes when
    // the process queue is created empty and immediately after
    // creating processing.
    verify(processQueue, times(2)).refreshQueue();
    assertThat(pipeliteMetrics.pipeline(pipeline.pipelineName()).stage().getSuccessCount()).isEqualTo(PROCESS_CNT);
    assertThat(processQueue.isRefreshQueue()).isFalse();
    assertThat(processQueue.getProcessQueueSize()).isZero();
}
Also used : ProcessQueue(pipelite.runner.process.ProcessQueue) ProcessEntityCreator(pipelite.runner.process.creator.ProcessEntityCreator) ProcessRunner(pipelite.runner.process.ProcessRunner)

Example 2 with ProcessQueue

use of pipelite.runner.process.ProcessQueue in project pipelite by enasequence.

the class PipelineRunner method refreshQueue.

private void refreshQueue() {
    if (processQueue.get() == null || processQueue.get().isRefreshQueue()) {
        if (activeRefreshQueue.compareAndSet(false, true)) {
            pipeliteServices.executor().refreshQueue().execute(() -> {
                internalErrorHandler.execute(() -> {
                    ProcessQueue p = processQueue.get();
                    boolean firstRefresh = p == null;
                    if (firstRefresh) {
                        // Create process queue.
                        // The process queue creation is intentionally deferred to
                        // happen here so that we will only assign the process queue
                        // after it has been refreshed once and processes have been
                        // created if needed.
                        p = processQueueFactory.create(pipeline);
                    }
                    // Refresh process queue.
                    p.refreshQueue();
                    if (p.getProcessQueueSize() == 0) {
                        // The process queue is empty.
                        // Create new process entities.
                        int createdProcessCount = processEntityCreator.create(p.getProcessQueueMaxSize());
                        replenishTime = ZonedDateTime.now();
                        if (createdProcessCount > 0) {
                            // Refresh process queue.
                            p.refreshQueue();
                        }
                    }
                    if (firstRefresh) {
                        processQueue.set(p);
                    }
                });
                activeRefreshQueue.set(false);
            });
        }
    }
}
Also used : ProcessQueue(pipelite.runner.process.ProcessQueue)

Example 3 with ProcessQueue

use of pipelite.runner.process.ProcessQueue in project pipelite by enasequence.

the class PipelineRunnerFactory method create.

public static PipelineRunner create(PipeliteConfiguration pipeliteConfiguration, PipeliteServices pipeliteServices, PipeliteMetrics pipeliteMetrics, String pipelineName) {
    // Get registered pipeline.
    RegisteredPipelineService registeredPipelineService = pipeliteServices.registeredPipeline();
    Pipeline pipeline = registeredPipelineService.getRegisteredPipeline(pipelineName, Pipeline.class);
    if (pipeline == null) {
        throw new PipeliteException("Missing pipeline: " + pipelineName);
    }
    // Get process creator.
    ProcessEntityCreator processEntityCreator = new ProcessEntityCreator(pipeline, pipeliteServices.process());
    ProcessQueueFactory processQueueFactory = (pipeline1) -> new ProcessQueue(pipeliteConfiguration, pipeliteServices, pipeline1);
    boolean lockProcess = true;
    ProcessRunnerFactory processRunnerFactory = (pipelineName1, process1) -> new ProcessRunner(pipeliteConfiguration, pipeliteServices, pipeliteMetrics, pipelineName1, process1, lockProcess);
    return create(pipeliteConfiguration, pipeliteServices, pipeliteMetrics, pipeline, processEntityCreator, processQueueFactory, processRunnerFactory);
}
Also used : ProcessQueue(pipelite.runner.process.ProcessQueue) ProcessRunnerFactory(pipelite.runner.process.ProcessRunnerFactory) PipeliteMetrics(pipelite.metrics.PipeliteMetrics) ProcessQueueFactory(pipelite.runner.process.ProcessQueueFactory) PipeliteException(pipelite.exception.PipeliteException) RegisteredPipelineService(pipelite.service.RegisteredPipelineService) ProcessEntityCreator(pipelite.runner.process.creator.ProcessEntityCreator) PipeliteConfiguration(pipelite.configuration.PipeliteConfiguration) Pipeline(pipelite.Pipeline) ProcessRunner(pipelite.runner.process.ProcessRunner) PipeliteServices(pipelite.service.PipeliteServices) ProcessQueueFactory(pipelite.runner.process.ProcessQueueFactory) ProcessRunnerFactory(pipelite.runner.process.ProcessRunnerFactory) RegisteredPipelineService(pipelite.service.RegisteredPipelineService) ProcessQueue(pipelite.runner.process.ProcessQueue) PipeliteException(pipelite.exception.PipeliteException) ProcessEntityCreator(pipelite.runner.process.creator.ProcessEntityCreator) ProcessRunner(pipelite.runner.process.ProcessRunner) Pipeline(pipelite.Pipeline)

Aggregations

ProcessQueue (pipelite.runner.process.ProcessQueue)3 ProcessRunner (pipelite.runner.process.ProcessRunner)2 ProcessEntityCreator (pipelite.runner.process.creator.ProcessEntityCreator)2 Pipeline (pipelite.Pipeline)1 PipeliteConfiguration (pipelite.configuration.PipeliteConfiguration)1 PipeliteException (pipelite.exception.PipeliteException)1 PipeliteMetrics (pipelite.metrics.PipeliteMetrics)1 ProcessQueueFactory (pipelite.runner.process.ProcessQueueFactory)1 ProcessRunnerFactory (pipelite.runner.process.ProcessRunnerFactory)1 PipeliteServices (pipelite.service.PipeliteServices)1 RegisteredPipelineService (pipelite.service.RegisteredPipelineService)1