use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class ControllerFacade method getConnectionStatus.
/**
* Gets the status for the specified connection.
*
* @param connectionId connection id
* @return the status for the specified connection
*/
public ConnectionStatus getConnectionStatus(final String connectionId) {
final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
final Connection connection = root.findConnection(connectionId);
// ensure the connection was found
if (connection == null) {
throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
}
// calculate the process group status
final String groupId = connection.getProcessGroup().getIdentifier();
final ProcessGroupStatus processGroupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
if (processGroupStatus == null) {
throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
}
final ConnectionStatus status = processGroupStatus.getConnectionStatus().stream().filter(connectionStatus -> connectionId.equals(connectionStatus.getId())).findFirst().orElse(null);
if (status == null) {
throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
}
return status;
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class ControllerSearchService method search.
/**
* Searches term in the controller beginning from a given process group.
*
* @param results Search results
* @param search The search term
* @param group The init process group
*/
public void search(final SearchResultsDTO results, final String search, final ProcessGroup group) {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
if (group.isAuthorized(authorizer, RequestAction.READ, user)) {
final ComponentSearchResultDTO groupMatch = search(search, group);
if (groupMatch != null) {
// get the parent group, not the current one
groupMatch.setParentGroup(buildResultGroup(group.getParent(), user));
groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user));
results.getProcessGroupResults().add(groupMatch);
}
}
for (final ProcessorNode procNode : group.getProcessors()) {
if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) {
final ComponentSearchResultDTO match = search(search, procNode);
if (match != null) {
match.setGroupId(group.getIdentifier());
match.setParentGroup(buildResultGroup(group, user));
match.setVersionedGroup(buildVersionedGroup(group, user));
results.getProcessorResults().add(match);
}
}
}
for (final Connection connection : group.getConnections()) {
if (connection.isAuthorized(authorizer, RequestAction.READ, user)) {
final ComponentSearchResultDTO match = search(search, connection);
if (match != null) {
match.setGroupId(group.getIdentifier());
match.setParentGroup(buildResultGroup(group, user));
match.setVersionedGroup(buildVersionedGroup(group, user));
results.getConnectionResults().add(match);
}
}
}
for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) {
if (remoteGroup.isAuthorized(authorizer, RequestAction.READ, user)) {
final ComponentSearchResultDTO match = search(search, remoteGroup);
if (match != null) {
match.setGroupId(group.getIdentifier());
match.setParentGroup(buildResultGroup(group, user));
match.setVersionedGroup(buildVersionedGroup(group, user));
results.getRemoteProcessGroupResults().add(match);
}
}
}
for (final Port port : group.getInputPorts()) {
if (port.isAuthorized(authorizer, RequestAction.READ, user)) {
final ComponentSearchResultDTO match = search(search, port);
if (match != null) {
match.setGroupId(group.getIdentifier());
match.setParentGroup(buildResultGroup(group, user));
match.setVersionedGroup(buildVersionedGroup(group, user));
results.getInputPortResults().add(match);
}
}
}
for (final Port port : group.getOutputPorts()) {
if (port.isAuthorized(authorizer, RequestAction.READ, user)) {
final ComponentSearchResultDTO match = search(search, port);
if (match != null) {
match.setGroupId(group.getIdentifier());
match.setParentGroup(buildResultGroup(group, user));
match.setVersionedGroup(buildVersionedGroup(group, user));
results.getOutputPortResults().add(match);
}
}
}
for (final Funnel funnel : group.getFunnels()) {
if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) {
final ComponentSearchResultDTO match = search(search, funnel);
if (match != null) {
match.setGroupId(group.getIdentifier());
match.setParentGroup(buildResultGroup(group, user));
match.setVersionedGroup(buildVersionedGroup(group, user));
results.getFunnelResults().add(match);
}
}
}
for (final ProcessGroup processGroup : group.getProcessGroups()) {
search(results, search, processGroup);
}
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method deleteFlowFileDropRequest.
@Override
public DropFlowFileStatus deleteFlowFileDropRequest(String connectionId, String dropRequestId) {
final Connection connection = locateConnection(connectionId);
final FlowFileQueue queue = connection.getFlowFileQueue();
final DropFlowFileStatus dropFlowFileStatus = queue.cancelDropFlowFileRequest(dropRequestId);
if (dropFlowFileStatus == null) {
throw new ResourceNotFoundException(String.format("Unable to find drop request with id '%s'.", dropRequestId));
}
return dropFlowFileStatus;
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method getContent.
@Override
public DownloadableContent getContent(String id, String flowFileUuid, String requestUri) {
try {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final Connection connection = locateConnection(id);
final FlowFileQueue queue = connection.getFlowFileQueue();
final FlowFileRecord flowFile = queue.getFlowFile(flowFileUuid);
if (flowFile == null) {
throw new ResourceNotFoundException(String.format("The FlowFile with UUID %s is no longer in the active queue.", flowFileUuid));
}
// get the attributes and ensure appropriate access
final Map<String, String> attributes = flowFile.getAttributes();
final Authorizable dataAuthorizable = new DataAuthorizable(connection.getSourceAuthorizable());
dataAuthorizable.authorize(authorizer, RequestAction.READ, user, attributes);
// get the filename and fall back to the identifier (should never happen)
String filename = attributes.get(CoreAttributes.FILENAME.key());
if (filename == null) {
filename = flowFileUuid;
}
// get the mime-type
final String type = attributes.get(CoreAttributes.MIME_TYPE.key());
// get the content
final InputStream content = flowController.getContent(flowFile, user.getIdentity(), requestUri);
return new DownloadableContent(filename, type, content);
} catch (final ContentNotFoundException cnfe) {
throw new ResourceNotFoundException("Unable to find the specified content.");
} catch (final IOException ioe) {
logger.error(String.format("Unable to get the content for flowfile (%s) at this time.", flowFileUuid), ioe);
throw new IllegalStateException("Unable to get the content at this time.");
}
}
use of org.apache.nifi.connectable.Connection in project nifi by apache.
the class StandardConnectionDAO method getFlowFileListingRequest.
@Override
public ListFlowFileStatus getFlowFileListingRequest(String connectionId, String listingRequestId) {
final Connection connection = locateConnection(connectionId);
final FlowFileQueue queue = connection.getFlowFileQueue();
final ListFlowFileStatus listRequest = queue.getListFlowFileStatus(listingRequestId);
if (listRequest == null) {
throw new ResourceNotFoundException(String.format("Unable to find listing request with id '%s'.", listingRequestId));
}
return listRequest;
}
Aggregations