Search in sources :

Example 51 with ProcessorDTO

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);
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO)

Example 52 with ProcessorDTO

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);
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO)

Example 53 with ProcessorDTO

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);
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with ProcessorDTO

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;
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO)

Example 55 with ProcessorDTO

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;
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil)

Aggregations

ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)69 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)24 ArrayList (java.util.ArrayList)21 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)19 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)19 HashMap (java.util.HashMap)17 HashSet (java.util.HashSet)16 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)15 PortDTO (org.apache.nifi.web.api.dto.PortDTO)15 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)15 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)13 Map (java.util.Map)11 Response (javax.ws.rs.core.Response)11 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)11 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)11 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)10 List (java.util.List)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)9 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)9