Search in sources :

Example 1 with FlowChangeRemoteProcessGroupDetails

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

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

the class RemoteProcessGroupAuditor method generateAuditRecord.

/**
 * Generates an audit record for the specified remote process group.
 *
 * @param remoteProcessGroup group
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
public Action generateAuditRecord(RemoteProcessGroup remoteProcessGroup, 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 remote process group details
        FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = createFlowChangeDetails(remoteProcessGroup);
        // create the remote process group action
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(remoteProcessGroup.getIdentifier());
        action.setSourceName(remoteProcessGroup.getName());
        action.setSourceType(Component.RemoteProcessGroup);
        action.setComponentDetails(remoteProcessGroupDetails);
        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 3 with FlowChangeRemoteProcessGroupDetails

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

the class RemoteProcessGroupAuditor method auditUpdateProcessGroupConfiguration.

/**
 * Audits the update of remote process group configuration.
 *
 * @param proceedingJoinPoint   join point
 * @param remoteProcessGroupDTO dto
 * @param remoteProcessGroupDAO dao
 * @return group
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.RemoteProcessGroup updateRemoteProcessGroup(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)) && " + "args(remoteProcessGroupDTO) && " + "target(remoteProcessGroupDAO)")
public RemoteProcessGroup auditUpdateProcessGroupConfiguration(ProceedingJoinPoint proceedingJoinPoint, RemoteProcessGroupDTO remoteProcessGroupDTO, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {
    final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
    // record the current value of this remoteProcessGroups configuration for comparisons later
    final boolean transmissionState = remoteProcessGroup.isTransmitting();
    final Map<String, Object> previousValues = ConfigurationRecorder.capturePreviousValues(CONFIG_RECORDERS, remoteProcessGroup);
    // perform the underlying operation
    final RemoteProcessGroup updatedRemoteProcessGroup = (RemoteProcessGroup) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        final Collection<ActionDetails> details = new ArrayList<>();
        // see if any property has changed
        ConfigurationRecorder.checkConfigured(CONFIG_RECORDERS, remoteProcessGroupDTO, updatedRemoteProcessGroup, previousValues, details);
        final Date timestamp = new Date();
        final Collection<Action> actions = new ArrayList<>();
        // create the remote process group details
        final FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = createFlowChangeDetails(remoteProcessGroup);
        // save the actions if necessary
        if (!details.isEmpty()) {
            // create the actions
            for (ActionDetails detail : details) {
                // create a configure action for each updated property
                FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, updatedRemoteProcessGroup, remoteProcessGroupDetails);
                remoteProcessGroupAction.setOperation(Operation.Configure);
                remoteProcessGroupAction.setActionDetails(detail);
                actions.add(remoteProcessGroupAction);
            }
        }
        // determine the new executing state
        boolean updatedTransmissionState = updatedRemoteProcessGroup.isTransmitting();
        // determine if the running state has changed
        if (transmissionState != updatedTransmissionState) {
            // create a remote process group action
            FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, updatedRemoteProcessGroup, remoteProcessGroupDetails);
            // set the operation accordingly
            if (updatedTransmissionState) {
                remoteProcessGroupAction.setOperation(Operation.Start);
            } else {
                remoteProcessGroupAction.setOperation(Operation.Stop);
            }
            actions.add(remoteProcessGroupAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedRemoteProcessGroup;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ArrayList(java.util.ArrayList) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) Date(java.util.Date) ActionDetails(org.apache.nifi.action.details.ActionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 4 with FlowChangeRemoteProcessGroupDetails

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

the class RemoteProcessGroupAuditor method createFlowChangeDetails.

private FlowChangeRemoteProcessGroupDetails createFlowChangeDetails(RemoteProcessGroup remoteProcessGroup) {
    FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
    remoteProcessGroupDetails.setUri(remoteProcessGroup.getTargetUri());
    return remoteProcessGroupDetails;
}
Also used : FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)

Example 5 with FlowChangeRemoteProcessGroupDetails

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

the class StandardActionDAO method createAction.

@Override
public Action createAction(Action action) throws DataAccessException {
    if (action.getUserIdentity() == null) {
        throw new IllegalArgumentException("User cannot be null.");
    }
    if (action.getTimestamp() == null) {
        throw new IllegalArgumentException("Action timestamp cannot be null.");
    }
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // obtain a statement to insert to the action table
        statement = connection.prepareStatement(INSERT_ACTION, Statement.RETURN_GENERATED_KEYS);
        statement.setString(1, StringUtils.left(action.getUserIdentity(), 4096));
        statement.setString(2, action.getSourceId());
        statement.setString(3, StringUtils.left(action.getSourceName(), 1000));
        statement.setString(4, action.getSourceType().name());
        statement.setString(5, action.getOperation().name());
        statement.setTimestamp(6, new java.sql.Timestamp(action.getTimestamp().getTime()));
        // insert the action
        int updateCount = statement.executeUpdate();
        final FlowChangeAction createdAction = new FlowChangeAction();
        createdAction.setUserIdentity(action.getUserIdentity());
        createdAction.setSourceId(action.getSourceId());
        createdAction.setSourceName(action.getSourceName());
        createdAction.setSourceType(action.getSourceType());
        createdAction.setOperation(action.getOperation());
        createdAction.setTimestamp(action.getTimestamp());
        createdAction.setActionDetails(action.getActionDetails());
        createdAction.setComponentDetails(action.getComponentDetails());
        // get the action id
        rs = statement.getGeneratedKeys();
        if (updateCount == 1 && rs.next()) {
            createdAction.setId(rs.getInt(1));
        } else {
            throw new DataAccessException("Unable to insert action.");
        }
        // close the previous statement
        statement.close();
        // determine the type of component
        ComponentDetails componentDetails = createdAction.getComponentDetails();
        if (componentDetails instanceof FlowChangeExtensionDetails) {
            createExtensionDetails(createdAction.getId(), (ExtensionDetails) componentDetails);
        } else if (componentDetails instanceof FlowChangeRemoteProcessGroupDetails) {
            createRemoteProcessGroupDetails(createdAction.getId(), (RemoteProcessGroupDetails) componentDetails);
        }
        // determine the type of action
        ActionDetails details = createdAction.getActionDetails();
        if (details instanceof FlowChangeConnectDetails) {
            createConnectDetails(createdAction.getId(), (ConnectDetails) details);
        } else if (details instanceof FlowChangeMoveDetails) {
            createMoveDetails(createdAction.getId(), (MoveDetails) details);
        } else if (details instanceof FlowChangeConfigureDetails) {
            createConfigureDetails(createdAction.getId(), (ConfigureDetails) details);
        } else if (details instanceof FlowChangePurgeDetails) {
            createPurgeDetails(createdAction.getId(), (PurgeDetails) details);
        }
        return createdAction;
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) MoveDetails(org.apache.nifi.action.details.MoveDetails) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) SQLException(java.sql.SQLException) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) PreparedStatement(java.sql.PreparedStatement) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) RemoteProcessGroupDetails(org.apache.nifi.action.component.details.RemoteProcessGroupDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ResultSet(java.sql.ResultSet) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) ActionDetails(org.apache.nifi.action.details.ActionDetails) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Aggregations

FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)8 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)5 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 Action (org.apache.nifi.action.Action)3 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)3 ActionDetails (org.apache.nifi.action.details.ActionDetails)3 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)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 WebApplicationException (javax.ws.rs.WebApplicationException)1 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)1 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)1 FlowChangeMoveDetails (org.apache.nifi.action.details.FlowChangeMoveDetails)1 FlowChangePurgeDetails (org.apache.nifi.action.details.FlowChangePurgeDetails)1 MoveDetails (org.apache.nifi.action.details.MoveDetails)1