private boolean isUpdateable(final Connection connection) { final Connectable source = connection.getSource(); if (source.getConnectableType() != ConnectableType.FUNNEL && source.isRunning()) { return false; } final Connectable destination = connection.getDestination(); if (destination.getConnectableType() != ConnectableType.FUNNEL && destination.isRunning()) { return false; } return true; }
@Override public void verifyCanDelete() { if (!flowFileQueue.isEmpty()) { throw new IllegalStateException("Queue not empty for " + this.getIdentifier()); } if (source.isRunning()) { if (!ConnectableType.FUNNEL.equals(source.getConnectableType())) { throw new IllegalStateException("Source of Connection (" + source.getIdentifier() + ") is running"); } } final Connectable dest = destination.get(); if (dest.isRunning()) { if (!ConnectableType.FUNNEL.equals(dest.getConnectableType())) { throw new IllegalStateException("Destination of Connection (" + dest.getIdentifier() + ") is running"); } } }
@Override public void setDestination(final Connectable newDestination) { final Connectable previousDestination = destination.get(); if (previousDestination.equals(newDestination)) { return; } if (previousDestination.isRunning() && !(previousDestination instanceof Funnel || previousDestination instanceof LocalPort)) { throw new IllegalStateException("Cannot change destination of Connection because the current destination is running"); } if (getFlowFileQueue().isUnacknowledgedFlowFile()) { throw new IllegalStateException("Cannot change destination of Connection because FlowFiles from this Connection are currently held by " + previousDestination); } if (newDestination instanceof Funnel && newDestination.equals(source)) { throw new IllegalStateException("Funnels do not support self-looping connections."); } try { previousDestination.removeConnection(this); this.destination.set(newDestination); getSource().updateConnection(this); newDestination.addConnection(this); scheduler.registerEvent(newDestination); } catch (final RuntimeException e) { this.destination.set(previousDestination); throw e; } }
/** * Verify that removing this connection will not prevent this Port from * still being connected via each relationship * * @param connection to test for removal * @return true if can be removed */ private boolean canConnectionBeRemoved(final Connection connection) { final Connectable source = connection.getSource(); if (!source.isRunning()) { // we don't have to verify that this Connectable is still connected because it's okay to make // the source invalid since it is not running. return true; } for (final Relationship relationship : source.getRelationships()) { if (source.isAutoTerminated(relationship)) { continue; } final Set<Connection> connectionsForRelationship = source.getConnections(relationship); if (connectionsForRelationship == null || connectionsForRelationship.isEmpty()) { return false; } } return true; }
@Override public ListingRequestDTO deleteFlowFileListingRequest(final String connectionId, final String listingRequestId) { final Connection connection = connectionDAO.getConnection(connectionId); final ListingRequestDTO listRequest = dtoFactory.createListingRequestDTO(connectionDAO.deleteFlowFileListingRequest(connectionId, listingRequestId)); // include whether the source and destination are running if (connection.getSource() != null) { listRequest.setSourceRunning(connection.getSource().isRunning()); } if (connection.getDestination() != null) { listRequest.setDestinationRunning(connection.getDestination().isRunning()); } return listRequest; }
@Override public ListingRequestDTO createFlowFileListingRequest(final String connectionId, final String listingRequestId) { final Connection connection = connectionDAO.getConnection(connectionId); final ListingRequestDTO listRequest = dtoFactory.createListingRequestDTO(connectionDAO.createFlowFileListingRequest(connectionId, listingRequestId)); // include whether the source and destination are running if (connection.getSource() != null) { listRequest.setSourceRunning(connection.getSource().isRunning()); } if (connection.getDestination() != null) { listRequest.setDestinationRunning(connection.getDestination().isRunning()); } return listRequest; }
@Override public ListingRequestDTO getFlowFileListingRequest(final String connectionId, final String listingRequestId) { final Connection connection = connectionDAO.getConnection(connectionId); final ListingRequestDTO listRequest = dtoFactory.createListingRequestDTO(connectionDAO.getFlowFileListingRequest(connectionId, listingRequestId)); // include whether the source and destination are running if (connection.getSource() != null) { listRequest.setSourceRunning(connection.getSource().isRunning()); } if (connection.getDestination() != null) { listRequest.setDestinationRunning(connection.getDestination().isRunning()); } return listRequest; }
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(); } }
dto.setRunning(connectable.isRunning()); if (isAuthorized) { dto.setComments(connectable.getComments());
/** * Verify that removing this connection will not prevent this Port from * still being connected via each relationship * * @param connection to test for removal * @return true if can be removed */ private boolean canConnectionBeRemoved(final Connection connection) { final Connectable source = connection.getSource(); if (!source.isRunning()) { // we don't have to verify that this Connectable is still connected because it's okay to make // the source invalid since it is not running. return true; } for (final Relationship relationship : source.getRelationships()) { if (source.isAutoTerminated(relationship)) { continue; } final Set<Connection> connectionsForRelationship = source.getConnections(relationship); if (connectionsForRelationship == null || connectionsForRelationship.isEmpty()) { return false; } } return true; }