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