Search in sources :

Example 6 with ProcessGroupDAO

use of org.apache.nifi.web.dao.ProcessGroupDAO in project nifi by apache.

the class ProcessGroupAuditor method removeProcessGroupAdvice.

/**
 * Audits the removal of a process group via deleteProcessGroup().
 *
 * @param proceedingJoinPoint join point
 * @param groupId group id
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(void deleteProcessGroup(java.lang.String)) && " + "args(groupId)")
public void removeProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId) throws Throwable {
    // get the process group before removing it
    ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    // remove the process group
    proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    // audit the process group removal
    final Action action = generateAuditRecord(processGroup, Operation.Remove);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Around(org.aspectj.lang.annotation.Around)

Example 7 with ProcessGroupDAO

use of org.apache.nifi.web.dao.ProcessGroupDAO 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)

Aggregations

ProcessGroup (org.apache.nifi.groups.ProcessGroup)7 ProcessGroupDAO (org.apache.nifi.web.dao.ProcessGroupDAO)7 Around (org.aspectj.lang.annotation.Around)6 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)5 Action (org.apache.nifi.action.Action)4 ArrayList (java.util.ArrayList)3 Operation (org.apache.nifi.action.Operation)3 Date (java.util.Date)2 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)2 Connection (org.apache.nifi.connectable.Connection)2 Funnel (org.apache.nifi.connectable.Funnel)2 Port (org.apache.nifi.connectable.Port)2 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 Snippet (org.apache.nifi.controller.Snippet)2 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)2 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)2 RemoteProcessGroupDAO (org.apache.nifi.web.dao.RemoteProcessGroupDAO)2 HashSet (java.util.HashSet)1 ActionDetails (org.apache.nifi.action.details.ActionDetails)1 ConnectDetails (org.apache.nifi.action.details.ConnectDetails)1