writeLock.lock(); try { if (!requireNonNull(connection).getSource().equals(this) && !connection.getDestination().equals(this)) { throw new IllegalArgumentException("Cannot add a connection to a Funnel for which the Funnel is neither the Source nor the Destination"); if (connection.getSource().equals(this) && connection.getDestination().equals(this)) { throw new IllegalArgumentException("Cannot add a connection from a Funnel back to itself"); if (connection.getDestination().equals(this)) { if (connection.getSource().equals(this)) { for (final Relationship relationship : connection.getRelationships()) { if (!relationship.equals(Relationship.ANONYMOUS)) { throw new IllegalArgumentException("No relationship with name " + relationship + " exists for Funnels");
public int getAvailableRelationshipCount() { int count = 0; for (final Relationship relationship : connectable.getRelationships()) { final Collection<Connection> connections = connectable.getConnections(relationship); if (connections == null || connections.isEmpty()) { count++; } else { boolean available = true; for (final Connection connection : connections) { // consider self-loops available if (connection.getSource() == connection.getDestination()) { continue; } if (connection.getFlowFileQueue().isFull()) { available = false; break; } } if (available) { count++; } } } return count; }
@Override public void removeConnection(final Connection connectionToRemove) { writeLock.lock(); try { // verify that Connection belongs to this group final Connection connection = connections.get(requireNonNull(connectionToRemove).getIdentifier()); if (connection == null) { throw new IllegalStateException("Connection " + connectionToRemove.getIdentifier() + " is not a member of this Process Group"); } connectionToRemove.verifyCanDelete(); connectionToRemove.getFlowFileQueue().stopLoadBalancing(); final Connectable source = connectionToRemove.getSource(); final Connectable dest = connectionToRemove.getDestination(); // update the source & destination source.removeConnection(connection); if (source != dest) { dest.removeConnection(connection); } // remove the connection from our map connections.remove(connection.getIdentifier()); LOG.info("{} removed from flow", connection); onComponentModified(); flowManager.onConnectionRemoved(connection); } finally { writeLock.unlock(); } }
public ConnectDetails createConnectDetails(final Connection connection, final Collection<Relationship> relationships) { return createConnectDetails(connection, connection.getSource(), relationships, connection.getDestination()); }
@Override public void inheritConnection(final Connection connection) { writeLock.lock(); try { connections.put(connection.getIdentifier(), connection); onComponentModified(); connection.setProcessGroup(this); } finally { writeLock.unlock(); } }
public void onConnectionAdded(final Connection connection) { allConnections.put(connection.getIdentifier(), connection); if (flowController.isInitialized()) { connection.getFlowFileQueue().startLoadBalancing(); } }
public VersionedConnection mapConnection(final Connection connection) { final FlowFileQueue queue = connection.getFlowFileQueue(); final VersionedConnection versionedConnection = new InstantiatedVersionedConnection(connection.getIdentifier(), connection.getProcessGroup().getIdentifier()); versionedConnection.setIdentifier(getId(connection.getVersionedComponentId(), connection.getIdentifier())); versionedConnection.setGroupIdentifier(getGroupId(connection.getProcessGroup().getIdentifier())); versionedConnection.setName(connection.getName()); versionedConnection.setBackPressureDataSizeThreshold(queue.getBackPressureDataSizeThreshold()); versionedConnection.setBackPressureObjectThreshold(queue.getBackPressureObjectThreshold()); versionedConnection.setFlowFileExpiration(queue.getFlowFileExpiration()); versionedConnection.setLabelIndex(connection.getLabelIndex()); versionedConnection.setPrioritizers(queue.getPriorities().stream().map(p -> p.getClass().getName()).collect(Collectors.toList())); versionedConnection.setSelectedRelationships(connection.getRelationships().stream().map(Relationship::getName).collect(Collectors.toSet())); versionedConnection.setzIndex(connection.getZIndex()); final FlowFileQueue flowFileQueue = connection.getFlowFileQueue(); versionedConnection.setLoadBalanceStrategy(flowFileQueue.getLoadBalanceStrategy().name()); versionedConnection.setPartitioningAttribute(flowFileQueue.getPartitioningAttribute()); versionedConnection.setLoadBalanceCompression(flowFileQueue.getLoadBalanceCompression().name()); versionedConnection.setBends(connection.getBendPoints().stream() .map(this::mapPosition) .collect(Collectors.toList())); versionedConnection.setSource(mapConnectable(connection.getSource())); versionedConnection.setDestination(mapConnectable(connection.getDestination())); return versionedConnection; }
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()); final FlowFileQueue queue = connection.getFlowFileQueue(); queue.setBackPressureDataSizeThreshold(proposed.getBackPressureDataSizeThreshold()); queue.setBackPressureObjectThreshold(proposed.getBackPressureObjectThreshold()); return flowManager.createPrioritizer(prioritizerName); } catch (final Exception e) { throw new IllegalStateException("Failed to create Prioritizer of type " + prioritizerName + " for Connection with ID " + connection.getIdentifier());
addIfAppropriate(searchStr, connection.getIdentifier(), "Id", matches); addIfAppropriate(searchStr, connection.getVersionedComponentId().orElse(null), "Version Control ID", matches); addIfAppropriate(searchStr, connection.getName(), "Name", matches); for (final Relationship relationship : connection.getRelationships()) { addIfAppropriate(searchStr, relationship.getName(), "Relationship", matches); final FlowFileQueue queue = connection.getFlowFileQueue(); for (final FlowFilePrioritizer comparator : queue.getPriorities()) { addIfAppropriate(searchStr, comparator.getClass().getName(), "Prioritizer", matches); final int expirationMillis = connection.getFlowFileQueue().getFlowFileExpiration(TimeUnit.MILLISECONDS); if (expirationMillis > 0) { matches.add("FlowFile expiration: " + connection.getFlowFileQueue().getFlowFileExpiration()); final String backPressureDataSize = connection.getFlowFileQueue().getBackPressureDataSizeThreshold(); final Double backPressureBytes = DataUnit.parseDataSize(backPressureDataSize, DataUnit.B); if (backPressureBytes > 0) { final long backPressureCount = connection.getFlowFileQueue().getBackPressureObjectThreshold(); if (backPressureCount > 0) { matches.add("Back pressure count: " + backPressureCount); final Connectable source = connection.getSource(); addIfAppropriate(searchStr, source.getIdentifier(), "Source id", matches); addIfAppropriate(searchStr, source.getName(), "Source name", matches); final Connectable destination = connection.getDestination(); addIfAppropriate(searchStr, destination.getIdentifier(), "Destination id", matches);
final boolean isSourceAuthorized = isAuthorized.evaluate(conn.getSource()); final boolean isDestinationAuthorized = isAuthorized.evaluate(conn.getDestination()); connStatus.setId(conn.getIdentifier()); connStatus.setGroupId(conn.getProcessGroup().getIdentifier()); connStatus.setSourceId(conn.getSource().getIdentifier()); connStatus.setSourceName(isSourceAuthorized ? conn.getSource().getName() : conn.getSource().getIdentifier()); connStatus.setDestinationId(conn.getDestination().getIdentifier()); connStatus.setDestinationName(isDestinationAuthorized ? conn.getDestination().getName() : conn.getDestination().getIdentifier()); connStatus.setBackPressureDataSizeThreshold(conn.getFlowFileQueue().getBackPressureDataSizeThreshold()); connStatus.setBackPressureObjectThreshold(conn.getFlowFileQueue().getBackPressureObjectThreshold()); final FlowFileEvent connectionStatusReport = statusReport.getReportEntry(conn.getIdentifier()); if (connectionStatusReport != null) { connStatus.setInputBytes(connectionStatusReport.getContentSizeIn()); if (StringUtils.isNotBlank(conn.getName())) { connStatus.setName(conn.getName()); } else if (conn.getRelationships() != null && !conn.getRelationships().isEmpty()) { final Collection<String> relationships = new ArrayList<>(conn.getRelationships().size()); for (final Relationship relationship : conn.getRelationships()) { relationships.add(relationship.getName()); connStatus.setName(conn.getIdentifier()); final QueueSize queueSize = conn.getFlowFileQueue().size(); final int connectionQueuedCount = queueSize.getObjectCount(); final long connectionQueuedBytes = queueSize.getByteCount();
@Override public Connection updateConnection(final ConnectionDTO connectionDTO) { final Connection connection = locateConnection(connectionDTO.getId()); final ProcessGroup group = connection.getProcessGroup(); final Connectable existingSource = connection.getSource(); if (isNotNull(connectionDTO.getSource()) && !existingSource.getIdentifier().equals(connectionDTO.getSource().getId())) { throw new IllegalStateException("Connection with ID " + connectionDTO.getId() + " has conflicting Source ID"); if (isNotNull(relationships)) { if (relationships.isEmpty()) { throw new IllegalArgumentException("Cannot remove all relationships from Connection with ID " + connection.getIdentifier() + " -- remove the Connection instead"); final Connectable currentDestination = connection.getDestination(); connection.setRelationships(newProcessorRelationships); connection.setDestination(newDestination);
@Override public void updateConnection(final Connection connection) throws IllegalStateException { if (requireNonNull(connection).getSource().equals(this)) { writeLock.lock(); try { if (!outgoingConnections.remove(connection)) { throw new IllegalStateException("No Connection with ID " + connection.getIdentifier() + " is currently registered with this Funnel"); } outgoingConnections.add(connection); } finally { writeLock.unlock(); } } if (connection.getDestination().equals(this)) { writeLock.lock(); try { if (!incomingConnections.remove(connection)) { throw new IllegalStateException("No Connection with ID " + connection.getIdentifier() + " is currently registered with this Funnel"); } incomingConnections.add(connection); } finally { writeLock.unlock(); } } }
Connectable previousDestination = connection.getDestination(); Collection<Relationship> previousRelationships = connection.getRelationships(); Map<String, String> values = extractConfiguredPropertyValues(connection, connectionDTO); Connectable source = connection.getSource(); Connectable destination = connection.getDestination(); final ConnectDetails connectDetails = createConnectDetails(connection, connection.getRelationships()); actions.add(generateAuditRecordForConnection(connection, Operation.Connect, connectDetails)); Collection<Relationship> newRelationships = connection.getRelationships(); configurationAction.setOperation(Operation.Configure); configurationAction.setTimestamp(actionTimestamp); configurationAction.setSourceId(connection.getIdentifier()); configurationAction.setSourceName(connection.getName()); configurationAction.setSourceType(Component.Connection); configurationAction.setActionDetails(configurationDetails);
private void registerDequeuedRecord(final FlowFileRecord flowFile, final Connection connection) { final StandardRepositoryRecord record = new StandardRepositoryRecord(connection.getFlowFileQueue(), flowFile); records.put(flowFile.getId(), record); flowFilesIn++; contentSizeIn += flowFile.getSize(); Set<FlowFileRecord> set = unacknowledgedFlowFiles.get(connection.getFlowFileQueue()); if (set == null) { set = new HashSet<>(); unacknowledgedFlowFiles.put(connection.getFlowFileQueue(), set); } set.add(flowFile); incrementConnectionOutputCounts(connection, flowFile); }
@Override public void verifyCanDelete(boolean ignoreConnections) throws IllegalStateException { if (ignoreConnections) { return; } readLock.lock(); try { for (final Connection connection : outgoingConnections) { connection.verifyCanDelete(); } for (final Connection connection : incomingConnections) { if (connection.getSource().equals(this)) { connection.verifyCanDelete(); } else { throw new IllegalStateException("Funnel " + this.getIdentifier() + " is the destination of another component"); } } } finally { readLock.unlock(); } }
writeLock.lock(); try { final String id = requireNonNull(connection).getIdentifier(); final Connection existingConnection = connections.get(id); if (existingConnection != null) { final Connectable source = connection.getSource(); final Connectable destination = connection.getDestination(); final ProcessGroup sourceGroup = source.getProcessGroup(); final ProcessGroup destinationGroup = destination.getProcessGroup(); connection.setProcessGroup(this); source.addConnection(connection); if (source != destination) { // don't call addConnection twice if it's a self-looping connection. destination.addConnection(connection); connections.put(connection.getIdentifier(), connection); flowManager.onConnectionAdded(connection); onComponentModified();
connection.verifyCanDelete(); for (final Port port : inputPorts.values()) { for (final Connection connection : port.getIncomingConnections()) { if (connection.getSource().equals(port)) { connection.verifyCanDelete(); } else { throw new IllegalStateException("Cannot delete Process Group because Input Port " + port.getIdentifier() if (connection.getDestination().equals(port)) { connection.verifyCanDelete(); } else { throw new IllegalStateException("Cannot delete Process Group because Output Port " + port.getIdentifier()
if (!connections.containsKey(conn.getIdentifier())) { throw new IllegalStateException("Connectable component " + connectable.getIdentifier() + " cannot be removed because it has incoming connections from the parent Process Group"); connectionIdsToRemove.add(conn.getIdentifier()); connections.get(id).verifyCanDelete(); for (final Connectable connectable : connectables) { for (final Connection conn : connectable.getIncomingConnections()) { if (!connectionIds.contains(conn.getIdentifier()) && !connectables.contains(conn.getSource())) { throw new IllegalStateException("Connectable component " + connectable.getIdentifier() + " cannot be removed because it has incoming connections " + "that are not selected to be deleted");
final String connectionId = connection.getIdentifier(); String connectionName = connection.getName(); if (StringUtils.isBlank(connectionName)) { Collection<String> relationshipNames = new HashSet<>(connection.getRelationships().size()); for (final Relationship relationship : connection.getRelationships()) { relationshipNames.add(relationship.getName());
@Override public boolean equals(final Object other) { if (!(other instanceof Connection)) { return false; } final Connection con = (Connection) other; return new EqualsBuilder().append(id, con.getIdentifier()).isEquals(); }