public ConnectionDTO copy(final ConnectionDTO original) { final ConnectionDTO copy = new ConnectionDTO(); copy.setAvailableRelationships(copy(original.getAvailableRelationships())); copy.setDestination(original.getDestination()); copy.setPosition(original.getPosition()); copy.setId(original.getId()); copy.setName(original.getName()); copy.setParentGroupId(original.getParentGroupId()); copy.setSelectedRelationships(copy(original.getSelectedRelationships())); copy.setFlowFileExpiration(original.getFlowFileExpiration()); copy.setBackPressureObjectThreshold(original.getBackPressureObjectThreshold()); copy.setBackPressureDataSizeThreshold(original.getBackPressureDataSizeThreshold()); copy.setPrioritizers(copy(original.getPrioritizers())); copy.setSource(original.getSource()); copy.setzIndex(original.getzIndex()); copy.setLabelIndex(original.getLabelIndex()); copy.setBends(copy(original.getBends())); copy.setLoadBalancePartitionAttribute(original.getLoadBalancePartitionAttribute()); copy.setLoadBalanceStrategy(original.getLoadBalanceStrategy()); copy.setLoadBalanceCompression(original.getLoadBalanceCompression()); copy.setLoadBalanceStatus(original.getLoadBalanceStatus()); copy.setVersionedComponentId(original.getVersionedComponentId()); return copy; }
/** * Scrubs connections prior to saving. This includes removing available relationships. * * @param connections conns */ private static void scrubConnections(final Set<ConnectionDTO> connections) { // go through each connection for (final ConnectionDTO connectionDTO : connections) { connectionDTO.setAvailableRelationships(null); scrubConnectable(connectionDTO.getSource()); scrubConnectable(connectionDTO.getDestination()); } }
@Override public void verifyUpdateConnection(final ConnectionDTO connectionDTO) { // if connection does not exist, then the update request is likely creating it // so we don't verify since it will fail if (connectionDAO.hasConnection(connectionDTO.getId())) { connectionDAO.verifyUpdate(connectionDTO); } else { connectionDAO.verifyCreate(connectionDTO.getParentGroupId(), connectionDTO); } }
final ConnectableDTO sourceDto = dto.getSource(); if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceDto.getType())) { final RemoteProcessGroup remoteGroup = processGroup.getRemoteProcessGroup(sourceDto.getGroupId()); final ProcessGroup sourceGroup = flowManager.getGroup(sourceDto.getGroupId()); if (sourceGroup == null) { throw new RuntimeException("Found Invalid ProcessGroup ID for Source: " + dto.getSource().getGroupId()); throw new RuntimeException("Found Invalid Connectable ID for Source: " + dto.getSource().getId()); final ConnectableDTO destinationDto = dto.getDestination(); if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationDto.getType())) { final RemoteProcessGroup remoteGroup = processGroup.getRemoteProcessGroup(destinationDto.getGroupId()); final ProcessGroup destinationGroup = flowManager.getGroup(destinationDto.getGroupId()); if (destinationGroup == null) { throw new RuntimeException("Found Invalid ProcessGroup ID for Destination: " + dto.getDestination().getGroupId()); throw new RuntimeException("Found Invalid Connectable ID for Destination: " + dto.getDestination().getId()); final Connection connection = flowManager.createConnection(dto.getId(), dto.getName(), source, destination, dto.getSelectedRelationships()); connection.setVersionedComponentId(dto.getVersionedComponentId()); connection.setProcessGroup(processGroup); for (final PositionDTO bend : dto.getBends()) { bendPoints.add(new Position(bend.getX(), bend.getY())); final Long zIndex = dto.getzIndex(); if (zIndex != null) {
final ConnectionDTO dto = new ConnectionDTO(); dto.setId(connection.getIdentifier()); dto.setParentGroupId(connection.getProcessGroup().getIdentifier()); 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(flowFileQueue.getBackPressureObjectThreshold()); dto.setBackPressureDataSizeThreshold(flowFileQueue.getBackPressureDataSizeThreshold()); dto.setFlowFileExpiration(flowFileQueue.getFlowFileExpiration()); dto.setPrioritizers(new ArrayList<String>()); for (final FlowFilePrioritizer comparator : flowFileQueue.getPriorities()) { dto.getPrioritizers().add(comparator.getClass().getCanonicalName()); if (dto.getSelectedRelationships() == null) { dto.setSelectedRelationships(new TreeSet<String>(Collator.getInstance(Locale.US))); dto.getSelectedRelationships().add(selectedRelationship.getName()); if (dto.getAvailableRelationships() == null) { dto.setAvailableRelationships(new TreeSet<String>(Collator.getInstance(Locale.US))); dto.getAvailableRelationships().add(availableRelationship.getName());
@Override public ConnectionSchema apply(ConnectionDTO connectionDTO) { Map<String, Object> map = new HashMap<>(); map.put(ID_KEY, connectionDTO.getId()); map.put(NAME_KEY, connectionDTO.getName()); map.put(ConnectionSchema.SOURCE_ID_KEY, connectionDTO.getSource().getId()); Set<String> selectedRelationships = nullToEmpty(connectionDTO.getSelectedRelationships()); map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAMES_KEY, selectedRelationships.stream().sorted().collect(Collectors.toList())); map.put(ConnectionSchema.DESTINATION_ID_KEY, connectionDTO.getDestination().getId()); map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, connectionDTO.getBackPressureObjectThreshold()); map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, connectionDTO.getBackPressureDataSizeThreshold()); map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, connectionDTO.getFlowFileExpiration()); List<String> queuePrioritizers = nullToEmpty(connectionDTO.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(connectionDTO.getSource().getType())) { connectionSchema.addValidationIssue("Connection " + connectionDTO.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; } }
public static ConnectionDTO getConnection(final Element element) { final ConnectionDTO dto = new ConnectionDTO(); dto.setId(getString(element, "id")); dto.setName(getString(element, "name")); dto.setLabelIndex(getOptionalInt(element, "labelIndex")); dto.setzIndex(getOptionalLong(element, "zIndex")); dto.setVersionedComponentId(getString(element, "versionedComponentId")); dto.setBends(bends); dto.setSource(sourceConnectable); sourceConnectable.setId(getString(element, "sourceId")); sourceConnectable.setGroupId(getString(element, "sourceGroupId")); dto.setDestination(destConnectable); destConnectable.setId(getString(element, "destinationId")); destConnectable.setGroupId(getString(element, "destinationGroupId")); dto.setSelectedRelationships(relationships); dto.setBackPressureObjectThreshold(getLong(element, "maxWorkQueueSize")); dto.setBackPressureDataSizeThreshold(maxDataSize); dto.setFlowFileExpiration(expiration); dto.setPrioritizers(prioritizerClasses); dto.setLoadBalanceStrategy(getString(element, "loadBalanceStrategy")); dto.setLoadBalancePartitionAttribute(getString(element, "partitioningAttribute"));
final ProcessGroup group = locateProcessGroup(flowController, groupId); if (isNotNull(connectionDTO.getParentGroupId()) && !flowController.getFlowManager().areGroupsSame(connectionDTO.getParentGroupId(), groupId)) { throw new IllegalStateException("Cannot specify a different Parent Group ID than the Group to which the Connection is being added"); final ConnectableDTO sourceConnectableDTO = connectionDTO.getSource(); final ConnectableDTO destinationConnectableDTO = connectionDTO.getDestination(); if (isNotNull(connectionDTO.getSelectedRelationships())) { relationships.addAll(connectionDTO.getSelectedRelationships()); final Connection connection = flowController.createConnection(connectionDTO.getId(), connectionDTO.getName(), source, destination, relationships);
final List<String> prioritizers = connectionDTO.getPrioritizers(); if (isNotNull(prioritizers)) { final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers); 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()); final String loadBalanceStrategyName = connectionDTO.getLoadBalanceStrategy(); final String loadBalancePartitionAttribute = connectionDTO.getLoadBalancePartitionAttribute(); if (isNotNull(loadBalanceStrategyName)) { final LoadBalanceStrategy loadBalanceStrategy = LoadBalanceStrategy.valueOf(loadBalanceStrategyName); final String loadBalanceCompressionName = connectionDTO.getLoadBalanceCompression(); if (isNotNull(loadBalanceCompressionName)) { connection.getFlowFileQueue().setLoadBalanceCompression(LoadBalanceCompression.valueOf(loadBalanceCompressionName)); 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())); if (isNotNull(connectionDTO.getName())) {
private void verifyUpdate(final Connection connection, final ConnectionDTO connectionDTO) { // determine what the request is attempting if (isAnyNotNull(connectionDTO.getBackPressureDataSizeThreshold(), connectionDTO.getBackPressureObjectThreshold(), connectionDTO.getDestination(), connectionDTO.getFlowFileExpiration(), connectionDTO.getName(), connectionDTO.getPosition(), connectionDTO.getPrioritizers(), connectionDTO.getSelectedRelationships())) { // validate the incoming request final List<String> validationErrors = validateProposedConfiguration(connection.getProcessGroup().getIdentifier(), connectionDTO); // ensure there was no validation errors if (!validationErrors.isEmpty()) { throw new ValidationException(validationErrors); } // If destination is changing, ensure that current destination is not running. This check is done here, rather than // in the Connection object itself because the Connection object itself does not know which updates are to occur and // we don't want to prevent updating things like the connection name or backpressure just because the destination is running final Connectable destination = connection.getDestination(); if (destination != null && destination.isRunning() && destination.getConnectableType() != ConnectableType.FUNNEL && destination.getConnectableType() != ConnectableType.INPUT_PORT) { throw new ValidationException(Collections.singletonList("Cannot change the destination of connection because the current destination is running")); } // verify that this connection supports modification connection.verifyCanUpdate(); } }
final ConnectionDTO dto = FlowFromDOMFactory.getConnection(connectionElement); final Connection connection = processGroup.getConnection(dto.getId()); connection.setName(dto.getName()); connection.setProcessGroup(processGroup); if (dto.getLabelIndex() != null) { connection.setLabelIndex(dto.getLabelIndex()); if (dto.getzIndex() != null) { connection.setZIndex(dto.getzIndex()); for (final PositionDTO bend : dto.getBends()) { bendPoints.add(new Position(bend.getX(), bend.getY())); final List<String> prioritizers = dto.getPrioritizers(); if (prioritizers != null) { final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers); if (dto.getBackPressureObjectThreshold() != null) { connection.getFlowFileQueue().setBackPressureObjectThreshold(dto.getBackPressureObjectThreshold()); if (dto.getBackPressureDataSizeThreshold() != null && !dto.getBackPressureDataSizeThreshold().trim().isEmpty()) { connection.getFlowFileQueue().setBackPressureDataSizeThreshold(dto.getBackPressureDataSizeThreshold()); if (dto.getFlowFileExpiration() != null) { connection.getFlowFileQueue().setFlowFileExpiration(dto.getFlowFileExpiration());
setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap); setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap); .flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())) .filter(connectable -> connectable.getType().equals(ConnectableType.REMOTE_OUTPUT_PORT.toString()) || connectable.getType().equals(ConnectableType.REMOTE_INPUT_PORT.toString())) .forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId()))); if (StringUtil.isNullOrEmpty(connection.getName())) { StringBuilder name = new StringBuilder(); ConnectableDTO connectionSource = connection.getSource(); name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap)); if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) { name.append(connection.getSelectedRelationships().iterator().next()); ConnectableDTO connectionDestination = connection.getDestination(); name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap)); connection.setName(name.toString());
public ConnectionEntity createConnectionEntity(final ConnectionDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final ConnectionStatusDTO status) { final ConnectionEntity entity = new ConnectionEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setStatus(status); entity.setId(dto.getId()); entity.setPosition(dto.getPosition()); entity.setBends(dto.getBends()); entity.setLabelIndex(dto.getLabelIndex()); entity.setzIndex(dto.getzIndex()); entity.setSourceId(dto.getSource().getId()); entity.setSourceGroupId(dto.getSource().getGroupId()); entity.setSourceType(dto.getSource().getType()); entity.setDestinationId(dto.getDestination().getId()); entity.setDestinationGroupId(dto.getDestination().getGroupId()); entity.setDestinationType(dto.getDestination().getType()); if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } return entity; }
if (requestConnectionEntity.getComponent().getId() != null) { throw new IllegalArgumentException("Connection ID cannot be specified."); final List<PositionDTO> proposedBends = requestConnectionEntity.getComponent().getBends(); if (proposedBends != null) { for (final PositionDTO proposedBend : proposedBends) { if (requestConnectionEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestConnectionEntity.getComponent().getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestConnectionEntity.getComponent().getParentGroupId(), groupId)); requestConnectionEntity.getComponent().setParentGroupId(groupId); if (requestConnection.getSource() == null || requestConnection.getSource().getId() == null) { throw new IllegalArgumentException("The source of the connection must be specified."); if (requestConnection.getSource().getType() == null) { throw new IllegalArgumentException("The type of the source of the connection must be specified."); sourceConnectableType = ConnectableType.valueOf(requestConnection.getSource().getType()); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException(String.format("Unrecognized source type %s. Expected values are [%s]", requestConnection.getSource().getType(), StringUtils.join(ConnectableType.values(), ", "))); if (requestConnection.getDestination() == null || requestConnection.getDestination().getId() == null) { throw new IllegalArgumentException("The destination of the connection must be specified."); if (requestConnection.getDestination().getType() == null) { throw new IllegalArgumentException("The type of the destination of the connection must be specified.");
final ConnectionDTO cp = dtoFactory.copy(connectionDTO); final ConnectableDTO source = connectableMap.get(cp.getSource().getGroupId() + "-" + cp.getSource().getId()); final ConnectableDTO destination = connectableMap.get(cp.getDestination().getGroupId() + "-" + cp.getDestination().getId()); cp.setId(generateId(connectionDTO.getId(), idGenerationSeed, isCopy)); cp.setSource(source); cp.setDestination(destination); cp.setParentGroupId(groupId); connections.add(cp);
/** * Extracts configured settings from the specified connection only if they have also been specified in the connectionDTO. * * @param connection connection * @param connectionDTO dto * @return properties */ private Map<String, String> extractConfiguredPropertyValues(Connection connection, ConnectionDTO connectionDTO) { Map<String, String> values = new HashMap<>(); if (connectionDTO.getName() != null) { values.put(NAME, connection.getName()); } if (connectionDTO.getFlowFileExpiration() != null) { values.put(FLOW_FILE_EXPIRATION, String.valueOf(connection.getFlowFileQueue().getFlowFileExpiration())); } if (connectionDTO.getBackPressureObjectThreshold() != null) { values.put(BACK_PRESSURE_OBJECT_THRESHOLD, String.valueOf(connection.getFlowFileQueue().getBackPressureObjectThreshold())); } if (connectionDTO.getBackPressureDataSizeThreshold() != null) { values.put(BACK_PRESSURE_DATA_SIZE_THRESHOLD, String.valueOf(connection.getFlowFileQueue().getBackPressureDataSizeThreshold())); } if (connectionDTO.getPrioritizers() != null) { List<String> prioritizers = new ArrayList<>(); for (FlowFilePrioritizer prioritizer : connection.getFlowFileQueue().getPriorities()) { prioritizers.add(prioritizer.getClass().getCanonicalName()); } values.put(PRIORITIZERS, StringUtils.join(prioritizers, ", ")); } return values; }
@Override public String toString() { return "ConnectionDTO [id: " + getId() + "]"; } }
List<String> validationErrors = new ArrayList<>(); if (isNotNull(connectionDTO.getBackPressureObjectThreshold()) && connectionDTO.getBackPressureObjectThreshold() < 0) { validationErrors.add("Max queue size must be a non-negative integer"); if (isNotNull(connectionDTO.getFlowFileExpiration())) { Matcher expirationMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(connectionDTO.getFlowFileExpiration()); if (!expirationMatcher.matches()) { validationErrors.add("Flow file expiration is not a valid time duration (ie 30 sec, 5 min)"); if (isNotNull(connectionDTO.getLabelIndex())) { if (connectionDTO.getLabelIndex() < 0) { validationErrors.add("The label index must be positive."); final ConnectableDTO proposedDestination = connectionDTO.getDestination(); if (proposedDestination != null && ConnectableType.REMOTE_INPUT_PORT.name().equals(proposedDestination.getType())) {
if (!id.equals(requestConnection.getId())) { throw new IllegalArgumentException(String.format("The connection id " + "(%s) in the request body does not equal the connection id of the " + "requested resource (%s).", requestConnection.getId(), id)); if (requestConnection.getDestination() != null) { if (requestConnection.getDestination().getId() == null) { throw new IllegalArgumentException("When specifying a destination component, the destination id is required."); if (requestConnection.getDestination().getType() == null) { throw new IllegalArgumentException("When specifying a destination component, the type of the destination is required."); final List<PositionDTO> proposedBends = requestConnection.getBends(); if (proposedBends != null) { for (final PositionDTO proposedBend : proposedBends) { if (requestConnection.getDestination() != null && !currentDestination.getIdentifier().equals(requestConnection.getDestination().getId())) { try { final ConnectableType destinationConnectableType = ConnectableType.valueOf(requestConnection.getDestination().getType()); newDestinationAuthorizable = lookup.getRemoteProcessGroup(requestConnection.getDestination().getGroupId()); } else { newDestinationAuthorizable = lookup.getLocalConnectable(requestConnection.getDestination().getId()); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException(String.format("Unrecognized destination type %s. Excepted values are [%s]", requestConnection.getDestination().getType(), StringUtils.join(ConnectableType.values(), ", ")));
final ConnectableDTO sourceDto = connectionDTO.getSource(); if (sourceDto == null || sourceDto.getId() == null) { throw new IllegalArgumentException("Cannot create connection without specifying source"); final ConnectableDTO destinationDto = connectionDTO.getDestination(); if (destinationDto == null || destinationDto.getId() == null) { throw new IllegalArgumentException("Cannot create connection without specifying destination");