Search in sources :

Example 1 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.

the class DtoFactory method createComponentDetailsDto.

/**
 * Creates a ComponentDetailsDTO for the specified ComponentDetails.
 *
 * @param componentDetails details
 * @return dto
 */
private ComponentDetailsDTO createComponentDetailsDto(final ComponentDetails componentDetails) {
    if (componentDetails == null) {
        return null;
    }
    if (componentDetails instanceof FlowChangeExtensionDetails) {
        final ExtensionDetailsDTO processorDetails = new ExtensionDetailsDTO();
        processorDetails.setType(((ExtensionDetails) componentDetails).getType());
        return processorDetails;
    } else if (componentDetails instanceof FlowChangeRemoteProcessGroupDetails) {
        final RemoteProcessGroupDetailsDTO remoteProcessGroupDetails = new RemoteProcessGroupDetailsDTO();
        remoteProcessGroupDetails.setUri(((RemoteProcessGroupDetails) componentDetails).getUri());
        return remoteProcessGroupDetails;
    } else {
        throw new WebApplicationException(new IllegalArgumentException(String.format("Unrecognized type of component details encountered %s during serialization. ", componentDetails.toString())));
    }
}
Also used : RemoteProcessGroupDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.RemoteProcessGroupDetailsDTO) RemoteProcessGroupDetails(org.apache.nifi.action.component.details.RemoteProcessGroupDetails) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) WebApplicationException(javax.ws.rs.WebApplicationException) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) ExtensionDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.ExtensionDetailsDTO)

Example 2 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.

the class ControllerServiceAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of a controller service.
 *
 * @param controllerService service
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
private Action generateAuditRecord(ControllerServiceNode controllerService, Operation operation, ActionDetails actionDetails) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // create the controller service details
        FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails();
        serviceDetails.setType(controllerService.getComponentType());
        // create the controller service action for adding this controller service
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(controllerService.getIdentifier());
        action.setSourceName(controllerService.getName());
        action.setSourceType(Component.ControllerService);
        action.setComponentDetails(serviceDetails);
        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 3 with FlowChangeExtensionDetails

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

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.

the class ProcessorAuditor method updateProcessorAdvice.

/**
 * Audits the configuration of a single processor.
 *
 * @param proceedingJoinPoint join point
 * @param processorDTO dto
 * @param processorDAO dao
 * @return node
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessorDAO+) && " + "execution(org.apache.nifi.controller.ProcessorNode updateProcessor(org.apache.nifi.web.api.dto.ProcessorDTO)) && " + "args(processorDTO) && " + "target(processorDAO)")
public ProcessorNode updateProcessorAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessorDTO processorDTO, ProcessorDAO processorDAO) throws Throwable {
    // determine the initial values for each property/setting that's changing
    ProcessorNode processor = processorDAO.getProcessor(processorDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(processor, processorDTO);
    final ScheduledState scheduledState = processor.getScheduledState();
    // update the processor state
    final ProcessorNode updatedProcessor = (ProcessorNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the processor action...
    processor = processorDAO.getProcessor(updatedProcessor.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(processor, processorDTO);
        // create the processor details
        FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(processor.getComponentType());
        // create a processor 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 = processor.getProcessor().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(processor.getIdentifier());
                configurationAction.setSourceName(processor.getName());
                configurationAction.setSourceType(Component.Processor);
                configurationAction.setComponentDetails(processorDetails);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // determine the new executing state
        final ScheduledState updatedScheduledState = processor.getScheduledState();
        // determine if the running state has changed and its not disabled
        if (scheduledState != updatedScheduledState) {
            // create a processor action
            FlowChangeAction processorAction = new FlowChangeAction();
            processorAction.setUserIdentity(user.getIdentity());
            processorAction.setTimestamp(new Date());
            processorAction.setSourceId(processor.getIdentifier());
            processorAction.setSourceName(processor.getName());
            processorAction.setSourceType(Component.Processor);
            processorAction.setComponentDetails(processorDetails);
            // set the operation accordingly
            if (ScheduledState.RUNNING.equals(updatedScheduledState)) {
                processorAction.setOperation(Operation.Start);
            } else if (ScheduledState.DISABLED.equals(updatedScheduledState)) {
                processorAction.setOperation(Operation.Disable);
            } else {
                // state is now stopped... consider the previous state
                if (ScheduledState.RUNNING.equals(scheduledState)) {
                    processorAction.setOperation(Operation.Stop);
                } else if (ScheduledState.DISABLED.equals(scheduledState)) {
                    processorAction.setOperation(Operation.Enable);
                }
            }
            actions.add(processorAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedProcessor;
}
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) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ScheduledState(org.apache.nifi.controller.ScheduledState) 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 5 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.

the class ProcessorAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of a processor.
 *
 * @param processor processor
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
public Action generateAuditRecord(ProcessorNode processor, Operation operation, ActionDetails actionDetails) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // create the processor details
        FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(processor.getComponentType());
        // create the processor action for adding this processor
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(processor.getIdentifier());
        action.setSourceName(processor.getName());
        action.setSourceType(Component.Processor);
        action.setComponentDetails(processorDetails);
        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Aggregations

FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)15 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)13 Date (java.util.Date)12 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)9 Action (org.apache.nifi.action.Action)8 ArrayList (java.util.ArrayList)7 Around (org.aspectj.lang.annotation.Around)6 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)5 Operation (org.apache.nifi.action.Operation)3 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3 StateMap (org.apache.nifi.components.state.StateMap)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 RemoteProcessGroupDetails (org.apache.nifi.action.component.details.RemoteProcessGroupDetails)2 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)2 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)2 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)2