private Connection addConnection(final ProcessGroup destinationGroup, final VersionedConnection proposed, final String componentIdSeed) { final Connectable source = getConnectable(destinationGroup, proposed.getSource()); if (source == null) { throw new IllegalArgumentException("Connection has a source with identifier " + proposed.getIdentifier() + " but no component could be found in the Process Group with a corresponding identifier"); } final Connectable destination = getConnectable(destinationGroup, proposed.getDestination()); if (destination == null) { throw new IllegalArgumentException("Connection has a destination with identifier " + proposed.getDestination().getId() + " but no component could be found in the Process Group with a corresponding identifier"); } final Connection connection = flowController.createConnection(generateUuid(proposed.getIdentifier(), destination.getIdentifier(), componentIdSeed), proposed.getName(), source, destination, proposed.getSelectedRelationships()); connection.setVersionedComponentId(proposed.getIdentifier()); destinationGroup.addConnection(connection); updateConnection(connection, proposed); flowManager.onConnectionAdded(connection); return connection; }
private void updateConnection(final Connection connection, final VersionedConnection proposed) { connection.setBendPoints(proposed.getBends() == null ? Collections.emptyList() : proposed.getBends().stream() .map(pos -> new Position(pos.getX(), pos.getY())) .collect(Collectors.toList())); connection.setDestination(getConnectable(connection.getProcessGroup(), proposed.getDestination())); connection.setLabelIndex(proposed.getLabelIndex()); connection.setName(proposed.getName()); connection.setRelationships(proposed.getSelectedRelationships().stream() .map(name -> new Relationship.Builder().name(name).build()) .collect(Collectors.toSet())); connection.setZIndex(proposed.getzIndex()); queue.setBackPressureDataSizeThreshold(proposed.getBackPressureDataSizeThreshold()); queue.setBackPressureObjectThreshold(proposed.getBackPressureObjectThreshold()); queue.setFlowFileExpiration(proposed.getFlowFileExpiration()); final List<FlowFilePrioritizer> prioritizers = proposed.getPrioritizers() == null ? Collections.emptyList() : proposed.getPrioritizers().stream() .map(prioritizerName -> { try { final String loadBalanceStrategyName = proposed.getLoadBalanceStrategy(); if (loadBalanceStrategyName == null) { queue.setLoadBalanceStrategy(LoadBalanceStrategy.DO_NOT_LOAD_BALANCE, proposed.getPartitioningAttribute()); } else { final LoadBalanceStrategy loadBalanceStrategy = LoadBalanceStrategy.valueOf(loadBalanceStrategyName); final String partitioningAttribute = proposed.getPartitioningAttribute(); final String compressionName = proposed.getLoadBalanceCompression();
@Override public ConnectionSchema apply(final VersionedConnection versionedConnection) { Map<String, Object> map = new HashMap<>(); map.put(ID_KEY, versionedConnection.getIdentifier()); map.put(NAME_KEY, versionedConnection.getName()); map.put(ConnectionSchema.SOURCE_ID_KEY, versionedConnection.getSource().getId()); Set<String> selectedRelationships = nullToEmpty(versionedConnection.getSelectedRelationships()); map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAMES_KEY, selectedRelationships.stream().sorted().collect(Collectors.toList())); map.put(ConnectionSchema.DESTINATION_ID_KEY, versionedConnection.getDestination().getId()); map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, versionedConnection.getBackPressureObjectThreshold()); map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, versionedConnection.getBackPressureDataSizeThreshold()); map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, versionedConnection.getFlowFileExpiration()); List<String> queuePrioritizers = nullToEmpty(versionedConnection.getPrioritizers()); if (queuePrioritizers.size() > 0) { map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, queuePrioritizers.get(0)); } ConnectionSchema connectionSchema = new ConnectionSchema(map); if (ConnectableType.FUNNEL.name().equals(versionedConnection.getSource().getType())) { connectionSchema.addValidationIssue("Connection " + versionedConnection.getName() + " has type " + ConnectableType.FUNNEL.name() + " which is not supported by MiNiFi"); } if (queuePrioritizers.size() > 1) { connectionSchema.addValidationIssue(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, CONNECTIONS_KEY, " has more than one queue prioritizer"); } return connectionSchema; } }
setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap); setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap); .flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())) .filter(connectable -> (connectable.getType() == ConnectableComponentType.REMOTE_OUTPUT_PORT || connectable.getType() == ConnectableComponentType.REMOTE_INPUT_PORT)) .forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId()))); if (StringUtil.isNullOrEmpty(connection.getName())) { StringBuilder name = new StringBuilder(); ConnectableComponent connectionSource = connection.getSource(); name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap)); if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) { name.append(connection.getSelectedRelationships().iterator().next()); ConnectableComponent connectionDestination = connection.getDestination(); name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap)); connection.setName(name.toString());
private void compare(final VersionedConnection connectionA, final VersionedConnection connectionB, final Set<FlowDifference> differences) { if (compareComponents(connectionA, connectionB, differences)) { return; } addIfDifferent(differences, DifferenceType.BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED, connectionA, connectionB, VersionedConnection::getBackPressureDataSizeThreshold); addIfDifferent(differences, DifferenceType.BACKPRESSURE_OBJECT_THRESHOLD_CHANGED, connectionA, connectionB, VersionedConnection::getBackPressureObjectThreshold); addIfDifferent(differences, DifferenceType.BENDPOINTS_CHANGED, connectionA, connectionB, VersionedConnection::getBends); addIfDifferent(differences, DifferenceType.DESTINATION_CHANGED, connectionA, connectionB, VersionedConnection::getDestination); addIfDifferent(differences, DifferenceType.FLOWFILE_EXPIRATION_CHANGED, connectionA, connectionB, VersionedConnection::getFlowFileExpiration); addIfDifferent(differences, DifferenceType.PRIORITIZERS_CHANGED, connectionA, connectionB, VersionedConnection::getPrioritizers); addIfDifferent(differences, DifferenceType.SELECTED_RELATIONSHIPS_CHANGED, connectionA, connectionB, VersionedConnection::getSelectedRelationships); addIfDifferent(differences, DifferenceType.SOURCE_CHANGED, connectionA, connectionB, c -> c.getSource().getId()); addIfDifferent(differences, DifferenceType.LOAD_BALANCE_STRATEGY_CHANGED, connectionA, connectionB, conn -> conn.getLoadBalanceStrategy() == null ? DEFAULT_LOAD_BALANCE_STRATEGY : conn.getLoadBalanceStrategy()); addIfDifferent(differences, DifferenceType.PARTITIONING_ATTRIBUTE_CHANGED, connectionA, connectionB, conn -> conn.getPartitioningAttribute() == null ? DEFAULT_PARTITIONING_ATTRIBUTE : conn.getPartitioningAttribute()); addIfDifferent(differences, DifferenceType.LOAD_BALANCE_COMPRESSION_CHANGED, connectionA, connectionB, conn -> conn.getLoadBalanceCompression() == null ? DEFAULT_LOAD_BALANCE_COMPRESSION : conn.getLoadBalanceCompression()); }
final String sourceVersionedId = connection.getSource().getId(); final List<Connectable> sources = connectablesByVersionId.get(sourceVersionedId); if (sources != null) { final String destinationVersionId = connection.getDestination().getId(); final List<Connectable> destinations = connectablesByVersionId.get(destinationVersionId); if (destinations != null) {
if (connectionToAdd.getPrioritizers() != null) { for (final String prioritizerType : connectionToAdd.getPrioritizers()) { try { flowManager.createPrioritizer(prioritizerType); final String loadBalanceStrategyName = connectionToAdd.getLoadBalanceStrategy(); if (loadBalanceStrategyName != null) { try {
private void findAllConnectionIds(final VersionedProcessGroup group, final Set<String> ids) { for (final VersionedConnection connection : group.getConnections()) { ids.add(connection.getIdentifier()); } for (final VersionedProcessGroup childGroup : group.getProcessGroups()) { findAllConnectionIds(childGroup, ids); } }
@Override public ConnectionSchema apply(final VersionedConnection versionedConnection) { Map<String, Object> map = new HashMap<>(); map.put(ID_KEY, versionedConnection.getIdentifier()); map.put(NAME_KEY, versionedConnection.getName()); map.put(ConnectionSchema.SOURCE_ID_KEY, versionedConnection.getSource().getId()); Set<String> selectedRelationships = nullToEmpty(versionedConnection.getSelectedRelationships()); map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAMES_KEY, selectedRelationships.stream().sorted().collect(Collectors.toList())); map.put(ConnectionSchema.DESTINATION_ID_KEY, versionedConnection.getDestination().getId()); map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, versionedConnection.getBackPressureObjectThreshold()); map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, versionedConnection.getBackPressureDataSizeThreshold()); map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, versionedConnection.getFlowFileExpiration()); List<String> queuePrioritizers = nullToEmpty(versionedConnection.getPrioritizers()); if (queuePrioritizers.size() > 0) { map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, queuePrioritizers.get(0)); } ConnectionSchema connectionSchema = new ConnectionSchema(map); if (ConnectableType.FUNNEL.name().equals(versionedConnection.getSource().getType())) { connectionSchema.addValidationIssue("Connection " + versionedConnection.getName() + " has type " + ConnectableType.FUNNEL.name() + " which is not supported by MiNiFi"); } if (queuePrioritizers.size() > 1) { connectionSchema.addValidationIssue(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, CONNECTIONS_KEY, " has more than one queue prioritizer"); } return connectionSchema; } }
setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap); setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap); .flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())) .filter(connectable -> (connectable.getType() == ConnectableComponentType.REMOTE_OUTPUT_PORT || connectable.getType() == ConnectableComponentType.REMOTE_INPUT_PORT)) .forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId()))); if (StringUtil.isNullOrEmpty(connection.getName())) { StringBuilder name = new StringBuilder(); ConnectableComponent connectionSource = connection.getSource(); name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap)); if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) { name.append(connection.getSelectedRelationships().iterator().next()); ConnectableComponent connectionDestination = connection.getDestination(); name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap)); connection.setName(name.toString());
private void findAllConnections(final VersionedProcessGroup group, final Map<String, VersionedConnection> map) { for (final VersionedConnection connection : group.getConnections()) { map.put(connection.getIdentifier(), connection); } for (final VersionedProcessGroup childGroup : group.getProcessGroups()) { findAllConnections(childGroup, map); } }
final Connection connection = connectionsByVersionedId.get(proposedConnection.getIdentifier()); if (connection == null) { final Connection added = addConnection(group, proposedConnection, componentIdSeed); connectionsRemoved.remove(proposedConnection.getIdentifier());