Search in sources :

Example 11 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.

the class LegacyNifiRestClient method stopInputs.

public void stopInputs(ProcessGroupDTO groupDTO) {
    List<ProcessorDTO> inputs = NifiProcessUtil.getInputProcessors(groupDTO);
    if (inputs != null) {
        for (ProcessorDTO input : inputs) {
            stopProcessor(input);
        }
    }
    Set<PortDTO> inputPorts = getInputPorts(groupDTO.getId());
    if (inputPorts != null) {
        for (PortDTO port : inputPorts) {
            stopInputPort(groupDTO.getId(), port.getId());
        }
    }
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO)

Example 12 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.

the class LegacyNifiRestClient method disableInputProcessors.

public boolean disableInputProcessors(@Nonnull final String processGroupId) {
    // Get the processor list
    boolean updated = false;
    final List<ProcessorDTO> processors = getInputProcessors(processGroupId);
    if (processors.isEmpty()) {
        return false;
    }
    for (final ProcessorDTO processor : processors) {
        // Verify state of processor
        if (!NifiProcessUtil.PROCESS_STATE.DISABLED.name().equals(processor.getState())) {
            // Stop processor before setting final state
            if (!NifiProcessUtil.PROCESS_STATE.STOPPED.name().equals(processor.getState())) {
                stopProcessor(processor.getParentGroupId(), processor.getId());
            }
            // Set final state
            ProcessorDTO updateDto = new ProcessorDTO();
            updateDto.setId(processor.getId());
            updateDto.setParentGroupId(processor.getParentGroupId());
            updateDto.setState(NifiProcessUtil.PROCESS_STATE.DISABLED.name());
            updateProcessor(updateDto);
            updated = true;
        }
    }
    return updated;
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO)

Example 13 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.

the class NifiConnectionOrderVisitor method getRemoteProcessGroupAsVisitableProcessor.

private NifiVisitableProcessor getRemoteProcessGroupAsVisitableProcessor(String processGroupId, String parentGroupId) {
    NifiVisitableProcessor processor = visitedProcessors.get(processGroupId);
    if (processor == null) {
        ProcessorDTO processorDTO = processorsMap.get(processGroupId);
        if (processorDTO == null) {
            RemoteProcessGroupDTO remoteProcessGroupDTO = getRemoteGroup(processGroupId);
            if (remoteProcessGroupDTO != null) {
                processorDTO = new ProcessorDTO();
                processorDTO.setType("NiFi.RemoteProcessGroup");
                processorDTO.setId(processGroupId);
                processorDTO.setParentGroupId(parentGroupId);
                processorDTO.setName(remoteProcessGroupDTO.getName());
                processorDTO.setConfig(new ProcessorConfigDTO());
                processorsMap.put(processGroupId, processorDTO);
            }
        }
        if (processorDTO != null) {
            processor = new NifiVisitableProcessor(processorDTO);
        }
    }
    return processor;
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) NifiVisitableProcessor(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessor) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)

Example 14 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.

the class TemplateCreationHelperTest method updateControllerServiceReferencesWithRecursive.

/**
 * Verify recursively enabling controller services when updating processor properties.
 */
@Test
public void updateControllerServiceReferencesWithRecursive() {
    final List<ControllerServiceDTO> updatedControllerServices = new ArrayList<>();
    final List<NifiProperty> updatedProperties = new ArrayList<>();
    // Mock NiFi client
    final NiFiControllerServicesRestClient controllerServicesRestClient = Mockito.mock(NiFiControllerServicesRestClient.class);
    Mockito.when(controllerServicesRestClient.update(Mockito.any())).thenAnswer(answer -> {
        final ControllerServiceDTO controllerService = answer.getArgumentAt(0, ControllerServiceDTO.class);
        updatedControllerServices.add(controllerService);
        return controllerService;
    });
    final NiFiRestClient restClient = Mockito.mock(NiFiRestClient.class);
    Mockito.when(restClient.controllerServices()).thenReturn(controllerServicesRestClient);
    // Mock Legacy NiFi client
    final LegacyNifiRestClient legacyRestClient = Mockito.mock(LegacyNifiRestClient.class);
    Mockito.when(legacyRestClient.enableControllerServiceAndSetProperties(Mockito.any(), Mockito.any())).thenReturn(new ControllerServiceDTO());
    Mockito.when(legacyRestClient.getNiFiRestClient()).thenReturn(restClient);
    Mockito.when(legacyRestClient.getPropertyDescriptorTransform()).thenReturn(new MockNiFiPropertyDescriptorTransform());
    Mockito.doAnswer(invocation -> {
        updatedProperties.add(invocation.getArgumentAt(2, NifiProperty.class));
        return null;
    }).when(legacyRestClient).updateProcessorProperty(Mockito.isNull(String.class), Mockito.eq("P1"), Mockito.any());
    final ControllerServiceDTO service1 = new ControllerServiceDTO();
    service1.setDescriptors(Collections.singletonMap("service", newPropertyDescriptor("service", "com.example.Service2", "S2")));
    service1.setId("S1");
    service1.setName("Service1");
    service1.setProperties(newHashMap("service", "invalid"));
    service1.setState("DISABLED");
    final ControllerServiceDTO service2 = new ControllerServiceDTO();
    service2.setId("S2");
    service2.setName("Service2");
    service2.setProperties(new HashMap<>());
    service2.setState("ENABLED");
    Mockito.when(legacyRestClient.getControllerServices()).thenReturn(ImmutableSet.of(service1, service2));
    // Mock processors
    final ProcessorConfigDTO config = new ProcessorConfigDTO();
    config.setDescriptors(Collections.singletonMap("service", newPropertyDescriptor("service", "com.example.Service1", "S1")));
    config.setProperties(Collections.singletonMap("service", "invalid"));
    final ProcessorDTO processor = new ProcessorDTO();
    processor.setId("P1");
    processor.setName("Processor1");
    processor.setConfig(config);
    // Update processors
    final TemplateCreationHelper helper = new TemplateCreationHelper(legacyRestClient);
    helper.snapshotControllerServiceReferences();
    helper.identifyNewlyCreatedControllerServiceReferences();
    helper.updateControllerServiceReferences(Collections.singletonList(processor));
    // Verify updated properties
    Assert.assertEquals("Property 'Service' not set on controller service 'Server1'.", 1, updatedControllerServices.size());
    Assert.assertEquals("S2", updatedControllerServices.get(0).getProperties().get("service"));
    Assert.assertEquals("Property 'Service' not set on processor 'Processor1'.", 1, updatedProperties.size());
    Assert.assertEquals("S1", updatedProperties.get(0).getValue());
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ArrayList(java.util.ArrayList) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) NiFiControllerServicesRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiControllerServicesRestClient) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Test(org.junit.Test)

Example 15 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project kylo by Teradata.

the class NifiProcessUtil method getNonInputProcessors.

/**
 * Return a list of all processors under a process group that have connections coming into them.
 *
 * @param group a process group
 * @return a list of all processors under a process group that have connections coming into them
 */
public static List<ProcessorDTO> getNonInputProcessors(ProcessGroupDTO group) {
    List<ProcessorDTO> processors = new ArrayList<>();
    final List<ProcessorDTO> inputProcessors = getInputProcessors(group);
    if (group.getContents().getProcessors() != null) {
        processors = Lists.newArrayList(Iterables.filter(group.getContents().getProcessors(), new Predicate<ProcessorDTO>() {

            @Override
            public boolean apply(ProcessorDTO processorDTO) {
                return !inputProcessors.contains(processorDTO);
            }
        }));
    }
    if (group.getContents().getProcessGroups() != null) {
        for (ProcessGroupDTO groupDTO : group.getContents().getProcessGroups()) {
            processors.addAll(getNonInputProcessors(groupDTO));
        }
    }
    return processors;
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

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