Search in sources :

Example 1 with Operation

use of org.apache.nifi.action.Operation in project nifi by apache.

the class ControllerServiceAuditor method updateControllerServiceAdvice.

/**
 * Audits the configuration of a single controller service.
 *
 * @param proceedingJoinPoint join point
 * @param controllerServiceDTO dto
 * @param controllerServiceDAO dao
 * @return object
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && " + "execution(org.apache.nifi.controller.service.ControllerServiceNode updateControllerService(org.apache.nifi.web.api.dto.ControllerServiceDTO)) && " + "args(controllerServiceDTO) && " + "target(controllerServiceDAO)")
public Object updateControllerServiceAdvice(ProceedingJoinPoint proceedingJoinPoint, ControllerServiceDTO controllerServiceDTO, ControllerServiceDAO controllerServiceDAO) throws Throwable {
    // determine the initial values for each property/setting that's changing
    ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(controllerService, controllerServiceDTO);
    final boolean isDisabled = isDisabled(controllerService);
    // update the controller service state
    final ControllerServiceNode updatedControllerService = (ControllerServiceNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the controller service action...
    controllerService = controllerServiceDAO.getControllerService(updatedControllerService.getIdentifier());
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(controllerService, controllerServiceDTO);
        // create the controller service details
        FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails();
        serviceDetails.setType(controllerService.getComponentType());
        // create a controller service action
        Date actionTimestamp = new Date();
        Collection<Action> actions = new ArrayList<>();
        // go through each updated value
        for (String property : updatedValues.keySet()) {
            String newValue = updatedValues.get(property);
            String oldValue = values.get(property);
            Operation operation = null;
            // determine the type of operation
            if (oldValue == null || newValue == null || !newValue.equals(oldValue)) {
                operation = Operation.Configure;
            }
            // create a configuration action accordingly
            if (operation != null) {
                // clear the value if this property is sensitive
                final PropertyDescriptor propertyDescriptor = controllerService.getControllerServiceImplementation().getPropertyDescriptor(property);
                if (propertyDescriptor != null && propertyDescriptor.isSensitive()) {
                    if (newValue != null) {
                        newValue = "********";
                    }
                    if (oldValue != null) {
                        oldValue = "********";
                    }
                } else if (ANNOTATION_DATA.equals(property)) {
                    if (newValue != null) {
                        newValue = "<annotation data not shown>";
                    }
                    if (oldValue != null) {
                        oldValue = "<annotation data not shown>";
                    }
                }
                final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
                actionDetails.setName(property);
                actionDetails.setValue(newValue);
                actionDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(user.getIdentity());
                configurationAction.setOperation(operation);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(controllerService.getIdentifier());
                configurationAction.setSourceName(controllerService.getName());
                configurationAction.setSourceType(Component.ControllerService);
                configurationAction.setComponentDetails(serviceDetails);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // determine the new executing state
        final boolean updateIsDisabled = isDisabled(updatedControllerService);
        // determine if the running state has changed and its not disabled
        if (isDisabled != updateIsDisabled) {
            // create a controller service action
            FlowChangeAction serviceAction = new FlowChangeAction();
            serviceAction.setUserIdentity(user.getIdentity());
            serviceAction.setTimestamp(new Date());
            serviceAction.setSourceId(controllerService.getIdentifier());
            serviceAction.setSourceName(controllerService.getName());
            serviceAction.setSourceType(Component.ControllerService);
            serviceAction.setComponentDetails(serviceDetails);
            // set the operation accordingly
            if (updateIsDisabled) {
                serviceAction.setOperation(Operation.Disable);
            } else {
                serviceAction.setOperation(Operation.Enable);
            }
            actions.add(serviceAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedControllerService;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 2 with Operation

use of org.apache.nifi.action.Operation in project nifi by apache.

the class ProcessGroupAuditor method scheduleComponentsAdvice.

/**
 * Audits the update of process group configuration.
 *
 * @param proceedingJoinPoint join point
 * @param groupId group id
 * @param state scheduled state
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(java.util.concurrent.Future<Void> scheduleComponents(java.lang.String, org.apache.nifi.controller.ScheduledState, java.util.Set)) && " + "args(groupId, state)")
public Future<Void> scheduleComponentsAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ScheduledState state) throws Throwable {
    final Operation operation;
    final Future<Void> result = (Future<Void>) proceedingJoinPoint.proceed();
    // determine the running state
    if (ScheduledState.RUNNING.equals(state)) {
        operation = Operation.Start;
    } else {
        operation = Operation.Stop;
    }
    saveUpdateAction(NiFiUserUtils.getNiFiUser(), groupId, operation);
    return result;
}
Also used : Future(java.util.concurrent.Future) Operation(org.apache.nifi.action.Operation) Around(org.aspectj.lang.annotation.Around)

Example 3 with Operation

use of org.apache.nifi.action.Operation 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 4 with Operation

use of org.apache.nifi.action.Operation in project nifi by apache.

the class ProcessGroupAuditor method activateControllerServicesAdvice.

/**
 * Audits the update of controller serivce state
 *
 * @param proceedingJoinPoint join point
 * @param groupId group id
 * @param state controller service state
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(java.util.concurrent.Future<Void> activateControllerServices(java.lang.String, org.apache.nifi.controller.service.ControllerServiceState, java.util.Set)) && " + "args(groupId, state)")
public Future<Void> activateControllerServicesAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ControllerServiceState state) throws Throwable {
    final Operation operation;
    final Future<Void> result = (Future<Void>) proceedingJoinPoint.proceed();
    // determine the service state
    if (ControllerServiceState.ENABLED.equals(state)) {
        operation = Operation.Enable;
    } else {
        operation = Operation.Disable;
    }
    saveUpdateAction(NiFiUserUtils.getNiFiUser(), groupId, operation);
    return result;
}
Also used : Future(java.util.concurrent.Future) Operation(org.apache.nifi.action.Operation) Around(org.aspectj.lang.annotation.Around)

Example 5 with Operation

use of org.apache.nifi.action.Operation 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)

Aggregations

Operation (org.apache.nifi.action.Operation)13 Around (org.aspectj.lang.annotation.Around)11 Date (java.util.Date)9 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)9 ArrayList (java.util.ArrayList)8 Action (org.apache.nifi.action.Action)8 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)8 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)7 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)3 ActionDetails (org.apache.nifi.action.details.ActionDetails)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3 ProcessGroup (org.apache.nifi.groups.ProcessGroup)3 ProcessGroupDAO (org.apache.nifi.web.dao.ProcessGroupDAO)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Future (java.util.concurrent.Future)2 Component (org.apache.nifi.action.Component)2 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)2 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)2