Search in sources :

Example 1 with ProcessGroupDAO

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

the class ProcessGroupAuditor method updateVersionControlInformationAdvice.

@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateVersionControlInformation(..))")
public ProcessGroup updateVersionControlInformationAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    final VersionControlInformationDTO vciDto = (VersionControlInformationDTO) proceedingJoinPoint.getArgs()[0];
    final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    final ProcessGroup processGroup = processGroupDAO.getProcessGroup(vciDto.getGroupId());
    final VersionControlInformation vci = processGroup.getVersionControlInformation();
    final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    final Operation operation;
    if (vci == null) {
        operation = Operation.StartVersionControl;
    } else {
        operation = Operation.CommitLocalChanges;
    }
    saveUpdateAction(NiFiUserUtils.getNiFiUser(), vciDto.getGroupId(), operation);
    return updatedProcessGroup;
}
Also used : ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Operation(org.apache.nifi.action.Operation) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) Around(org.aspectj.lang.annotation.Around)

Example 2 with ProcessGroupDAO

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

the class ProcessGroupAuditor method saveUpdateAction.

private void saveUpdateAction(final NiFiUser user, final String groupId, final Operation operation) throws Throwable {
    ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    // if the user was starting/stopping this process group
    FlowChangeAction action = new FlowChangeAction();
    action.setUserIdentity(user.getIdentity());
    action.setSourceId(processGroup.getIdentifier());
    action.setSourceName(processGroup.getName());
    action.setSourceType(Component.ProcessGroup);
    action.setTimestamp(new Date());
    action.setOperation(operation);
    // add this action
    saveAction(action, logger);
}
Also used : ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 3 with ProcessGroupDAO

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

the class ProcessGroupAuditor method updateProcessGroupAdvice.

/**
 * Audits the update of process group configuration.
 *
 * @param proceedingJoinPoint join point
 * @param processGroupDTO dto
 * @return group
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroup(org.apache.nifi.web.api.dto.ProcessGroupDTO)) && " + "args(processGroupDTO)")
public ProcessGroup updateProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessGroupDTO processGroupDTO) throws Throwable {
    ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    ProcessGroup processGroup = processGroupDAO.getProcessGroup(processGroupDTO.getId());
    String name = processGroup.getName();
    String comments = processGroup.getComments();
    // perform the underlying operation
    ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<ActionDetails> details = new ArrayList<>();
        // see if the name has changed
        if (name != null && updatedProcessGroup.getName() != null && !name.equals(updatedProcessGroup.getName())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("name");
            configDetails.setValue(updatedProcessGroup.getName());
            configDetails.setPreviousValue(name);
            details.add(configDetails);
        }
        // see if the comments has changed
        if (comments != null && updatedProcessGroup.getComments() != null && !comments.equals(updatedProcessGroup.getComments())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("comments");
            configDetails.setValue(updatedProcessGroup.getComments());
            configDetails.setPreviousValue(comments);
            details.add(configDetails);
        }
        // hold all actions
        Collection<Action> actions = new ArrayList<>();
        // save the actions if necessary
        if (!details.isEmpty()) {
            Date timestamp = new Date();
            // create the actions
            for (ActionDetails detail : details) {
                // determine the type of operation being performed
                Operation operation = Operation.Configure;
                if (detail instanceof FlowChangeMoveDetails) {
                    operation = Operation.Move;
                }
                // create the port action for updating the name
                FlowChangeAction processGroupAction = new FlowChangeAction();
                processGroupAction.setUserIdentity(user.getIdentity());
                processGroupAction.setOperation(operation);
                processGroupAction.setTimestamp(timestamp);
                processGroupAction.setSourceId(updatedProcessGroup.getIdentifier());
                processGroupAction.setSourceName(updatedProcessGroup.getName());
                processGroupAction.setSourceType(Component.ProcessGroup);
                processGroupAction.setActionDetails(detail);
                actions.add(processGroupAction);
            }
        }
        // save actions if necessary
        if (!actions.isEmpty()) {
            saveActions(actions, logger);
        }
    }
    return updatedProcessGroup;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ActionDetails(org.apache.nifi.action.details.ActionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 4 with ProcessGroupDAO

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

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

the class ProcessGroupAuditor method updateProcessGroupFlowAdvice.

@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroupFlow(..))")
public ProcessGroup updateProcessGroupFlowAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    final Object[] args = proceedingJoinPoint.getArgs();
    final String groupId = (String) args[0];
    final NiFiUser user = (NiFiUser) args[1];
    final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    final VersionControlInformation vci = processGroup.getVersionControlInformation();
    final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    final VersionControlInformation updatedVci = updatedProcessGroup.getVersionControlInformation();
    final Operation operation;
    if (vci == null) {
        operation = Operation.StartVersionControl;
    } else {
        if (updatedVci == null) {
            operation = Operation.StopVersionControl;
        } else if (vci.getVersion() == updatedVci.getVersion()) {
            operation = Operation.RevertLocalChanges;
        } else {
            operation = Operation.ChangeVersion;
        }
    }
    saveUpdateAction(user, groupId, operation);
    return updatedProcessGroup;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Operation(org.apache.nifi.action.Operation) 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