Java Code Examples for org.apache.nifi.groups.ProcessGroup#findConnection()

The following examples show how to use org.apache.nifi.groups.ProcessGroup#findConnection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the status history for the specified connection.
 *
 * @param connectionId connection id
 * @return status history
 */
public StatusHistoryDTO getConnectionStatusHistory(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));
    }

    final StatusHistoryDTO statusHistory = flowController.getConnectionStatusHistory(connectionId);

    // if not authorized
    if (!connection.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser())) {
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_NAME, connectionId);
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_SOURCE_NAME, connection.getSource().getIdentifier());
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_DESTINATION_NAME, connection.getDestination().getIdentifier());
    }

    return statusHistory;
}
 
Example 2
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: ControllerFacade.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the status history for the specified connection.
 *
 * @param connectionId connection id
 * @return status history
 */
public StatusHistoryDTO getConnectionStatusHistory(final String connectionId) {
    final ProcessGroup root = getRootGroup();
    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));
    }

    final StatusHistoryDTO statusHistory = flowController.getConnectionStatusHistory(connectionId);

    // if not authorized
    if (!connection.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser())) {
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_NAME, connectionId);
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_SOURCE_NAME, connection.getSource().getIdentifier());
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_DESTINATION_NAME, connection.getDestination().getIdentifier());
    }

    return statusHistory;
}
 
Example 4
Source File: ControllerFacade.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = getRootGroup();
    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.getEventAccess().getGroupStatus(groupId, NiFiUserUtils.getNiFiUser(), 1);
    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;
}
 
Example 5
Source File: ControllerFacade.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets status analytics for the specified connection.
 *
 * @param connectionId connection id
 * @return the statistics for the specified connection
 */
public StatusAnalytics getConnectionStatusAnalytics(final String connectionId) {
    final ProcessGroup root = getRootGroup();
    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.getEventAccess().getGroupStatus(groupId, NiFiUserUtils.getNiFiUser(), 1);
    if (processGroupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    // get from flow controller
    final StatusAnalyticsEngine statusAnalyticsEngine = flowController.getStatusAnalyticsEngine();
    if (statusAnalyticsEngine == null) {
        throw new ResourceNotFoundException(String.format("Unable to provide analytics for connection with id '%s'. Analytics may not be enabled", connectionId));
    }

    return statusAnalyticsEngine.getStatusAnalytics(connectionId);
}
 
Example 6
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void setComponentDetails(final ProvenanceEventDTO dto) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());

    final Connectable connectable = root.findLocalConnectable(dto.getComponentId());
    if (connectable != null) {
        dto.setGroupId(connectable.getProcessGroup().getIdentifier());
        dto.setComponentName(connectable.getName());
        return;
    }

    final RemoteGroupPort remoteGroupPort = root.findRemoteGroupPort(dto.getComponentId());
    if (remoteGroupPort != null) {
        dto.setGroupId(remoteGroupPort.getProcessGroupIdentifier());
        dto.setComponentName(remoteGroupPort.getName());
        return;
    }

    final Connection connection = root.findConnection(dto.getComponentId());
    if (connection != null) {
        dto.setGroupId(connection.getProcessGroup().getIdentifier());

        String name = connection.getName();
        final Collection<Relationship> relationships = connection.getRelationships();
        if (StringUtils.isBlank(name) && CollectionUtils.isNotEmpty(relationships)) {
            name = StringUtils.join(relationships.stream().map(relationship -> relationship.getName()).collect(Collectors.toSet()), ", ");
        }
        dto.setComponentName(name);

        return;
    }
}
 
Example 7
Source File: StandardConnectionDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private Connection locateConnection(final String connectionId) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    final Connection connection = rootGroup.findConnection(connectionId);

    if (connection == null) {
        throw new ResourceNotFoundException(String.format("Unable to find connection with id '%s'.", connectionId));
    } else {
        return connection;
    }
}
 
Example 8
Source File: StandardConnectionDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
private Connection locateConnection(final String connectionId) {
    final ProcessGroup rootGroup = flowController.getFlowManager().getRootGroup();
    final Connection connection = rootGroup.findConnection(connectionId);

    if (connection == null) {
        throw new ResourceNotFoundException(String.format("Unable to find connection with id '%s'.", connectionId));
    } else {
        return connection;
    }
}
 
Example 9
Source File: StandardConnectionDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasConnection(String id) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    return rootGroup.findConnection(id) != null;
}
 
Example 10
Source File: ControllerFacade.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void setComponentDetails(final ProvenanceEventDTO dto) {
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final ProcessGroup root = getRootGroup();

    final Connectable connectable = findLocalConnectable(dto.getComponentId());
    if (connectable != null) {
        dto.setGroupId(connectable.getProcessGroup().getIdentifier());

        // if the user is approved for this component policy, provide additional details, otherwise override/redact as necessary
        if (Result.Approved.equals(connectable.checkAuthorization(authorizer, RequestAction.READ, user).getResult())) {
            dto.setComponentName(connectable.getName());
        } else {
            dto.setComponentType(connectable.getConnectableType().toString());
            dto.setComponentName(dto.getComponentId());
            dto.setRelationship(null);
        }

        return;
    }

    final RemoteGroupPort remoteGroupPort = root.findRemoteGroupPort(dto.getComponentId());
    if (remoteGroupPort != null) {
        dto.setGroupId(remoteGroupPort.getProcessGroupIdentifier());

        // if the user is approved for this component policy, provide additional details, otherwise override/redact as necessary
        if (Result.Approved.equals(remoteGroupPort.checkAuthorization(authorizer, RequestAction.READ, user).getResult())) {
            dto.setComponentName(remoteGroupPort.getName());
        } else {
            dto.setComponentName(dto.getComponentId());
            dto.setRelationship(null);
        }

        return;
    }

    final Connection connection = root.findConnection(dto.getComponentId());
    if (connection != null) {
        dto.setGroupId(connection.getProcessGroup().getIdentifier());

        // if the user is approved for this component policy, provide additional details, otherwise override/redact as necessary
        if (Result.Approved.equals(connection.checkAuthorization(authorizer, RequestAction.READ, user).getResult())) {
            String name = connection.getName();
            final Collection<Relationship> relationships = connection.getRelationships();
            if (StringUtils.isBlank(name) && CollectionUtils.isNotEmpty(relationships)) {
                name = StringUtils.join(relationships.stream().map(Relationship::getName).collect(Collectors.toSet()), ", ");
            }
            dto.setComponentName(name);
        } else {
            dto.setComponentName(dto.getComponentId());
            dto.setRelationship(null);
        }
    }
}
 
Example 11
Source File: StandardConnectionDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasConnection(String id) {
    final ProcessGroup rootGroup = flowController.getFlowManager().getRootGroup();
    return rootGroup.findConnection(id) != null;
}