Search in sources :

Example 1 with ProcessState

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

the class ProcessService method getProcessStateSummary.

@Timed("pipelite.transactional")
public List<ProcessStateSummary> getProcessStateSummary() {
    List<ProcessStateSummary> list = new ArrayList<>();
    String sql = "SELECT PIPELINE_NAME, STATE, COUNT(1) FROM PIPELITE2_PROCESS GROUP BY PIPELINE_NAME, STATE";
    Map<String, List<ProcessStateRow>> groupedByPipelineName = jdbcTemplate.query(sql, (rs, rowNum) -> {
        ProcessState state = null;
        try {
            state = ProcessState.valueOf(rs.getString(2));
        } catch (IllegalArgumentException ex) {
        // Ignore unknown states
        }
        ProcessStateRow row = new ProcessStateRow();
        row.setPipelineName(rs.getString(1));
        row.setProcessState(state);
        row.setCount(rs.getLong(3));
        return row;
    }).stream().collect(groupingBy(ProcessStateRow::getPipelineName));
    for (String pipelineName : groupedByPipelineName.keySet()) {
        Map<ProcessState, List<ProcessStateRow>> groupedByProcessState = groupedByPipelineName.get(pipelineName).stream().collect(groupingBy(ProcessStateRow::getProcessState));
        ProcessStateSummary stateSummary = new ProcessStateSummary();
        stateSummary.setPipelineName(pipelineName);
        if (groupedByProcessState.containsKey(ProcessState.PENDING)) {
            stateSummary.setPendingCount(groupedByProcessState.get(ProcessState.PENDING).get(0).count);
        }
        if (groupedByProcessState.containsKey(ProcessState.ACTIVE)) {
            stateSummary.setActiveCount(groupedByProcessState.get(ProcessState.ACTIVE).get(0).count);
        }
        if (groupedByProcessState.containsKey(ProcessState.COMPLETED)) {
            stateSummary.setCompletedCount(groupedByProcessState.get(ProcessState.COMPLETED).get(0).count);
        }
        if (groupedByProcessState.containsKey(ProcessState.FAILED)) {
            stateSummary.setFailedCount(groupedByProcessState.get(ProcessState.FAILED).get(0).count);
        }
        list.add(stateSummary);
    }
    return list;
}
Also used : ProcessState(pipelite.process.ProcessState) Timed(io.micrometer.core.annotation.Timed)

Example 2 with ProcessState

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

the class ProcessRunner method endProcessExecution.

private void endProcessExecution() {
    ProcessState processState = evaluateProcessState(process);
    logContext(log.atInfo()).log("Process execution finished: %s", processState.name());
    pipeliteServices.process().endExecution(process, processState);
}
Also used : ProcessState(pipelite.process.ProcessState)

Example 3 with ProcessState

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

the class ProcessServiceTest method assertProcessStateCount.

private void assertProcessStateCount(List<ProcessEntity> processes, int completedCount, int activeCount, int failedCount, int pendingCount) {
    Map<ProcessState, AtomicInteger> counter = new HashMap<>();
    counter.put(ProcessState.COMPLETED, new AtomicInteger());
    counter.put(ProcessState.ACTIVE, new AtomicInteger());
    counter.put(ProcessState.FAILED, new AtomicInteger());
    counter.put(ProcessState.PENDING, new AtomicInteger());
    processes.forEach(process -> counter.get(process.getProcessState()).incrementAndGet());
    assertThat(counter.get(ProcessState.COMPLETED).get()).isEqualTo(completedCount);
    assertThat(counter.get(ProcessState.ACTIVE).get()).isEqualTo(activeCount);
    assertThat(counter.get(ProcessState.FAILED).get()).isEqualTo(failedCount);
    assertThat(counter.get(ProcessState.PENDING).get()).isEqualTo(pendingCount);
}
Also used : ProcessState(pipelite.process.ProcessState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 4 with ProcessState

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

the class ProcessServiceTest method getProcesses.

@Test
public void getProcesses() {
    String pipelineName = PipeliteIdCreator.pipelineName();
    List<ProcessEntity> processes = Arrays.asList(saveProcess(pipelineName, ProcessState.ACTIVE, 1), saveProcess(pipelineName, ProcessState.ACTIVE, 1), saveProcess(pipelineName, ProcessState.COMPLETED, 1), saveProcess(pipelineName, ProcessState.COMPLETED, 1), saveProcess(pipelineName, ProcessState.FAILED, 1), saveProcess(pipelineName, ProcessState.FAILED, 1), saveProcess(pipelineName, ProcessState.PENDING, 1), saveProcess(pipelineName, ProcessState.PENDING, 1));
    // Test without state.
    assertProcessStateCount(processService.getProcesses(pipelineName, null, /* state*/
    MAX_PROCESS_COUNT), 2, 2, 2, 2);
    for (ProcessState state : EnumSet.of(ProcessState.ACTIVE, ProcessState.COMPLETED, ProcessState.FAILED, ProcessState.CANCELLED)) {
        assertProcessStateCount(processService.getProcesses(pipelineName, state, MAX_PROCESS_COUNT), state == ProcessState.COMPLETED ? 2 : 0, state == ProcessState.ACTIVE ? 2 : 0, state == ProcessState.FAILED ? 2 : 0, state == ProcessState.PENDING ? 2 : 0);
    }
}
Also used : ProcessState(pipelite.process.ProcessState) ProcessEntity(pipelite.entity.ProcessEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProcessState (pipelite.process.ProcessState)4 Timed (io.micrometer.core.annotation.Timed)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ProcessEntity (pipelite.entity.ProcessEntity)1