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;
}
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());
}
}
Aggregations