use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method deleteConnection.
@Override
public void deleteConnection(final String id) {
final Connection connection = locateConnection(id);
connection.getProcessGroup().removeConnection(connection);
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method getFlowFileDropRequest.
@Override
public DropFlowFileStatus getFlowFileDropRequest(String connectionId, String dropRequestId) {
final Connection connection = locateConnection(connectionId);
final FlowFileQueue queue = connection.getFlowFileQueue();
final DropFlowFileStatus dropRequest = queue.getDropFlowFileStatus(dropRequestId);
if (dropRequest == null) {
throw new ResourceNotFoundException(String.format("Unable to find drop request with id '%s'.", dropRequestId));
}
return dropRequest;
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method deleteFlowFileListingRequest.
@Override
public ListFlowFileStatus deleteFlowFileListingRequest(String connectionId, String listingRequestId) {
final Connection connection = locateConnection(connectionId);
final FlowFileQueue queue = connection.getFlowFileQueue();
final ListFlowFileStatus listFlowFileStatus = queue.cancelListFlowFileRequest(listingRequestId);
if (listFlowFileStatus == null) {
throw new ResourceNotFoundException(String.format("Unable to find listing request with id '%s'.", listingRequestId));
}
return listFlowFileStatus;
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method updateConnection.
@Override
public Connection updateConnection(final ConnectionDTO connectionDTO) {
final Connection connection = locateConnection(connectionDTO.getId());
final ProcessGroup group = connection.getProcessGroup();
// ensure we can update
verifyUpdate(connection, connectionDTO);
final Collection<Relationship> newProcessorRelationships = new ArrayList<>();
Connectable newDestination = null;
// ensure that the source ID is correct, if specified.
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");
}
// determine any new relationships
final Set<String> relationships = connectionDTO.getSelectedRelationships();
if (isNotNull(relationships)) {
if (relationships.isEmpty()) {
throw new IllegalArgumentException("Cannot remove all relationships from Connection with ID " + connection.getIdentifier() + " -- remove the Connection instead");
}
if (existingSource == null) {
throw new IllegalArgumentException("Cannot specify new relationships without including the source.");
}
for (final String relationship : relationships) {
final Relationship processorRelationship = existingSource.getRelationship(relationship);
if (processorRelationship == null) {
throw new IllegalArgumentException("Unable to locate " + relationship + " relationship.");
}
newProcessorRelationships.add(processorRelationship);
}
}
// determine if the destination changed
final ConnectableDTO proposedDestination = connectionDTO.getDestination();
if (proposedDestination != null) {
final Connectable currentDestination = connection.getDestination();
// handle remote input port differently
if (ConnectableType.REMOTE_INPUT_PORT.name().equals(proposedDestination.getType())) {
// the group id must be specified
if (proposedDestination.getGroupId() == null) {
throw new IllegalArgumentException("When the destination is a remote input port its group id is required.");
}
// if the current destination is a remote input port
boolean isDifferentRemoteProcessGroup = false;
if (currentDestination.getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) {
RemoteGroupPort remotePort = (RemoteGroupPort) currentDestination;
if (!proposedDestination.getGroupId().equals(remotePort.getRemoteProcessGroup().getIdentifier())) {
isDifferentRemoteProcessGroup = true;
}
}
// if the destination is changing or the previous destination was a different remote process group
if (!proposedDestination.getId().equals(currentDestination.getIdentifier()) || isDifferentRemoteProcessGroup) {
final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, group.getIdentifier());
final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(proposedDestination.getGroupId());
// ensure the remote process group was found
if (remoteProcessGroup == null) {
throw new IllegalArgumentException("Unable to find the specified remote process group.");
}
final RemoteGroupPort remoteInputPort = remoteProcessGroup.getInputPort(proposedDestination.getId());
// ensure the new destination was found
if (remoteInputPort == null) {
throw new IllegalArgumentException("Unable to find the specified destination.");
}
// ensure the remote port actually exists
if (!remoteInputPort.getTargetExists()) {
throw new IllegalArgumentException("The specified remote input port does not exist.");
} else {
newDestination = remoteInputPort;
}
}
} else {
// if there is a different destination id
if (!proposedDestination.getId().equals(currentDestination.getIdentifier())) {
// if the destination connectable's group id has not been set, its inferred to be the current group
if (proposedDestination.getGroupId() == null) {
proposedDestination.setGroupId(group.getIdentifier());
}
final ProcessGroup destinationGroup = locateProcessGroup(flowController, proposedDestination.getGroupId());
newDestination = destinationGroup.getConnectable(proposedDestination.getId());
// ensure the new destination was found
if (newDestination == null) {
throw new IllegalArgumentException("Unable to find the specified destination.");
}
}
}
}
// configure the connection
configureConnection(connection, connectionDTO);
// update the relationships if necessary
if (!newProcessorRelationships.isEmpty()) {
connection.setRelationships(newProcessorRelationships);
}
// update the destination if necessary
if (isNotNull(newDestination)) {
connection.setDestination(newDestination);
}
return connection;
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method verifyDelete.
@Override
public void verifyDelete(String id) {
final Connection connection = locateConnection(id);
connection.verifyCanDelete();
}
Aggregations