Search in sources :

Example 1 with ConnectDetails

use of org.apache.nifi.action.details.ConnectDetails in project nifi by apache.

the class RelationshipAuditor method createConnectionAdvice.

/**
 * Audits the creation of relationships via createConnection().
 *
 * This method only needs to be run 'after returning'. However, in Java 7 the order in which these methods are returned from Class.getDeclaredMethods (even though there is no order guaranteed)
 * seems to differ from Java 6. SpringAOP depends on this ordering to determine advice precedence. By normalizing all advice into Around advice we can alleviate this issue.
 *
 * @param proceedingJoinPoint join point
 * @return connection
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ConnectionDAO+) && " + "execution(org.apache.nifi.connectable.Connection createConnection(java.lang.String, org.apache.nifi.web.api.dto.ConnectionDTO))")
public Connection createConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // perform the underlying operation
    Connection connection = (Connection) proceedingJoinPoint.proceed();
    // audit the connection creation
    final ConnectDetails connectDetails = createConnectDetails(connection, connection.getRelationships());
    final Action action = generateAuditRecordForConnection(connection, Operation.Connect, connectDetails);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return connection;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) Around(org.aspectj.lang.annotation.Around)

Example 2 with ConnectDetails

use of org.apache.nifi.action.details.ConnectDetails in project nifi by apache.

the class RelationshipAuditor method removeConnectionAdvice.

/**
 * Audits the removal of relationships via deleteConnection().
 *
 * @param proceedingJoinPoint join point
 * @param id id
 * @param connectionDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ConnectionDAO+) && " + "execution(void deleteConnection(java.lang.String)) && " + "args(id) && " + "target(connectionDAO)")
public void removeConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint, String id, ConnectionDAO connectionDAO) throws Throwable {
    // get the connection before performing the update
    Connection connection = connectionDAO.getConnection(id);
    // perform the underlying operation
    proceedingJoinPoint.proceed();
    // audit the connection creation
    final ConnectDetails connectDetails = createConnectDetails(connection, connection.getRelationships());
    final Action action = generateAuditRecordForConnection(connection, Operation.Disconnect, connectDetails);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) Around(org.aspectj.lang.annotation.Around)

Example 3 with ConnectDetails

use of org.apache.nifi.action.details.ConnectDetails in project nifi by apache.

the class RelationshipAuditor method updateConnectionAdvice.

/**
 * Audits the creation and removal of relationships via updateConnection().
 *
 * @param proceedingJoinPoint join point
 * @param connectionDTO dto
 * @param connectionDAO dao
 * @return connection
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ConnectionDAO+) && " + "execution(org.apache.nifi.connectable.Connection updateConnection(org.apache.nifi.web.api.dto.ConnectionDTO)) && " + "args(connectionDTO) && " + "target(connectionDAO)")
public Connection updateConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint, ConnectionDTO connectionDTO, ConnectionDAO connectionDAO) throws Throwable {
    // get the previous configuration
    Connection connection = connectionDAO.getConnection(connectionDTO.getId());
    Connectable previousDestination = connection.getDestination();
    Collection<Relationship> previousRelationships = connection.getRelationships();
    Map<String, String> values = extractConfiguredPropertyValues(connection, connectionDTO);
    // perform the underlying operation
    connection = (Connection) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<Action> actions = new ArrayList<>();
        Map<String, String> updatedValues = extractConfiguredPropertyValues(connection, connectionDTO);
        // get the source
        Connectable source = connection.getSource();
        // get the current target
        Connectable destination = connection.getDestination();
        // determine if a new target was specified in the initial request
        if (destination != null && !previousDestination.getIdentifier().equals(destination.getIdentifier())) {
            // record the removal of all relationships from the previous target
            final ConnectDetails disconnectDetails = createConnectDetails(connection, source, previousRelationships, previousDestination);
            actions.add(generateAuditRecordForConnection(connection, Operation.Disconnect, disconnectDetails));
            // record the addition of all relationships to the new target
            final ConnectDetails connectDetails = createConnectDetails(connection, connection.getRelationships());
            actions.add(generateAuditRecordForConnection(connection, Operation.Connect, connectDetails));
        }
        // audit and relationships added/removed
        Collection<Relationship> newRelationships = connection.getRelationships();
        // identify any relationships that were added
        if (newRelationships != null) {
            List<Relationship> relationshipsToAdd = new ArrayList<>(newRelationships);
            if (previousRelationships != null) {
                relationshipsToAdd.removeAll(previousRelationships);
            }
            if (!relationshipsToAdd.isEmpty()) {
                final ConnectDetails connectDetails = createConnectDetails(connection, relationshipsToAdd);
                actions.add(generateAuditRecordForConnection(connection, Operation.Connect, connectDetails));
            }
        }
        // identify any relationships that were removed
        if (previousRelationships != null) {
            List<Relationship> relationshipsToRemove = new ArrayList<>(previousRelationships);
            if (newRelationships != null) {
                relationshipsToRemove.removeAll(newRelationships);
            }
            if (!relationshipsToRemove.isEmpty()) {
                final ConnectDetails connectDetails = createConnectDetails(connection, relationshipsToRemove);
                actions.add(generateAuditRecordForConnection(connection, Operation.Disconnect, connectDetails));
            }
        }
        // go through each updated value
        Date actionTimestamp = new Date();
        for (String property : updatedValues.keySet()) {
            String newValue = updatedValues.get(property);
            String oldValue = values.get(property);
            // ensure the value is changing
            if (oldValue == null || newValue == null || !newValue.equals(oldValue)) {
                // create the config details
                FlowChangeConfigureDetails configurationDetails = new FlowChangeConfigureDetails();
                configurationDetails.setName(property);
                configurationDetails.setValue(newValue);
                configurationDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(user.getIdentity());
                configurationAction.setOperation(Operation.Configure);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(connection.getIdentifier());
                configurationAction.setSourceName(connection.getName());
                configurationAction.setSourceType(Component.Connection);
                configurationAction.setActionDetails(configurationDetails);
                actions.add(configurationAction);
            }
        }
        // save the actions
        if (!actions.isEmpty()) {
            saveActions(actions, logger);
        }
    }
    return connection;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) Date(java.util.Date) Connectable(org.apache.nifi.connectable.Connectable) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) Relationship(org.apache.nifi.processor.Relationship) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 4 with ConnectDetails

use of org.apache.nifi.action.details.ConnectDetails in project nifi by apache.

the class SnippetAuditor method removeSnippetAdvice.

/**
 * Audits bulk delete.
 *
 * @param proceedingJoinPoint join point
 * @param snippetId snippet id
 * @param snippetDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && " + "execution(void deleteSnippetComponents(java.lang.String)) && " + "args(snippetId) && " + "target(snippetDAO)")
public void removeSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, String snippetId, SnippetDAO snippetDAO) throws Throwable {
    // get the snippet before removing it
    final Snippet snippet = snippetDAO.getSnippet(snippetId);
    // locate all the components being removed
    final Set<Funnel> funnels = new HashSet<>();
    for (String id : snippet.getFunnels().keySet()) {
        funnels.add(funnelDAO.getFunnel(id));
    }
    final Set<Port> inputPorts = new HashSet<>();
    for (String id : snippet.getInputPorts().keySet()) {
        inputPorts.add(inputPortDAO.getPort(id));
    }
    final Set<Port> outputPorts = new HashSet<>();
    for (String id : snippet.getOutputPorts().keySet()) {
        outputPorts.add(outputPortDAO.getPort(id));
    }
    final Set<RemoteProcessGroup> remoteProcessGroups = new HashSet<>();
    for (String id : snippet.getRemoteProcessGroups().keySet()) {
        remoteProcessGroups.add(remoteProcessGroupDAO.getRemoteProcessGroup(id));
    }
    final Set<ProcessGroup> processGroups = new HashSet<>();
    final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    for (String id : snippet.getProcessGroups().keySet()) {
        processGroups.add(processGroupDAO.getProcessGroup(id));
    }
    final Set<ProcessorNode> processors = new HashSet<>();
    for (String id : snippet.getProcessors().keySet()) {
        processors.add(processorDAO.getProcessor(id));
    }
    final Set<Connection> connections = new HashSet<>();
    for (String id : snippet.getConnections().keySet()) {
        connections.add(connectionDAO.getConnection(id));
    }
    // remove the snippet and components
    proceedingJoinPoint.proceed();
    final Collection<Action> actions = new ArrayList<>();
    // audit funnel removal
    for (Funnel funnel : funnels) {
        final Action action = funnelAuditor.generateAuditRecord(funnel, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Port inputPort : inputPorts) {
        final Action action = portAuditor.generateAuditRecord(inputPort, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Port outputPort : outputPorts) {
        final Action action = portAuditor.generateAuditRecord(outputPort, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (RemoteProcessGroup remoteProcessGroup : remoteProcessGroups) {
        final Action action = remoteProcessGroupAuditor.generateAuditRecord(remoteProcessGroup, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (ProcessGroup processGroup : processGroups) {
        final Action action = processGroupAuditor.generateAuditRecord(processGroup, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (ProcessorNode processor : processors) {
        final Action action = processorAuditor.generateAuditRecord(processor, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Connection connection : connections) {
        final ConnectDetails connectDetails = relationshipAuditor.createConnectDetails(connection, connection.getRelationships());
        final Action action = relationshipAuditor.generateAuditRecordForConnection(connection, Operation.Disconnect, connectDetails);
        if (action != null) {
            actions.add(action);
        }
    }
    // save the actions
    if (CollectionUtils.isNotEmpty(actions)) {
        saveActions(actions, logger);
    }
}
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) Port(org.apache.nifi.connectable.Port) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) Snippet(org.apache.nifi.controller.Snippet) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) HashSet(java.util.HashSet) Around(org.aspectj.lang.annotation.Around)

Example 5 with ConnectDetails

use of org.apache.nifi.action.details.ConnectDetails in project nifi by apache.

the class DtoFactory method createActionDetailsDto.

/**
 * Creates an ActionDetailsDTO for the specified ActionDetails.
 *
 * @param actionDetails details
 * @return dto
 */
private ActionDetailsDTO createActionDetailsDto(final ActionDetails actionDetails) {
    if (actionDetails == null) {
        return null;
    }
    if (actionDetails instanceof FlowChangeConfigureDetails) {
        final ConfigureDetailsDTO configureDetails = new ConfigureDetailsDTO();
        configureDetails.setName(((ConfigureDetails) actionDetails).getName());
        configureDetails.setPreviousValue(((ConfigureDetails) actionDetails).getPreviousValue());
        configureDetails.setValue(((ConfigureDetails) actionDetails).getValue());
        return configureDetails;
    } else if (actionDetails instanceof FlowChangeConnectDetails) {
        final ConnectDetailsDTO connectDetails = new ConnectDetailsDTO();
        connectDetails.setSourceId(((ConnectDetails) actionDetails).getSourceId());
        connectDetails.setSourceName(((ConnectDetails) actionDetails).getSourceName());
        connectDetails.setSourceType(((ConnectDetails) actionDetails).getSourceType().toString());
        connectDetails.setRelationship(((ConnectDetails) actionDetails).getRelationship());
        connectDetails.setDestinationId(((ConnectDetails) actionDetails).getDestinationId());
        connectDetails.setDestinationName(((ConnectDetails) actionDetails).getDestinationName());
        connectDetails.setDestinationType(((ConnectDetails) actionDetails).getDestinationType().toString());
        return connectDetails;
    } else if (actionDetails instanceof FlowChangeMoveDetails) {
        final MoveDetailsDTO moveDetails = new MoveDetailsDTO();
        moveDetails.setPreviousGroup(((MoveDetails) actionDetails).getPreviousGroup());
        moveDetails.setPreviousGroupId(((MoveDetails) actionDetails).getPreviousGroupId());
        moveDetails.setGroup(((MoveDetails) actionDetails).getGroup());
        moveDetails.setGroupId(((MoveDetails) actionDetails).getGroupId());
        return moveDetails;
    } else if (actionDetails instanceof FlowChangePurgeDetails) {
        final PurgeDetailsDTO purgeDetails = new PurgeDetailsDTO();
        purgeDetails.setEndDate(((PurgeDetails) actionDetails).getEndDate());
        return purgeDetails;
    } else {
        throw new WebApplicationException(new IllegalArgumentException(String.format("Unrecognized type of action details encountered %s during serialization.", actionDetails.toString())));
    }
}
Also used : FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ConfigureDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConfigureDetailsDTO) MoveDetailsDTO(org.apache.nifi.web.api.dto.action.details.MoveDetailsDTO) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) WebApplicationException(javax.ws.rs.WebApplicationException) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) PurgeDetailsDTO(org.apache.nifi.web.api.dto.action.details.PurgeDetailsDTO) ConnectDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConnectDetailsDTO)

Aggregations

ConnectDetails (org.apache.nifi.action.details.ConnectDetails)5 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)5 Action (org.apache.nifi.action.Action)4 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)4 Connection (org.apache.nifi.connectable.Connection)4 Around (org.aspectj.lang.annotation.Around)4 ArrayList (java.util.ArrayList)2 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 FlowChangeMoveDetails (org.apache.nifi.action.details.FlowChangeMoveDetails)1 FlowChangePurgeDetails (org.apache.nifi.action.details.FlowChangePurgeDetails)1 PurgeDetails (org.apache.nifi.action.details.PurgeDetails)1 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)1 Connectable (org.apache.nifi.connectable.Connectable)1 Funnel (org.apache.nifi.connectable.Funnel)1 Port (org.apache.nifi.connectable.Port)1 ProcessorNode (org.apache.nifi.controller.ProcessorNode)1 Snippet (org.apache.nifi.controller.Snippet)1