Search in sources :

Example 26 with Port

use of org.apache.nifi.connectable.Port in project nifi by apache.

the class PortAuditor method createPortAdvice.

/**
 * Audits the creation of a port.
 *
 * @param proceedingJoinPoint join point
 * @return port
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.PortDAO+) && " + "execution(org.apache.nifi.connectable.Port createPort(java.lang.String, org.apache.nifi.web.api.dto.PortDTO))")
public Port createPortAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // perform the underlying operation
    Port port = (Port) proceedingJoinPoint.proceed();
    // audit the port creation
    final Action action = generateAuditRecord(port, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return port;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Around(org.aspectj.lang.annotation.Around)

Example 27 with Port

use of org.apache.nifi.connectable.Port in project nifi by apache.

the class RelationshipAuditor method determineConnectableType.

/**
 * Determines the type of component the specified connectable is.
 */
private Component determineConnectableType(Connectable connectable) {
    String sourceId = connectable.getIdentifier();
    Component componentType = Component.Controller;
    if (connectable instanceof ProcessorNode) {
        componentType = Component.Processor;
    } else if (connectable instanceof RemoteGroupPort) {
        final RemoteGroupPort remoteGroupPort = (RemoteGroupPort) connectable;
        if (TransferDirection.RECEIVE.equals(remoteGroupPort.getTransferDirection())) {
            if (remoteGroupPort.getRemoteProcessGroup() == null) {
                componentType = Component.InputPort;
            } else {
                componentType = Component.OutputPort;
            }
        } else {
            if (remoteGroupPort.getRemoteProcessGroup() == null) {
                componentType = Component.OutputPort;
            } else {
                componentType = Component.InputPort;
            }
        }
    } else if (connectable instanceof Port) {
        ProcessGroup processGroup = connectable.getProcessGroup();
        if (processGroup.getInputPort(sourceId) != null) {
            componentType = Component.InputPort;
        } else if (processGroup.getOutputPort(sourceId) != null) {
            componentType = Component.OutputPort;
        }
    } else if (connectable instanceof Funnel) {
        componentType = Component.Funnel;
    }
    return componentType;
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) ProcessorNode(org.apache.nifi.controller.ProcessorNode) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Port(org.apache.nifi.connectable.Port) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Component(org.apache.nifi.action.Component)

Example 28 with Port

use of org.apache.nifi.connectable.Port in project nifi by apache.

the class SnippetAuditor method updateSnippetAdvice.

/**
 * Audits a bulk move.
 *
 * @param proceedingJoinPoint join point
 * @param snippetDTO dto
 * @param snippetDAO dao
 * @return snippet
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && " + "execution(org.apache.nifi.controller.Snippet updateSnippetComponents(org.apache.nifi.web.api.dto.SnippetDTO)) && " + "args(snippetDTO) && " + "target(snippetDAO)")
public Snippet updateSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, SnippetDTO snippetDTO, SnippetDAO snippetDAO) throws Throwable {
    // get the snippet before removing it
    Snippet snippet = snippetDAO.getSnippet(snippetDTO.getId());
    final String previousGroupId = snippet.getParentGroupId();
    // perform the underlying operation
    snippet = (Snippet) proceedingJoinPoint.proceed();
    // if this snippet is linked and its parent group id has changed
    final String groupId = snippetDTO.getParentGroupId();
    if (!previousGroupId.equals(groupId)) {
        // create move audit records for all items in this snippet
        final Collection<Action> actions = new ArrayList<>();
        for (String id : snippet.getProcessors().keySet()) {
            final ProcessorNode processor = processorDAO.getProcessor(id);
            final Action action = processorAuditor.generateAuditRecord(processor, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getFunnels().keySet()) {
            final Funnel funnel = funnelDAO.getFunnel(id);
            final Action action = funnelAuditor.generateAuditRecord(funnel, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getInputPorts().keySet()) {
            final Port port = inputPortDAO.getPort(id);
            final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getOutputPorts().keySet()) {
            final Port port = outputPortDAO.getPort(id);
            final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getRemoteProcessGroups().keySet()) {
            final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(id);
            final Action action = remoteProcessGroupAuditor.generateAuditRecord(remoteProcessGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getProcessGroups().keySet()) {
            final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
            final ProcessGroup processGroup = processGroupDAO.getProcessGroup(id);
            final Action action = processGroupAuditor.generateAuditRecord(processGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getConnections().keySet()) {
            final Connection connection = connectionDAO.getConnection(id);
            final Action action = relationshipAuditor.generateAuditRecordForConnection(connection, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        // save the actions
        if (CollectionUtils.isNotEmpty(actions)) {
            saveActions(actions, logger);
        }
    }
    return snippet;
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) Port(org.apache.nifi.connectable.Port) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Connection(org.apache.nifi.connectable.Connection) Snippet(org.apache.nifi.controller.Snippet) Around(org.aspectj.lang.annotation.Around)

Example 29 with Port

use of org.apache.nifi.connectable.Port in project nifi by apache.

the class StandardAuthorizableLookup method getRootGroupInputPort.

@Override
public RootGroupPortAuthorizable getRootGroupInputPort(String id) {
    final Port inputPort = inputPortDAO.getPort(id);
    if (!(inputPort instanceof RootGroupPort)) {
        throw new IllegalArgumentException(String.format("The specified id '%s' does not represent an input port in the root group.", id));
    }
    final DataTransferAuthorizable baseAuthorizable = new DataTransferAuthorizable(inputPort);
    return new RootGroupPortAuthorizable() {

        @Override
        public Authorizable getAuthorizable() {
            return baseAuthorizable;
        }

        @Override
        public AuthorizationResult checkAuthorization(NiFiUser user) {
            // perform the authorization of the user by using the underlying component, ensures consistent authorization with raw s2s
            final PortAuthorizationResult authorizationResult = ((RootGroupPort) inputPort).checkUserAuthorization(user);
            if (authorizationResult.isAuthorized()) {
                return AuthorizationResult.approved();
            } else {
                return AuthorizationResult.denied(authorizationResult.getExplanation());
            }
        }
    };
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) DataTransferAuthorizable(org.apache.nifi.authorization.resource.DataTransferAuthorizable) PortAuthorizationResult(org.apache.nifi.remote.PortAuthorizationResult)

Example 30 with Port

use of org.apache.nifi.connectable.Port in project nifi by apache.

the class SnippetUtils method resolveNameConflicts.

private void resolveNameConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup group) {
    // get a list of all names of ports so that we can rename the ports as needed.
    final List<String> existingPortNames = new ArrayList<>();
    for (final Port inputPort : group.getInputPorts()) {
        existingPortNames.add(inputPort.getName());
    }
    for (final Port outputPort : group.getOutputPorts()) {
        existingPortNames.add(outputPort.getName());
    }
    // rename ports
    if (snippetContents.getInputPorts() != null) {
        for (final PortDTO portDTO : snippetContents.getInputPorts()) {
            String portName = portDTO.getName();
            while (existingPortNames.contains(portName)) {
                portName = "Copy of " + portName;
            }
            portDTO.setName(portName);
            existingPortNames.add(portDTO.getName());
        }
    }
    if (snippetContents.getOutputPorts() != null) {
        for (final PortDTO portDTO : snippetContents.getOutputPorts()) {
            String portName = portDTO.getName();
            while (existingPortNames.contains(portName)) {
                portName = "Copy of " + portName;
            }
            portDTO.setName(portName);
            existingPortNames.add(portDTO.getName());
        }
    }
    // get a list of all names of process groups so that we can rename as needed.
    final Set<String> groupNames = new HashSet<>();
    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        groupNames.add(childGroup.getName());
    }
    if (snippetContents.getProcessGroups() != null) {
        for (final ProcessGroupDTO groupDTO : snippetContents.getProcessGroups()) {
            // 'Copy of...' so we do this only if there is no Version Control Information present.
            if (groupDTO.getVersionControlInformation() == null) {
                String groupName = groupDTO.getName();
                while (groupNames.contains(groupName)) {
                    groupName = "Copy of " + groupName;
                }
                groupDTO.setName(groupName);
            }
            groupNames.add(groupDTO.getName());
        }
    }
}
Also used : RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) Port(org.apache.nifi.connectable.Port) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Port (org.apache.nifi.connectable.Port)71 RootGroupPort (org.apache.nifi.remote.RootGroupPort)63 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)46 ProcessGroup (org.apache.nifi.groups.ProcessGroup)34 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)30 Connection (org.apache.nifi.connectable.Connection)27 ProcessorNode (org.apache.nifi.controller.ProcessorNode)27 ArrayList (java.util.ArrayList)26 HashSet (java.util.HashSet)25 Funnel (org.apache.nifi.connectable.Funnel)25 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)24 Label (org.apache.nifi.controller.label.Label)20 LinkedHashSet (java.util.LinkedHashSet)19 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)19 Connectable (org.apache.nifi.connectable.Connectable)18 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)18 HashMap (java.util.HashMap)16 Map (java.util.Map)16 Snippet (org.apache.nifi.controller.Snippet)16 Collections (java.util.Collections)15