use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.
the class LegacyNifiRestClient method setProcessorState.
/**
* Update the Processor state
*/
private ProcessorDTO setProcessorState(ProcessorDTO processor, NifiProcessUtil.PROCESS_STATE state) {
ProcessorDTO updateDto = new ProcessorDTO();
updateDto.setId(processor.getId());
updateDto.setParentGroupId(processor.getParentGroupId());
updateDto.setState(state.name());
return updateProcessor(updateDto);
}
use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.
the class LegacyNifiRestClient method startProcessor.
public void startProcessor(String processorGroupId, String processorId) {
ProcessorDTO dto = new ProcessorDTO();
dto.setId(processorId);
dto.setParentGroupId(processorGroupId);
dto.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
updateProcessor(dto);
}
use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.
the class LegacyNifiRestClient method updateProcessorProperties.
public void updateProcessorProperties(String processGroupId, String processorId, List<NifiProperty> properties) {
Map<String, NifiProperty> propertyMap = NifiPropertyUtil.propertiesAsMap(properties);
// fetch the processor
ProcessorDTO processor = getProcessor(processGroupId, processorId);
// iterate through and update the properties
for (Map.Entry<String, NifiProperty> property : propertyMap.entrySet()) {
processor.getConfig().getProperties().put(property.getKey(), property.getValue().getValue());
}
updateProcessor(processor);
}
use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.
the class LegacyNifiRestClient method setInputProcessorState.
/**
* Finds an input processor of the specified type within the specified process group and sets it to the passed in {@code state}. Other input processors are set to {@code DISABLED}.
*
* @param processGroupId the id of the NiFi process group to be searched
* @param type the type (or Java class) of processor to set to {@code state}, or {@code null} to use the first processor
* @param state the state to set the matched input processor
* @return {@code true} if the processor was found, or {@code false} otherwise
*/
public boolean setInputProcessorState(@Nonnull final String processGroupId, @Nullable final String type, NifiProcessUtil.PROCESS_STATE state) {
// Get the processor list and the processor to be run
final List<ProcessorDTO> processors = getInputProcessors(processGroupId);
if (processors.isEmpty()) {
return false;
}
final ProcessorDTO selected = StringUtils.isBlank(type) ? processors.get(0) : NifiProcessUtil.findFirstProcessorsByType(processors, type);
if (selected == null) {
return false;
}
// Set selected processor to RUNNING and others to DISABLED
for (final ProcessorDTO processor : processors) {
// Verify state of processor
if (processor.equals(selected)) {
updateProcessorState(processor, state);
} else {
updateProcessorState(processor, NifiProcessUtil.PROCESS_STATE.DISABLED);
}
}
return true;
}
use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.
the class LegacyNifiRestClient method updateProcessorState.
/**
* Transitions the Processor into the correct state: {@code DISABLED, RUNNING, STOPPED}
*
* @param processorDTO the processor to update
* @param state the State which the processor should be set to
*/
private ProcessorDTO updateProcessorState(ProcessorDTO processorDTO, NifiProcessUtil.PROCESS_STATE state) {
NifiProcessUtil.PROCESS_STATE currentState = NifiProcessUtil.PROCESS_STATE.valueOf(processorDTO.getState());
if (NifiProcessUtil.PROCESS_STATE.DISABLED.equals(state) && !NifiProcessUtil.PROCESS_STATE.DISABLED.equals(currentState)) {
// disable it
// first stop it
ProcessorDTO updatedProcessor = updateProcessorState(processorDTO, NifiProcessUtil.PROCESS_STATE.STOPPED);
// then disable it
return setProcessorState(updatedProcessor, NifiProcessUtil.PROCESS_STATE.DISABLED);
}
if (NifiProcessUtil.PROCESS_STATE.RUNNING.equals(state) && !NifiProcessUtil.PROCESS_STATE.RUNNING.equals(currentState)) {
// run it
// first make sure its enabled
ProcessorDTO updatedProcessor = updateProcessorState(processorDTO, NifiProcessUtil.PROCESS_STATE.ENABLED);
return setProcessorState(updatedProcessor, NifiProcessUtil.PROCESS_STATE.RUNNING);
}
if (NifiProcessUtil.PROCESS_STATE.STOPPED.equals(state) && !NifiProcessUtil.PROCESS_STATE.STOPPED.equals(currentState)) {
// stop it
// first make sure its enabled
ProcessorDTO updatedProcessor = updateProcessorState(processorDTO, NifiProcessUtil.PROCESS_STATE.ENABLED);
setProcessorState(updatedProcessor, NifiProcessUtil.PROCESS_STATE.STOPPED);
}
if (NifiProcessUtil.PROCESS_STATE.ENABLED.equals(state) && !NifiProcessUtil.PROCESS_STATE.ENABLED.equals(currentState)) {
// if disabled, enable it
if (NifiProcessUtil.PROCESS_STATE.DISABLED.equals(currentState)) {
return setProcessorState(processorDTO, NifiProcessUtil.PROCESS_STATE.STOPPED);
}
return processorDTO;
}
return processorDTO;
}
Aggregations