Search in sources :

Example 21 with ConnectionDTO

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

the class LegacyNifiRestClient method startProcessGroupAndParentInputPorts.

public void startProcessGroupAndParentInputPorts(ProcessGroupDTO entity) {
    // 1 startAll
    try {
        startAll(entity.getId(), entity.getParentGroupId());
    } catch (NifiClientRuntimeException e) {
        log.error("Error trying to mark connection ports Running for {}", entity.getName());
    }
    Set<PortDTO> ports = null;
    try {
        ports = getPortsForProcessGroup(entity.getParentGroupId());
    } catch (NifiClientRuntimeException e) {
        log.error("Error getPortsForProcessGroup {}", entity.getName());
    }
    if (ports != null && !ports.isEmpty()) {
        Map<String, PortDTO> portsById = ports.stream().collect(Collectors.toMap(port -> port.getId(), port -> port));
        ProcessGroupFlowDTO flow = getNiFiRestClient().processGroups().flow(entity.getParentGroupId());
        if (flow != null) {
            Set<PortDTO> matchingPorts = new HashSet<>();
            flow.getFlow().getConnections().stream().map(connectionEntity -> connectionEntity.getComponent()).forEach(connectionDTO -> {
                // map input ports
                if (connectionDTO.getDestination().getGroupId().equalsIgnoreCase(entity.getId()) && portsById.containsKey(connectionDTO.getSource().getId())) {
                    matchingPorts.add(portsById.get(connectionDTO.getSource().getId()));
                }
                // map output ports
                if (connectionDTO.getSource().getGroupId().equalsIgnoreCase(entity.getId()) && portsById.containsKey(connectionDTO.getDestination().getId())) {
                    matchingPorts.add(portsById.get(connectionDTO.getDestination().getId()));
                }
            });
            for (PortDTO port : matchingPorts) {
                port.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
                if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name())) {
                    try {
                        if (port.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
                            PortDTO stoppedPort = stopInputPort(entity.getParentGroupId(), port.getId());
                            if (stoppedPort.getValidationErrors() != null && !stoppedPort.getValidationErrors().isEmpty()) {
                                startInputPort(entity.getParentGroupId(), port.getId());
                            } else {
                                String validationErrors = stoppedPort.getValidationErrors() != null ? ("Validation Errors: " + stoppedPort.getValidationErrors().stream().collect(Collectors.joining(","))) : "";
                                log.warn("Unable to start input port [" + port.getId() + "] with name: [" + port.getName() + "] within process group: [" + port.getParentGroupId() + "]. " + validationErrors);
                            }
                        } else {
                            startInputPort(entity.getParentGroupId(), port.getId());
                        }
                    } catch (NifiClientRuntimeException e) {
                        log.error("Error starting Input Port {} for process group {}", port.getName(), entity.getName());
                    }
                } else if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name())) {
                    try {
                        if (port.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
                            PortDTO stoppedPort = stopOutputPort(entity.getParentGroupId(), port.getId());
                            if (stoppedPort.getValidationErrors() != null && !stoppedPort.getValidationErrors().isEmpty()) {
                                startOutputPort(entity.getParentGroupId(), port.getId());
                            } else {
                                String validationErrors = stoppedPort.getValidationErrors() != null ? ("Validation Errors: " + stoppedPort.getValidationErrors().stream().collect(Collectors.joining(","))) : "";
                                log.warn("Unable to start output port [" + port.getId() + "] with name: [" + port.getName() + "] within process group: [" + port.getParentGroupId() + "]. " + validationErrors);
                            }
                        } else {
                            startOutputPort(entity.getParentGroupId(), port.getId());
                        }
                    } catch (NifiClientRuntimeException e) {
                        log.error("Error starting Output Port {} for process group {}", port.getName(), entity.getName());
                    }
                }
            }
        }
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) ClientErrorException(javax.ws.rs.ClientErrorException) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) ConfigurationPropertyReplacer(com.thinkbiganalytics.nifi.feedmgr.ConfigurationPropertyReplacer) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) AboutDTO(org.apache.nifi.web.api.dto.AboutDTO) Map(java.util.Map) BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) NifiPropertyGroup(com.thinkbiganalytics.nifi.rest.model.NifiPropertyGroup) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Predicate(com.google.common.base.Predicate) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Iterables(com.google.common.collect.Iterables) NifiConnectionOrderVisitorCache(com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache) NiFiPropertyDescriptor(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptor) HashMap(java.util.HashMap) NifiRemoteProcessGroupUtil(com.thinkbiganalytics.nifi.rest.support.NifiRemoteProcessGroupUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) NiFiObjectCache(com.thinkbiganalytics.nifi.rest.NiFiObjectCache) NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) Nonnull(javax.annotation.Nonnull) TemplateInstanceCreator(com.thinkbiganalytics.nifi.feedmgr.TemplateInstanceCreator) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) DocumentedTypeDTO(org.apache.nifi.web.api.dto.DocumentedTypeDTO) Logger(org.slf4j.Logger) TemplateCreationHelper(com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper) NifiEnvironmentProperties(com.thinkbiganalytics.nifi.feedmgr.NifiEnvironmentProperties) TimeUnit(java.util.concurrent.TimeUnit) SearchResultsDTO(org.apache.nifi.web.api.dto.search.SearchResultsDTO) Collections(java.util.Collections) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) HashSet(java.util.HashSet)

Example 22 with ConnectionDTO

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

the class AlignProcessGroupComponents method createLayoutGroups.

/**
 * Group the items together to create the various LayoutGroups needed for different Rendering
 */
private void createLayoutGroups() {
    Map<String, Set<ProcessGroupDTO>> outputPortIdToGroup = new HashMap<String, Set<ProcessGroupDTO>>();
    groupIdToOutputPorts = new HashMap<>();
    Map<String, Set<ProcessGroupDTO>> inputPortIdToGroup = new HashMap<String, Set<ProcessGroupDTO>>();
    groupIdToInputPorts = new HashMap<>();
    Map<String, Set<String>> groupIdToGroup = new HashMap<>();
    List<ProcessGroupDTO> connectedGroups = new LinkedList<>();
    parentProcessGroup.getContents().getConnections().stream().filter(connectionDTO -> (isOutputPortToGroupConnection(connectionDTO) || isGroupToGroupConnection(connectionDTO) || isInputPortToGroupConnection(connectionDTO))).forEach(connectionDTO -> {
        PortDTO outputPort = outputPortMap.get(connectionDTO.getDestination().getId()) == null ? outputPortMap.get(connectionDTO.getSource().getId()) : outputPortMap.get(connectionDTO.getDestination().getId());
        PortDTO inputPort = inputPortMap.get(connectionDTO.getSource().getId()) == null ? inputPortMap.get(connectionDTO.getDestination().getId()) : inputPortMap.get(connectionDTO.getSource().getId());
        ProcessGroupDTO destinationGroup = processGroupDTOMap.get(connectionDTO.getDestination().getGroupId());
        ProcessGroupDTO sourceGroup = processGroupDTOMap.get(connectionDTO.getSource().getGroupId());
        if (outputPort != null) {
            ProcessGroupDTO processGroup = destinationGroup == null ? sourceGroup : destinationGroup;
            outputPortIdToGroup.computeIfAbsent(outputPort.getId(), (key) -> new HashSet<ProcessGroupDTO>()).add(processGroup);
            groupIdToOutputPorts.computeIfAbsent(processGroup.getId(), (key) -> new HashSet<PortDTO>()).add(outputPort);
            if (processGroupWithConnectionsMap.containsKey(processGroup.getId())) {
                processGroupWithConnectionsMap.get(processGroup.getId()).addConnection(connectionDTO).addPort(outputPort);
            }
        }
        if (inputPort != null) {
            ProcessGroupDTO processGroup = destinationGroup == null ? sourceGroup : destinationGroup;
            inputPortIdToGroup.computeIfAbsent(inputPort.getId(), (key) -> new HashSet<ProcessGroupDTO>()).add(processGroup);
            groupIdToInputPorts.computeIfAbsent(processGroup.getId(), (key) -> new HashSet<PortDTO>()).add(inputPort);
            if (processGroupWithConnectionsMap.containsKey(processGroup.getId())) {
                processGroupWithConnectionsMap.get(processGroup.getId()).addConnection(connectionDTO).addPort(outputPort);
            }
        } else if (destinationGroup != null && sourceGroup != null) {
            groupIdToGroup.computeIfAbsent(sourceGroup.getId(), (key) -> new HashSet<String>()).add(destinationGroup.getId());
        }
    });
    // group port connections together
    groupIdToOutputPorts.entrySet().stream().forEach(entry -> {
        String processGroupId = entry.getKey();
        String portKey = entry.getValue().stream().map(portDTO -> portDTO.getId()).sorted().collect(Collectors.joining(","));
        portKey = "AAA" + portKey;
        layoutGroups.computeIfAbsent(portKey, (key) -> new ProcessGroupToOutputPort(entry.getValue())).add(processGroupDTOMap.get(processGroupId));
    });
    // group port connections together
    groupIdToInputPorts.entrySet().stream().forEach(entry -> {
        String processGroupId = entry.getKey();
        String portKey = entry.getValue().stream().map(portDTO -> portDTO.getId()).sorted().collect(Collectors.joining(","));
        portKey = "BBB" + portKey;
        layoutGroups.computeIfAbsent(portKey, (key) -> new InputPortToProcessGroup(entry.getValue())).add(processGroupDTOMap.get(processGroupId));
    });
    groupIdToGroup.entrySet().stream().forEach(entry -> {
        String sourceGroupId = entry.getKey();
        String processGroupKey = entry.getValue().stream().sorted().collect(Collectors.joining(","));
        processGroupKey = "CCC" + processGroupKey;
        layoutGroups.computeIfAbsent(processGroupKey, (key) -> new ProcessGroupToProcessGroup(entry.getValue())).add(processGroupDTOMap.get(entry.getKey()));
    });
    // add in any groups that dont have connections to ports
    processGroupDTOMap.values().stream().filter(processGroupDTO -> !groupIdToGroup.values().stream().flatMap(set -> set.stream()).collect(Collectors.toSet()).contains(processGroupDTO.getId()) && !groupIdToInputPorts.containsKey(processGroupDTO.getId()) && !groupIdToOutputPorts.containsKey(processGroupDTO.getId()) && !groupIdToGroup.containsKey(processGroupDTO.getId())).forEach(group -> {
        layoutGroups.computeIfAbsent("NO_PORTS", (key) -> new ProcessGroupWithoutConnections()).add(group);
    });
    // identify the sequence of processgroups if they are connected to each other
    List<String> startingProcessorIds = groupIdToGroup.keySet().stream().filter(id -> !groupIdToGroup.values().stream().anyMatch(ids -> ids.contains(id))).collect(Collectors.toList());
    connectedProcessGroups = new ArrayList<>();
    // start with these and attempt to create flows
    startingProcessorIds.forEach(id -> {
        LayoutOrder layoutOrder = new LayoutOrder(0, 0, processGroupDTOMap.get(id), new LinkedList<>());
        addPorts(layoutOrder, id);
        connectedProcessGroups.add(layoutOrder);
        buildLayoutOrder(layoutOrder, processGroupDTOMap.get(id), groupIdToGroup);
        ConnectedProcessGroup connectedProcessGroup = new ConnectedProcessGroup(layoutOrder);
        connectedProcessGroupsLayouts.add(connectedProcessGroup);
    });
}
Also used : Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) Set(java.util.Set) TemplateCreationHelper(com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) HashSet(java.util.HashSet) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) Map(java.util.Map) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) LinkedList(java.util.LinkedList) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PortDTO(org.apache.nifi.web.api.dto.PortDTO) LinkedList(java.util.LinkedList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) HashSet(java.util.HashSet)

Example 23 with ConnectionDTO

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

the class NifiConnectionOrderVisitor method searchConnectionMatchingSource.

private ConnectionDTO searchConnectionMatchingSource(String parentGroupId, String destinationId) {
    // search up to find the connection that matches this dest id
    try {
        ProcessGroupDTO parent = null;
        try {
            log.debug("fetch ProcessGroup for searchConnectionMatchingSource {} ", parentGroupId);
            parent = getGroup(parentGroupId);
        } catch (NifiComponentNotFoundException e) {
            log.debug("Exception searching Connection matching the source. Parent Group ID: " + parentGroupId + ", and destinationId of  " + destinationId);
        }
        if (parent != null) {
            // processGroup.getDto().setParent(parentParent.getProcessGroup());
            // get Contents of this parent
            NifiVisitableProcessGroup visitableProcessGroup = new NifiVisitableProcessGroup(parent);
            ConnectionDTO conn = visitableProcessGroup.getConnectionMatchingSourceId(destinationId);
            if (conn != null) {
                return conn;
            }
            if (conn == null && parent.getParentGroupId() != null) {
                return searchConnectionMatchingSource(parent.getParentGroupId(), destinationId);
            }
        }
    } catch (Exception e) {
        log.error("Exception searching Connection matching the source.  Parent Group ID: " + parentGroupId + ", and destinationId of  " + destinationId);
    }
    return null;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)

Example 24 with ConnectionDTO

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

the class NifiVisitableProcessGroup method accept.

/**
 * Visit this process group using the supplied visitor
 *
 * @param nifiVisitor the visitor
 */
@Override
public void accept(NifiFlowVisitor nifiVisitor) {
    if (dto.getContents() != null) {
        if (dto.getContents().getProcessors() != null) {
            for (ProcessorDTO processorDTO : dto.getContents().getProcessors()) {
                NifiVisitableProcessor processor = getOrCreateProcessor(nifiVisitor, processorDTO);
                nifiVisitor.visitProcessor(processor);
            }
        }
        if (dto.getContents().getProcessGroups() != null) {
            for (ProcessGroupDTO processGroupDTO : dto.getContents().getProcessGroups()) {
                if (processGroupDTO != null) {
                    nifiVisitor.visitProcessGroup(getOrCreateProcessGroup(nifiVisitor, processGroupDTO));
                }
            }
        }
        if (dto.getContents().getConnections() != null) {
            for (ConnectionDTO connectionDTO : dto.getContents().getConnections()) {
                nifiVisitor.visitConnection(new NifiVisitableConnection(this, connectionDTO));
            }
        }
        populateStartingAndEndingProcessors();
    }
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 25 with ConnectionDTO

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

the class NiFiConnectionsRestClientV1 method update.

@Override
public Optional<ConnectionDTO> update(@Nonnull ConnectionDTO connectionDTO) {
    Optional<ConnectionEntity> current = findEntityById(connectionDTO.getId());
    if (current.isPresent()) {
        ConnectionEntity connectionEntity = new ConnectionEntity();
        ConnectionDTO updateDto = new ConnectionDTO();
        connectionEntity.setComponent(updateDto);
        updateDto.setId(connectionDTO.getId());
        updateDto.setSelectedRelationships(connectionDTO.getSelectedRelationships());
        if (connectionDTO.getSource() != null) {
            updateDto.setSource(new ConnectableDTO());
            updateDto.getSource().setGroupId(connectionDTO.getSource().getGroupId());
            updateDto.getSource().setId(connectionDTO.getSource().getId());
            updateDto.getSource().setType(connectionDTO.getSource().getType());
        }
        if (connectionDTO.getDestination() != null) {
            updateDto.setDestination(new ConnectableDTO());
            updateDto.getDestination().setGroupId(connectionDTO.getDestination().getGroupId());
            updateDto.getDestination().setId(connectionDTO.getDestination().getId());
            updateDto.getDestination().setType(connectionDTO.getDestination().getType());
        }
        final RevisionDTO revision = new RevisionDTO();
        revision.setVersion(current.get().getRevision().getVersion());
        connectionEntity.setRevision(revision);
        try {
            return Optional.of(client.put(CONNECTION_PATH + connectionDTO.getId(), connectionEntity, ConnectionEntity.class).getComponent());
        } catch (Exception e) {
            log.error("Error updating connection entry info for connection: {} {} ", connectionDTO, e.getMessage());
            return Optional.empty();
        }
    }
    return Optional.empty();
}
Also used : ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) NotFoundException(javax.ws.rs.NotFoundException) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)

Aggregations

ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)66 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)35 ArrayList (java.util.ArrayList)32 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)32 HashSet (java.util.HashSet)30 PortDTO (org.apache.nifi.web.api.dto.PortDTO)28 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)25 List (java.util.List)24 HashMap (java.util.HashMap)20 Set (java.util.Set)20 Collectors (java.util.stream.Collectors)18 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Map (java.util.Map)16 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)15 Inject (javax.inject.Inject)15 NifiConnectionUtil (com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil)14 Optional (java.util.Optional)13 StringUtils (org.apache.commons.lang3.StringUtils)13