Search in sources :

Example 71 with ProcessGroupDTO

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

the class LegacyNifiRestClient method connectFeedToGlobalTemplate.

/**
 * Connect a Feed to a reusable Template
 */
public void connectFeedToGlobalTemplate(final String feedProcessGroupId, final String feedOutputName, final String categoryProcessGroupId, String reusableTemplateCategoryGroupId, String inputPortName) throws NifiComponentNotFoundException {
    ProcessGroupDTO categoryProcessGroup = getProcessGroup(categoryProcessGroupId, false, false);
    ProcessGroupDTO feedProcessGroup = getProcessGroup(feedProcessGroupId, false, false);
    ProcessGroupDTO categoryParent = getProcessGroup(categoryProcessGroup.getParentGroupId(), false, false);
    ProcessGroupDTO reusableTemplateCategoryGroup = getProcessGroup(reusableTemplateCategoryGroupId, false, false);
    // Go into the Feed and find the output port that is to be associated with the global template
    Set<PortDTO> outputPortsEntity = getOutputPorts(feedProcessGroupId);
    PortDTO feedOutputPort = null;
    if (outputPortsEntity != null) {
        feedOutputPort = NifiConnectionUtil.findPortMatchingName(outputPortsEntity, feedOutputName);
    }
    if (feedOutputPort == null) {
    // ERROR  This feed needs to have an output port assigned on it to make the connection
    }
    Set<PortDTO> inputPortsEntity = getInputPorts(reusableTemplateCategoryGroupId);
    PortDTO inputPort = NifiConnectionUtil.findPortMatchingName(inputPortsEntity, inputPortName);
    String inputPortId = inputPort.getId();
    final String categoryOutputPortName = categoryProcessGroup.getName() + " to " + inputPort.getName();
    // Find or create the output port that will join to the globabl template at the Category Level
    Set<PortDTO> categoryOutputPortsEntity = getOutputPorts(categoryProcessGroupId);
    PortDTO categoryOutputPort = null;
    if (categoryOutputPortsEntity != null) {
        categoryOutputPort = NifiConnectionUtil.findPortMatchingName(categoryOutputPortsEntity, categoryOutputPortName);
    }
    if (categoryOutputPort == null) {
        // create it
        PortDTO portDTO = new PortDTO();
        portDTO.setParentGroupId(categoryProcessGroupId);
        portDTO.setName(categoryOutputPortName);
        categoryOutputPort = client.processGroups().createOutputPort(categoryProcessGroupId, portDTO);
    }
    // Now create a connection from the Feed PRocessGroup to this outputPortEntity
    ConnectionDTO feedOutputToCategoryOutputConnection = NifiConnectionUtil.findConnection(findConnectionsForParent(categoryProcessGroupId), feedOutputPort.getId(), categoryOutputPort.getId());
    if (feedOutputToCategoryOutputConnection == null) {
        // CONNECT FEED OUTPUT PORT TO THE Category output port
        ConnectableDTO source = new ConnectableDTO();
        source.setGroupId(feedProcessGroupId);
        source.setId(feedOutputPort.getId());
        source.setName(feedProcessGroup.getName());
        source.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
        ConnectableDTO dest = new ConnectableDTO();
        dest.setGroupId(categoryProcessGroupId);
        dest.setName(categoryOutputPort.getName());
        dest.setId(categoryOutputPort.getId());
        dest.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
        createConnection(categoryProcessGroup.getId(), source, dest);
    }
    ConnectionDTO categoryToReusableTemplateConnection = NifiConnectionUtil.findConnection(findConnectionsForParent(categoryParent.getId()), categoryOutputPort.getId(), inputPortId);
    // Now connect the category PRocessGroup to the global template
    if (categoryToReusableTemplateConnection == null) {
        ConnectableDTO categorySource = new ConnectableDTO();
        categorySource.setGroupId(categoryProcessGroupId);
        categorySource.setId(categoryOutputPort.getId());
        categorySource.setName(categoryOutputPortName);
        categorySource.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
        ConnectableDTO categoryToGlobalTemplate = new ConnectableDTO();
        categoryToGlobalTemplate.setGroupId(reusableTemplateCategoryGroupId);
        categoryToGlobalTemplate.setId(inputPortId);
        categoryToGlobalTemplate.setName(inputPortName);
        categoryToGlobalTemplate.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
        createConnection(categoryParent.getId(), categorySource, categoryToGlobalTemplate);
    }
}
Also used : PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 72 with ProcessGroupDTO

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

the class LegacyNifiRestClient method getPortsForProcessGroup.

public Set<PortDTO> getPortsForProcessGroup(String processGroupId) throws NifiComponentNotFoundException {
    Set<PortDTO> ports = new HashSet<>();
    ProcessGroupDTO processGroupEntity = getProcessGroup(processGroupId, false, true);
    Set<PortDTO> inputPorts = processGroupEntity.getContents().getInputPorts();
    if (inputPorts != null) {
        ports.addAll(inputPorts);
    }
    Set<PortDTO> outputPorts = processGroupEntity.getContents().getOutputPorts();
    if (outputPorts != null) {
        ports.addAll(outputPorts);
    }
    return ports;
}
Also used : PortDTO(org.apache.nifi.web.api.dto.PortDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) HashSet(java.util.HashSet)

Example 73 with ProcessGroupDTO

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

the class LegacyNifiRestClient method deleteChildProcessGroups.

public List<ProcessGroupDTO> deleteChildProcessGroups(String processGroupId) throws NifiClientRuntimeException {
    List<ProcessGroupDTO> deletedEntities = new ArrayList<>();
    ProcessGroupDTO entity = getProcessGroup(processGroupId, true, true);
    if (entity != null && entity.getContents().getProcessGroups() != null) {
        for (ProcessGroupDTO groupDTO : entity.getContents().getProcessGroups()) {
            deletedEntities.add(deleteProcessGroup(groupDTO));
        }
    }
    return deletedEntities;
}
Also used : ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)

Example 74 with ProcessGroupDTO

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

the class LegacyNifiRestClient method getPropertiesForTemplate.

/**
 * @param parentProcessGroup         the parent group for which this template will reside
 * @param dto                        the template to parse
 * @param includePropertyDescriptors true to include propertyDescriptor details on each property, false to just include the property key
 * @return all the properties included in this template
 */
public List<NifiProperty> getPropertiesForTemplate(ProcessGroupDTO parentProcessGroup, TemplateDTO dto, boolean includePropertyDescriptors) {
    if (includePropertyDescriptors) {
        TemplateCreationHelper helper = new TemplateCreationHelper(this, niFiObjectCache);
        ProcessGroupDTO groupDTO = helper.createTemporaryTemplateFlow(dto.getId());
        dto.setSnippet(groupDTO.getContents());
    }
    return NifiPropertyUtil.getPropertiesForTemplate(parentProcessGroup, dto, propertyDescriptorTransform);
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) TemplateCreationHelper(com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper)

Example 75 with ProcessGroupDTO

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

the class AlignNiFiComponents method autoLayout.

/**
 * layout the NiFi components
 */
public void autoLayout() {
    AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(niFiRestClient, "root", new AlignComponentsConfig());
    ProcessGroupDTO root = alignProcessGroupComponents.autoLayout();
    // align all of roots children
    aligned = alignProcessGroupComponents.isAligned();
    root.getContents().getProcessGroups().stream().forEach(processGroupDTO -> {
        AlignProcessGroupComponents categoryAlign = new AlignProcessGroupComponents(niFiRestClient, processGroupDTO.getId(), new AlignComponentsConfig());
        ProcessGroupDTO groupDTO = categoryAlign.autoLayout();
        if (categoryAlign.isAligned() && groupDTO != null && groupDTO.getContents() != null && groupDTO.getContents().getProcessGroups() != null) {
            alignedProcessGroups += groupDTO.getContents().getProcessGroups().size();
        }
        aligned &= categoryAlign.isAligned();
    });
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Aggregations

ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)96 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)35 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)32 ArrayList (java.util.ArrayList)29 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)29 PortDTO (org.apache.nifi.web.api.dto.PortDTO)27 HashSet (java.util.HashSet)25 HashMap (java.util.HashMap)20 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)18 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)18 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)16 List (java.util.List)16 Set (java.util.Set)16 Collectors (java.util.stream.Collectors)15 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)15 Map (java.util.Map)14 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)13 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13