Search in sources :

Example 1 with FlowChangeConnectDetails

use of org.apache.nifi.action.details.FlowChangeConnectDetails in project nifi by apache.

the class RelationshipAuditor method createConnectDetails.

/**
 * Creates action details for connect/disconnect actions.
 *
 * @param connection connection
 * @param source source
 * @param relationships relationships
 * @param destination destinations
 * @return details
 */
public ConnectDetails createConnectDetails(final Connection connection, final Connectable source, final Collection<Relationship> relationships, final Connectable destination) {
    final Component sourceType = determineConnectableType(source);
    final Component destiantionType = determineConnectableType(destination);
    // format the relationship names
    Collection<String> relationshipNames = new HashSet<>(connection.getRelationships().size());
    for (final Relationship relationship : relationships) {
        relationshipNames.add(relationship.getName());
    }
    final String formattedRelationships = relationshipNames.isEmpty() ? StringUtils.EMPTY : StringUtils.join(relationshipNames, ", ");
    // create the connect details
    final FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
    connectDetails.setSourceId(source.getIdentifier());
    connectDetails.setSourceName(source.getName());
    connectDetails.setSourceType(sourceType);
    connectDetails.setRelationship(formattedRelationships);
    connectDetails.setDestinationId(destination.getIdentifier());
    connectDetails.setDestinationName(destination.getName());
    connectDetails.setDestinationType(destiantionType);
    return connectDetails;
}
Also used : FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Relationship(org.apache.nifi.processor.Relationship) Component(org.apache.nifi.action.Component) HashSet(java.util.HashSet)

Example 2 with FlowChangeConnectDetails

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

Example 3 with FlowChangeConnectDetails

use of org.apache.nifi.action.details.FlowChangeConnectDetails in project nifi by apache.

the class SnippetAuditor method auditSnippet.

/**
 * Audits the specified snippet.
 */
private void auditSnippet(final FlowSnippetDTO snippet) {
    final Collection<Action> actions = new ArrayList<>();
    final Date timestamp = new Date();
    // input ports
    for (final PortDTO inputPort : snippet.getInputPorts()) {
        actions.add(generateAuditRecord(inputPort.getId(), inputPort.getName(), Component.InputPort, Operation.Add, timestamp));
    }
    // output ports
    for (final PortDTO outputPort : snippet.getOutputPorts()) {
        actions.add(generateAuditRecord(outputPort.getId(), outputPort.getName(), Component.OutputPort, Operation.Add, timestamp));
    }
    // remote processor groups
    for (final RemoteProcessGroupDTO remoteProcessGroup : snippet.getRemoteProcessGroups()) {
        FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
        remoteProcessGroupDetails.setUri(remoteProcessGroup.getTargetUri());
        final FlowChangeAction action = generateAuditRecord(remoteProcessGroup.getId(), remoteProcessGroup.getName(), Component.RemoteProcessGroup, Operation.Add, timestamp);
        action.setComponentDetails(remoteProcessGroupDetails);
        actions.add(action);
    }
    // processor groups
    for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
        actions.add(generateAuditRecord(processGroup.getId(), processGroup.getName(), Component.ProcessGroup, Operation.Add, timestamp));
    }
    // processors
    for (final ProcessorDTO processor : snippet.getProcessors()) {
        final FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(StringUtils.substringAfterLast(processor.getType(), "."));
        final FlowChangeAction action = generateAuditRecord(processor.getId(), processor.getName(), Component.Processor, Operation.Add, timestamp);
        action.setComponentDetails(processorDetails);
        actions.add(action);
    }
    // funnels
    for (final FunnelDTO funnel : snippet.getFunnels()) {
        actions.add(generateAuditRecord(funnel.getId(), StringUtils.EMPTY, Component.Funnel, Operation.Add, timestamp));
    }
    // connections
    for (final ConnectionDTO connection : snippet.getConnections()) {
        final ConnectableDTO source = connection.getSource();
        final ConnectableDTO destination = connection.getDestination();
        // determine the relationships and connection name
        final String relationships = CollectionUtils.isEmpty(connection.getSelectedRelationships()) ? StringUtils.EMPTY : StringUtils.join(connection.getSelectedRelationships(), ", ");
        final String name = StringUtils.isBlank(connection.getName()) ? relationships : connection.getName();
        // create the connect details
        FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
        connectDetails.setSourceId(source.getId());
        connectDetails.setSourceName(source.getName());
        connectDetails.setSourceType(determineConnectableType(source));
        connectDetails.setRelationship(relationships);
        connectDetails.setDestinationId(destination.getId());
        connectDetails.setDestinationName(destination.getName());
        connectDetails.setDestinationType(determineConnectableType(destination));
        // create the audit record
        final FlowChangeAction action = generateAuditRecord(connection.getId(), name, Component.Connection, Operation.Connect, timestamp);
        action.setActionDetails(connectDetails);
        actions.add(action);
    }
    // save the actions
    if (!actions.isEmpty()) {
        saveActions(actions, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ArrayList(java.util.ArrayList) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) Date(java.util.Date) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 4 with FlowChangeConnectDetails

use of org.apache.nifi.action.details.FlowChangeConnectDetails in project nifi by apache.

the class StandardActionDAO method getConnectDetails.

private ConnectDetails getConnectDetails(Integer actionId) throws DataAccessException {
    FlowChangeConnectDetails connectionDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_CONNECT_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            final Component sourceComponent = Component.valueOf(rs.getString("SOURCE_TYPE"));
            final Component destinationComponent = Component.valueOf(rs.getString("DESTINATION_TYPE"));
            connectionDetails = new FlowChangeConnectDetails();
            connectionDetails.setSourceId(rs.getString("SOURCE_ID"));
            connectionDetails.setSourceName(rs.getString("SOURCE_NAME"));
            connectionDetails.setSourceType(sourceComponent);
            connectionDetails.setRelationship(rs.getString("RELATIONSHIP"));
            connectionDetails.setDestinationId(rs.getString("DESTINATION_ID"));
            connectionDetails.setDestinationName(rs.getString("DESTINATION_NAME"));
            connectionDetails.setDestinationType(destinationComponent);
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return connectionDetails;
}
Also used : FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Component(org.apache.nifi.action.Component) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 5 with FlowChangeConnectDetails

use of org.apache.nifi.action.details.FlowChangeConnectDetails in project nifi by apache.

the class DtoFactory method createActionDetailsDto.

/**
 * Creates an ActionDetailsDTO for the specified ActionDetails.
 *
 * @param actionDetails details
 * @return dto
 */
private ActionDetailsDTO createActionDetailsDto(final ActionDetails actionDetails) {
    if (actionDetails == null) {
        return null;
    }
    if (actionDetails instanceof FlowChangeConfigureDetails) {
        final ConfigureDetailsDTO configureDetails = new ConfigureDetailsDTO();
        configureDetails.setName(((ConfigureDetails) actionDetails).getName());
        configureDetails.setPreviousValue(((ConfigureDetails) actionDetails).getPreviousValue());
        configureDetails.setValue(((ConfigureDetails) actionDetails).getValue());
        return configureDetails;
    } else if (actionDetails instanceof FlowChangeConnectDetails) {
        final ConnectDetailsDTO connectDetails = new ConnectDetailsDTO();
        connectDetails.setSourceId(((ConnectDetails) actionDetails).getSourceId());
        connectDetails.setSourceName(((ConnectDetails) actionDetails).getSourceName());
        connectDetails.setSourceType(((ConnectDetails) actionDetails).getSourceType().toString());
        connectDetails.setRelationship(((ConnectDetails) actionDetails).getRelationship());
        connectDetails.setDestinationId(((ConnectDetails) actionDetails).getDestinationId());
        connectDetails.setDestinationName(((ConnectDetails) actionDetails).getDestinationName());
        connectDetails.setDestinationType(((ConnectDetails) actionDetails).getDestinationType().toString());
        return connectDetails;
    } else if (actionDetails instanceof FlowChangeMoveDetails) {
        final MoveDetailsDTO moveDetails = new MoveDetailsDTO();
        moveDetails.setPreviousGroup(((MoveDetails) actionDetails).getPreviousGroup());
        moveDetails.setPreviousGroupId(((MoveDetails) actionDetails).getPreviousGroupId());
        moveDetails.setGroup(((MoveDetails) actionDetails).getGroup());
        moveDetails.setGroupId(((MoveDetails) actionDetails).getGroupId());
        return moveDetails;
    } else if (actionDetails instanceof FlowChangePurgeDetails) {
        final PurgeDetailsDTO purgeDetails = new PurgeDetailsDTO();
        purgeDetails.setEndDate(((PurgeDetails) actionDetails).getEndDate());
        return purgeDetails;
    } else {
        throw new WebApplicationException(new IllegalArgumentException(String.format("Unrecognized type of action details encountered %s during serialization.", actionDetails.toString())));
    }
}
Also used : FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ConfigureDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConfigureDetailsDTO) MoveDetailsDTO(org.apache.nifi.web.api.dto.action.details.MoveDetailsDTO) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) WebApplicationException(javax.ws.rs.WebApplicationException) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) PurgeDetailsDTO(org.apache.nifi.web.api.dto.action.details.PurgeDetailsDTO) ConnectDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConnectDetailsDTO)

Aggregations

FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)5 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Component (org.apache.nifi.action.Component)2 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)2 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)2 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)2 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)2 FlowChangeMoveDetails (org.apache.nifi.action.details.FlowChangeMoveDetails)2 FlowChangePurgeDetails (org.apache.nifi.action.details.FlowChangePurgeDetails)2 PurgeDetails (org.apache.nifi.action.details.PurgeDetails)2 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Action (org.apache.nifi.action.Action)1 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)1 RemoteProcessGroupDetails (org.apache.nifi.action.component.details.RemoteProcessGroupDetails)1