Search in sources :

Example 11 with FlowFilePrioritizer

use of org.apache.nifi.flowfile.FlowFilePrioritizer in project nifi by apache.

the class DtoFactory method createConnectionDto.

/**
 * Creates a ConnectionDTO from the specified Connection.
 *
 * @param connection connection
 * @return dto
 */
public ConnectionDTO createConnectionDto(final Connection connection) {
    if (connection == null) {
        return null;
    }
    final ConnectionDTO dto = new ConnectionDTO();
    dto.setId(connection.getIdentifier());
    dto.setParentGroupId(connection.getProcessGroup().getIdentifier());
    final List<PositionDTO> bendPoints = new ArrayList<>();
    for (final Position bendPoint : connection.getBendPoints()) {
        bendPoints.add(createPositionDto(bendPoint));
    }
    dto.setBends(bendPoints);
    dto.setName(connection.getName());
    dto.setLabelIndex(connection.getLabelIndex());
    dto.setzIndex(connection.getZIndex());
    dto.setSource(createConnectableDto(connection.getSource()));
    dto.setDestination(createConnectableDto(connection.getDestination()));
    dto.setVersionedComponentId(connection.getVersionedComponentId().orElse(null));
    dto.setBackPressureObjectThreshold(connection.getFlowFileQueue().getBackPressureObjectThreshold());
    dto.setBackPressureDataSizeThreshold(connection.getFlowFileQueue().getBackPressureDataSizeThreshold());
    dto.setFlowFileExpiration(connection.getFlowFileQueue().getFlowFileExpiration());
    dto.setPrioritizers(new ArrayList<String>());
    for (final FlowFilePrioritizer comparator : connection.getFlowFileQueue().getPriorities()) {
        dto.getPrioritizers().add(comparator.getClass().getCanonicalName());
    }
    // For ports, we do not want to populate the relationships.
    for (final Relationship selectedRelationship : connection.getRelationships()) {
        if (!Relationship.ANONYMOUS.equals(selectedRelationship)) {
            if (dto.getSelectedRelationships() == null) {
                dto.setSelectedRelationships(new TreeSet<String>(Collator.getInstance(Locale.US)));
            }
            dto.getSelectedRelationships().add(selectedRelationship.getName());
        }
    }
    // For ports, we do not want to populate the relationships.
    for (final Relationship availableRelationship : connection.getSource().getRelationships()) {
        if (!Relationship.ANONYMOUS.equals(availableRelationship)) {
            if (dto.getAvailableRelationships() == null) {
                dto.setAvailableRelationships(new TreeSet<String>(Collator.getInstance(Locale.US)));
            }
            dto.getAvailableRelationships().add(availableRelationship.getName());
        }
    }
    return dto;
}
Also used : Position(org.apache.nifi.connectable.Position) Relationship(org.apache.nifi.processor.Relationship) ArrayList(java.util.ArrayList) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer)

Example 12 with FlowFilePrioritizer

use of org.apache.nifi.flowfile.FlowFilePrioritizer in project nifi by apache.

the class StandardConnectionDAO method configureConnection.

/**
 * Configures the specified connection using the specified dto.
 */
private void configureConnection(Connection connection, ConnectionDTO connectionDTO) {
    // validate flow file comparators/prioritizers
    List<FlowFilePrioritizer> newPrioritizers = null;
    final List<String> prioritizers = connectionDTO.getPrioritizers();
    if (isNotNull(prioritizers)) {
        final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers);
        newPrioritizers = new ArrayList<>();
        for (final String className : newPrioritizersClasses) {
            try {
                newPrioritizers.add(flowController.createPrioritizer(className));
            } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                throw new IllegalArgumentException("Unable to set prioritizer " + className + ": " + e);
            }
        }
    }
    // update connection queue
    if (isNotNull(connectionDTO.getFlowFileExpiration())) {
        connection.getFlowFileQueue().setFlowFileExpiration(connectionDTO.getFlowFileExpiration());
    }
    if (isNotNull(connectionDTO.getBackPressureObjectThreshold())) {
        connection.getFlowFileQueue().setBackPressureObjectThreshold(connectionDTO.getBackPressureObjectThreshold());
    }
    if (isNotNull(connectionDTO.getBackPressureDataSizeThreshold())) {
        connection.getFlowFileQueue().setBackPressureDataSizeThreshold(connectionDTO.getBackPressureDataSizeThreshold());
    }
    if (isNotNull(newPrioritizers)) {
        connection.getFlowFileQueue().setPriorities(newPrioritizers);
    }
    // update the connection state
    if (isNotNull(connectionDTO.getBends())) {
        final List<Position> bendPoints = new ArrayList<>();
        for (final PositionDTO bend : connectionDTO.getBends()) {
            if (bend != null) {
                bendPoints.add(new Position(bend.getX(), bend.getY()));
            }
        }
        connection.setBendPoints(bendPoints);
    }
    if (isNotNull(connectionDTO.getName())) {
        connection.setName(connectionDTO.getName());
    }
    if (isNotNull(connectionDTO.getLabelIndex())) {
        connection.setLabelIndex(connectionDTO.getLabelIndex());
    }
    if (isNotNull(connectionDTO.getzIndex())) {
        connection.setZIndex(connectionDTO.getzIndex());
    }
}
Also used : Position(org.apache.nifi.connectable.Position) ArrayList(java.util.ArrayList) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer)

Aggregations

FlowFilePrioritizer (org.apache.nifi.flowfile.FlowFilePrioritizer)12 ArrayList (java.util.ArrayList)9 Position (org.apache.nifi.connectable.Position)7 Relationship (org.apache.nifi.processor.Relationship)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)4 List (java.util.List)3 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)3 Connectable (org.apache.nifi.connectable.Connectable)3 Connection (org.apache.nifi.connectable.Connection)3 Port (org.apache.nifi.connectable.Port)3 Size (org.apache.nifi.connectable.Size)3 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)3 Label (org.apache.nifi.controller.label.Label)3 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)3 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)3 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)3 ProcessGroup (org.apache.nifi.groups.ProcessGroup)3 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)3