Search in sources :

Example 1 with PROCESS_STATE

use of com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.PROCESS_STATE in project kylo by Teradata.

the class AbstractNiFiProcessorsRestClient method genrateWakeSequence.

private List<Function<ProcessorDTO, ProcessorDTO>> genrateWakeSequence(ProcessorDTO originalProc) {
    List<Function<ProcessorDTO, ProcessorDTO>> sequence = new ArrayList<>();
    PROCESS_STATE state = PROCESS_STATE.valueOf(originalProc.getState().toUpperCase());
    SCHEDULE_STRATEGIES strategy = SCHEDULE_STRATEGIES.valueOf(originalProc.getConfig().getSchedulingStrategy().toUpperCase());
    // Stop the processor if it is disabled or running.
    if (state == PROCESS_STATE.DISABLED || state == PROCESS_STATE.RUNNING) {
        sequence.add((proc) -> {
            proc.setState(PROCESS_STATE.STOPPED.name());
            return updateWithRetry(proc, 5, 300, TimeUnit.MILLISECONDS);
        });
    }
    // In all other cases add the sequence: set a long timer -> start -> stop -> reset original scheduling.
    if (state != PROCESS_STATE.RUNNING || strategy != SCHEDULE_STRATEGIES.TIMER_DRIVEN) {
        // Set long timer -> start -> stop -> reset scheduling.
        sequence.add((proc) -> {
            proc.setConfig(createConfig(SCHEDULE_STRATEGIES.TIMER_DRIVEN.name(), TRIGGER_TIMER_PERIOD));
            proc.setState(PROCESS_STATE.RUNNING.name());
            return updateWithRetry(proc, 5, 300, TimeUnit.MILLISECONDS);
        });
        sequence.add((proc) -> {
            delay(2000);
            proc.setState(PROCESS_STATE.STOPPED.name());
            return updateWithRetry(proc, 5, 300, TimeUnit.MILLISECONDS);
        });
    }
    // Disable or start the processor again depending on its original state
    if (state == PROCESS_STATE.DISABLED) {
        sequence.add((proc) -> {
            proc.setConfig(createConfig(originalProc.getConfig().getSchedulingStrategy(), originalProc.getConfig().getSchedulingPeriod()));
            proc.setState(PROCESS_STATE.DISABLED.name());
            return updateWithRetry(proc, 5, 300, TimeUnit.MILLISECONDS);
        });
    } else if (state == PROCESS_STATE.RUNNING) {
        sequence.add((proc) -> {
            proc.setConfig(createConfig(originalProc.getConfig().getSchedulingStrategy(), originalProc.getConfig().getSchedulingPeriod()));
            proc.setState(PROCESS_STATE.RUNNING.name());
            return updateWithRetry(proc, 5, 300, TimeUnit.MILLISECONDS);
        });
    }
    return sequence;
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Logger(org.slf4j.Logger) SCHEDULE_STRATEGIES(com.thinkbiganalytics.nifi.rest.support.NifiFeedConstants.SCHEDULE_STRATEGIES) NifiProcessorSchedule(com.thinkbiganalytics.nifi.rest.model.NifiProcessorSchedule) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) LoggerFactory(org.slf4j.LoggerFactory) PROCESS_STATE(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.PROCESS_STATE) Function(java.util.function.Function) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) ArrayList(java.util.ArrayList) Function(java.util.function.Function) PROCESS_STATE(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.PROCESS_STATE) ArrayList(java.util.ArrayList) SCHEDULE_STRATEGIES(com.thinkbiganalytics.nifi.rest.support.NifiFeedConstants.SCHEDULE_STRATEGIES)

Aggregations

NifiProcessorSchedule (com.thinkbiganalytics.nifi.rest.model.NifiProcessorSchedule)1 NifiConstants (com.thinkbiganalytics.nifi.rest.support.NifiConstants)1 SCHEDULE_STRATEGIES (com.thinkbiganalytics.nifi.rest.support.NifiFeedConstants.SCHEDULE_STRATEGIES)1 PROCESS_STATE (com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.PROCESS_STATE)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Function (java.util.function.Function)1 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)1 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1