Search in sources :

Example 31 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class FlowController method getGroupStatus.

/**
 * Returns the status for the components in the specified group with the
 * specified report. The results will be filtered by executing the specified
 * predicate.
 *
 * @param group group id
 * @param statusReport report
 * @param isAuthorized is authorized check
 * @return the component status
 */
public ProcessGroupStatus getGroupStatus(final ProcessGroup group, final RepositoryStatusReport statusReport, final Predicate<Authorizable> isAuthorized) {
    if (group == null) {
        return null;
    }
    final ProcessGroupStatus status = new ProcessGroupStatus();
    status.setId(group.getIdentifier());
    status.setName(isAuthorized.evaluate(group) ? group.getName() : group.getIdentifier());
    int activeGroupThreads = 0;
    long bytesRead = 0L;
    long bytesWritten = 0L;
    int queuedCount = 0;
    long queuedContentSize = 0L;
    int flowFilesIn = 0;
    long bytesIn = 0L;
    int flowFilesOut = 0;
    long bytesOut = 0L;
    int flowFilesReceived = 0;
    long bytesReceived = 0L;
    int flowFilesSent = 0;
    long bytesSent = 0L;
    int flowFilesTransferred = 0;
    long bytesTransferred = 0;
    // set status for processors
    final Collection<ProcessorStatus> processorStatusCollection = new ArrayList<>();
    status.setProcessorStatus(processorStatusCollection);
    for (final ProcessorNode procNode : group.getProcessors()) {
        final ProcessorStatus procStat = getProcessorStatus(statusReport, procNode, isAuthorized);
        processorStatusCollection.add(procStat);
        activeGroupThreads += procStat.getActiveThreadCount();
        bytesRead += procStat.getBytesRead();
        bytesWritten += procStat.getBytesWritten();
        flowFilesReceived += procStat.getFlowFilesReceived();
        bytesReceived += procStat.getBytesReceived();
        flowFilesSent += procStat.getFlowFilesSent();
        bytesSent += procStat.getBytesSent();
    }
    // set status for local child groups
    final Collection<ProcessGroupStatus> localChildGroupStatusCollection = new ArrayList<>();
    status.setProcessGroupStatus(localChildGroupStatusCollection);
    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        final ProcessGroupStatus childGroupStatus = getGroupStatus(childGroup, statusReport, isAuthorized);
        localChildGroupStatusCollection.add(childGroupStatus);
        activeGroupThreads += childGroupStatus.getActiveThreadCount();
        bytesRead += childGroupStatus.getBytesRead();
        bytesWritten += childGroupStatus.getBytesWritten();
        queuedCount += childGroupStatus.getQueuedCount();
        queuedContentSize += childGroupStatus.getQueuedContentSize();
        flowFilesReceived += childGroupStatus.getFlowFilesReceived();
        bytesReceived += childGroupStatus.getBytesReceived();
        flowFilesSent += childGroupStatus.getFlowFilesSent();
        bytesSent += childGroupStatus.getBytesSent();
        flowFilesTransferred += childGroupStatus.getFlowFilesTransferred();
        bytesTransferred += childGroupStatus.getBytesTransferred();
    }
    // set status for remote child groups
    final Collection<RemoteProcessGroupStatus> remoteProcessGroupStatusCollection = new ArrayList<>();
    status.setRemoteProcessGroupStatus(remoteProcessGroupStatusCollection);
    for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) {
        final RemoteProcessGroupStatus remoteStatus = createRemoteGroupStatus(remoteGroup, statusReport, isAuthorized);
        if (remoteStatus != null) {
            remoteProcessGroupStatusCollection.add(remoteStatus);
            flowFilesReceived += remoteStatus.getReceivedCount();
            bytesReceived += remoteStatus.getReceivedContentSize();
            flowFilesSent += remoteStatus.getSentCount();
            bytesSent += remoteStatus.getSentContentSize();
        }
    }
    // connection status
    final Collection<ConnectionStatus> connectionStatusCollection = new ArrayList<>();
    status.setConnectionStatus(connectionStatusCollection);
    // get the connection and remote port status
    for (final Connection conn : group.getConnections()) {
        final boolean isConnectionAuthorized = isAuthorized.evaluate(conn);
        final boolean isSourceAuthorized = isAuthorized.evaluate(conn.getSource());
        final boolean isDestinationAuthorized = isAuthorized.evaluate(conn.getDestination());
        final ConnectionStatus connStatus = new ConnectionStatus();
        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());
            connStatus.setInputCount(connectionStatusReport.getFlowFilesIn());
            connStatus.setOutputBytes(connectionStatusReport.getContentSizeOut());
            connStatus.setOutputCount(connectionStatusReport.getFlowFilesOut());
            flowFilesTransferred += connectionStatusReport.getFlowFilesIn() + connectionStatusReport.getFlowFilesOut();
            bytesTransferred += connectionStatusReport.getContentSizeIn() + connectionStatusReport.getContentSizeOut();
        }
        if (isConnectionAuthorized) {
            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(StringUtils.join(relationships, ", "));
            }
        } else {
            connStatus.setName(conn.getIdentifier());
        }
        final QueueSize queueSize = conn.getFlowFileQueue().size();
        final int connectionQueuedCount = queueSize.getObjectCount();
        final long connectionQueuedBytes = queueSize.getByteCount();
        if (connectionQueuedCount > 0) {
            connStatus.setQueuedBytes(connectionQueuedBytes);
            connStatus.setQueuedCount(connectionQueuedCount);
        }
        connectionStatusCollection.add(connStatus);
        queuedCount += connectionQueuedCount;
        queuedContentSize += connectionQueuedBytes;
        final Connectable source = conn.getSource();
        if (ConnectableType.REMOTE_OUTPUT_PORT.equals(source.getConnectableType())) {
            final RemoteGroupPort remoteOutputPort = (RemoteGroupPort) source;
            activeGroupThreads += processScheduler.getActiveThreadCount(remoteOutputPort);
        }
        final Connectable destination = conn.getDestination();
        if (ConnectableType.REMOTE_INPUT_PORT.equals(destination.getConnectableType())) {
            final RemoteGroupPort remoteInputPort = (RemoteGroupPort) destination;
            activeGroupThreads += processScheduler.getActiveThreadCount(remoteInputPort);
        }
    }
    // status for input ports
    final Collection<PortStatus> inputPortStatusCollection = new ArrayList<>();
    status.setInputPortStatus(inputPortStatusCollection);
    final Set<Port> inputPorts = group.getInputPorts();
    for (final Port port : inputPorts) {
        final boolean isInputPortAuthorized = isAuthorized.evaluate(port);
        final PortStatus portStatus = new PortStatus();
        portStatus.setId(port.getIdentifier());
        portStatus.setGroupId(port.getProcessGroup().getIdentifier());
        portStatus.setName(isInputPortAuthorized ? port.getName() : port.getIdentifier());
        portStatus.setActiveThreadCount(processScheduler.getActiveThreadCount(port));
        // determine the run status
        if (ScheduledState.RUNNING.equals(port.getScheduledState())) {
            portStatus.setRunStatus(RunStatus.Running);
        } else if (ScheduledState.DISABLED.equals(port.getScheduledState())) {
            portStatus.setRunStatus(RunStatus.Disabled);
        } else if (!port.isValid()) {
            portStatus.setRunStatus(RunStatus.Invalid);
        } else {
            portStatus.setRunStatus(RunStatus.Stopped);
        }
        // special handling for root group ports
        if (port instanceof RootGroupPort) {
            final RootGroupPort rootGroupPort = (RootGroupPort) port;
            portStatus.setTransmitting(rootGroupPort.isTransmitting());
        }
        final FlowFileEvent entry = statusReport.getReportEntries().get(port.getIdentifier());
        if (entry == null) {
            portStatus.setInputBytes(0L);
            portStatus.setInputCount(0);
            portStatus.setOutputBytes(0L);
            portStatus.setOutputCount(0);
        } else {
            final int processedCount = entry.getFlowFilesOut();
            final long numProcessedBytes = entry.getContentSizeOut();
            portStatus.setOutputBytes(numProcessedBytes);
            portStatus.setOutputCount(processedCount);
            final int inputCount = entry.getFlowFilesIn();
            final long inputBytes = entry.getContentSizeIn();
            portStatus.setInputBytes(inputBytes);
            portStatus.setInputCount(inputCount);
            flowFilesIn += inputCount;
            bytesIn += inputBytes;
            bytesWritten += entry.getBytesWritten();
            flowFilesReceived += entry.getFlowFilesReceived();
            bytesReceived += entry.getBytesReceived();
        }
        inputPortStatusCollection.add(portStatus);
        activeGroupThreads += portStatus.getActiveThreadCount();
    }
    // status for output ports
    final Collection<PortStatus> outputPortStatusCollection = new ArrayList<>();
    status.setOutputPortStatus(outputPortStatusCollection);
    final Set<Port> outputPorts = group.getOutputPorts();
    for (final Port port : outputPorts) {
        final boolean isOutputPortAuthorized = isAuthorized.evaluate(port);
        final PortStatus portStatus = new PortStatus();
        portStatus.setId(port.getIdentifier());
        portStatus.setGroupId(port.getProcessGroup().getIdentifier());
        portStatus.setName(isOutputPortAuthorized ? port.getName() : port.getIdentifier());
        portStatus.setActiveThreadCount(processScheduler.getActiveThreadCount(port));
        // determine the run status
        if (ScheduledState.RUNNING.equals(port.getScheduledState())) {
            portStatus.setRunStatus(RunStatus.Running);
        } else if (ScheduledState.DISABLED.equals(port.getScheduledState())) {
            portStatus.setRunStatus(RunStatus.Disabled);
        } else if (!port.isValid()) {
            portStatus.setRunStatus(RunStatus.Invalid);
        } else {
            portStatus.setRunStatus(RunStatus.Stopped);
        }
        // special handling for root group ports
        if (port instanceof RootGroupPort) {
            final RootGroupPort rootGroupPort = (RootGroupPort) port;
            portStatus.setTransmitting(rootGroupPort.isTransmitting());
        }
        final FlowFileEvent entry = statusReport.getReportEntries().get(port.getIdentifier());
        if (entry == null) {
            portStatus.setInputBytes(0L);
            portStatus.setInputCount(0);
            portStatus.setOutputBytes(0L);
            portStatus.setOutputCount(0);
        } else {
            final int processedCount = entry.getFlowFilesOut();
            final long numProcessedBytes = entry.getContentSizeOut();
            portStatus.setOutputBytes(numProcessedBytes);
            portStatus.setOutputCount(processedCount);
            final int inputCount = entry.getFlowFilesIn();
            final long inputBytes = entry.getContentSizeIn();
            portStatus.setInputBytes(inputBytes);
            portStatus.setInputCount(inputCount);
            bytesRead += entry.getBytesRead();
            flowFilesOut += entry.getFlowFilesOut();
            bytesOut += entry.getContentSizeOut();
            flowFilesSent = entry.getFlowFilesSent();
            bytesSent += entry.getBytesSent();
        }
        outputPortStatusCollection.add(portStatus);
        activeGroupThreads += portStatus.getActiveThreadCount();
    }
    for (final Funnel funnel : group.getFunnels()) {
        activeGroupThreads += processScheduler.getActiveThreadCount(funnel);
    }
    status.setActiveThreadCount(activeGroupThreads);
    status.setBytesRead(bytesRead);
    status.setBytesWritten(bytesWritten);
    status.setQueuedCount(queuedCount);
    status.setQueuedContentSize(queuedContentSize);
    status.setInputContentSize(bytesIn);
    status.setInputCount(flowFilesIn);
    status.setOutputContentSize(bytesOut);
    status.setOutputCount(flowFilesOut);
    status.setFlowFilesReceived(flowFilesReceived);
    status.setBytesReceived(bytesReceived);
    status.setFlowFilesSent(flowFilesSent);
    status.setBytesSent(bytesSent);
    status.setFlowFilesTransferred(flowFilesTransferred);
    status.setBytesTransferred(bytesTransferred);
    final VersionControlInformation vci = group.getVersionControlInformation();
    if (vci != null && vci.getStatus() != null && vci.getStatus().getState() != null) {
        status.setVersionedFlowState(vci.getStatus().getState());
    }
    return status;
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) StandardRootGroupPort(org.apache.nifi.remote.StandardRootGroupPort) RootGroupPort(org.apache.nifi.remote.RootGroupPort) StandardRootGroupPort(org.apache.nifi.remote.StandardRootGroupPort) LocalPort(org.apache.nifi.connectable.LocalPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) ArrayList(java.util.ArrayList) QueueSize(org.apache.nifi.controller.queue.QueueSize) Connectable(org.apache.nifi.connectable.Connectable) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) StandardRemoteProcessGroup(org.apache.nifi.remote.StandardRemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) StandardConnection(org.apache.nifi.connectable.StandardConnection) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) FlowFileEvent(org.apache.nifi.controller.repository.FlowFileEvent) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) Relationship(org.apache.nifi.processor.Relationship) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) StandardRemoteProcessGroup(org.apache.nifi.remote.StandardRemoteProcessGroup) Collection(java.util.Collection)

Example 32 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class ControllerFacade method setComponentDetails.

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;
    }
}
Also used : Bundle(org.apache.nifi.bundle.Bundle) Arrays(java.util.Arrays) SearchableFields(org.apache.nifi.provenance.SearchableFields) StringUtils(org.apache.commons.lang3.StringUtils) QueueSize(org.apache.nifi.controller.queue.QueueSize) ClassUtils(org.apache.commons.lang3.ClassUtils) ROOT_GROUP_ID_ALIAS(org.apache.nifi.controller.FlowController.ROOT_GROUP_ID_ALIAS) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Map(java.util.Map) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ProvenanceRepository(org.apache.nifi.provenance.ProvenanceRepository) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Connectable(org.apache.nifi.connectable.Connectable) Connection(org.apache.nifi.connectable.Connection) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) Set(java.util.Set) FlowController(org.apache.nifi.controller.FlowController) VariableRegistry(org.apache.nifi.registry.VariableRegistry) AttributeDTO(org.apache.nifi.web.api.dto.provenance.AttributeDTO) ControllerService(org.apache.nifi.controller.ControllerService) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) WebApplicationException(javax.ws.rs.WebApplicationException) ExtensionManager(org.apache.nifi.nar.ExtensionManager) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) ComponentStatusRepository(org.apache.nifi.controller.status.history.ComponentStatusRepository) LineageRequestDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO) ProvenanceRequestDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceRequestDTO) DtoFactory(org.apache.nifi.web.api.dto.DtoFactory) Resource(org.apache.nifi.authorization.Resource) Counter(org.apache.nifi.controller.Counter) ProvenanceEventDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceEventDTO) AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) CollectionUtils(org.apache.commons.collections4.CollectionUtils) TreeSet(java.util.TreeSet) LineageDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO) ArrayList(java.util.ArrayList) ContentAvailability(org.apache.nifi.controller.ContentAvailability) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Relationship(org.apache.nifi.processor.Relationship) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) ProcessGroupCounts(org.apache.nifi.groups.ProcessGroupCounts) ProvenanceDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceDTO) Collator(java.text.Collator) DocumentedTypeDTO(org.apache.nifi.web.api.dto.DocumentedTypeDTO) ContentDirection(org.apache.nifi.controller.repository.claim.ContentDirection) RequestAction(org.apache.nifi.authorization.RequestAction) ProvenanceOptionsDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceOptionsDTO) IOException(java.io.IOException) Authorizer(org.apache.nifi.authorization.Authorizer) NiFiProperties(org.apache.nifi.util.NiFiProperties) ReportingTask(org.apache.nifi.reporting.ReportingTask) CoreAttributes(org.apache.nifi.flowfile.attributes.CoreAttributes) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessGroup(org.apache.nifi.groups.ProcessGroup) SortedSet(java.util.SortedSet) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Query(org.apache.nifi.provenance.search.Query) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Port(org.apache.nifi.connectable.Port) FlowService(org.apache.nifi.services.FlowService) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ControllerStatusDTO(org.apache.nifi.web.api.dto.status.ControllerStatusDTO) Locale(java.util.Locale) SearchableField(org.apache.nifi.provenance.search.SearchableField) Template(org.apache.nifi.controller.Template) Label(org.apache.nifi.controller.label.Label) ProvenanceSearchableFieldDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceSearchableFieldDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) RequiredPermission(org.apache.nifi.components.RequiredPermission) TimeZone(java.util.TimeZone) Collection(java.util.Collection) BundleUtils(org.apache.nifi.util.BundleUtils) Collectors(java.util.stream.Collectors) ResourceFactory(org.apache.nifi.authorization.resource.ResourceFactory) Processor(org.apache.nifi.processor.Processor) SystemDiagnostics(org.apache.nifi.diagnostics.SystemDiagnostics) List(java.util.List) Result(org.apache.nifi.authorization.AuthorizationResult.Result) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) ProvenanceResultsDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceResultsDTO) SearchTerms(org.apache.nifi.provenance.search.SearchTerms) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) HashMap(java.util.HashMap) Function(java.util.function.Function) HashSet(java.util.HashSet) QueryResult(org.apache.nifi.provenance.search.QueryResult) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) SearchTerm(org.apache.nifi.provenance.search.SearchTerm) QuerySubmission(org.apache.nifi.provenance.search.QuerySubmission) ContentNotFoundException(org.apache.nifi.controller.repository.ContentNotFoundException) Logger(org.slf4j.Logger) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ComputeLineageSubmission(org.apache.nifi.provenance.lineage.ComputeLineageSubmission) FormatUtils(org.apache.nifi.util.FormatUtils) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) PortStatus(org.apache.nifi.controller.status.PortStatus) SearchResultsDTO(org.apache.nifi.web.api.dto.search.SearchResultsDTO) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) DownloadableContent(org.apache.nifi.web.DownloadableContent) LineageRequestType(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO.LineageRequestType) Comparator(java.util.Comparator) Collections(java.util.Collections) InputStream(java.io.InputStream) Connectable(org.apache.nifi.connectable.Connectable) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Relationship(org.apache.nifi.processor.Relationship) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Connection(org.apache.nifi.connectable.Connection)

Example 33 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class StandardConnectionDAO method verifyUpdate.

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();
    }
}
Also used : ValidationException(org.apache.nifi.controller.exception.ValidationException) Connectable(org.apache.nifi.connectable.Connectable)

Example 34 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class StandardConnectionDAO method verifyCreate.

@Override
public void verifyCreate(String groupId, ConnectionDTO connectionDTO) {
    // validate the incoming request
    final List<String> validationErrors = validateProposedConfiguration(groupId, connectionDTO);
    // ensure there was no validation errors
    if (!validationErrors.isEmpty()) {
        throw new ValidationException(validationErrors);
    }
    // Ensure that both the source and the destination for the connection exist.
    // In the case that the source or destination is a port in a Remote Process Group,
    // this is necessary because the ports can change in the background. It may still be
    // possible for a port to disappear between the 'verify' stage and the creation stage,
    // but this prevents the case where some nodes already know about the port while other
    // nodes in the cluster do not. This is a more common case, as users may try to connect
    // to the port as soon as the port is created.
    final ConnectableDTO sourceDto = connectionDTO.getSource();
    if (sourceDto == null || sourceDto.getId() == null) {
        throw new IllegalArgumentException("Cannot create connection without specifying source");
    }
    final ConnectableDTO destinationDto = connectionDTO.getDestination();
    if (destinationDto == null || destinationDto.getId() == null) {
        throw new IllegalArgumentException("Cannot create connection without specifying destination");
    }
    if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceDto.getType())) {
        final ProcessGroup sourceParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = sourceParentGroup.getRemoteProcessGroup(sourceDto.getGroupId());
        if (remoteProcessGroup == null) {
            throw new IllegalArgumentException("Unable to find the specified remote process group.");
        }
        final RemoteGroupPort sourceConnectable = remoteProcessGroup.getOutputPort(sourceDto.getId());
        if (sourceConnectable == null) {
            throw new IllegalArgumentException("The specified source for the connection does not exist");
        } else if (!sourceConnectable.getTargetExists()) {
            throw new IllegalArgumentException("The specified remote output port does not exist.");
        }
    } else {
        final ProcessGroup sourceGroup = locateProcessGroup(flowController, sourceDto.getGroupId());
        final Connectable sourceConnectable = sourceGroup.getConnectable(sourceDto.getId());
        if (sourceConnectable == null) {
            throw new IllegalArgumentException("The specified source for the connection does not exist");
        }
    }
    if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationDto.getType())) {
        final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(destinationDto.getGroupId());
        if (remoteProcessGroup == null) {
            throw new IllegalArgumentException("Unable to find the specified remote process group.");
        }
        final RemoteGroupPort destinationConnectable = remoteProcessGroup.getInputPort(destinationDto.getId());
        if (destinationConnectable == null) {
            throw new IllegalArgumentException("The specified destination for the connection does not exist");
        } else if (!destinationConnectable.getTargetExists()) {
            throw new IllegalArgumentException("The specified remote input port does not exist.");
        }
    } else {
        final ProcessGroup destinationGroup = locateProcessGroup(flowController, destinationDto.getGroupId());
        final Connectable destinationConnectable = destinationGroup.getConnectable(destinationDto.getId());
        if (destinationConnectable == null) {
            throw new IllegalArgumentException("The specified destination for the connection does not exist");
        }
    }
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ValidationException(org.apache.nifi.controller.exception.ValidationException) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connectable(org.apache.nifi.connectable.Connectable) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 35 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class StandardConnectionDAO method createConnection.

@Override
public Connection createConnection(final String groupId, final ConnectionDTO connectionDTO) {
    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    if (isNotNull(connectionDTO.getParentGroupId()) && !flowController.areGroupsSame(connectionDTO.getParentGroupId(), groupId)) {
        throw new IllegalStateException("Cannot specify a different Parent Group ID than the Group to which the Connection is being added");
    }
    // get the source and destination connectables
    final ConnectableDTO sourceConnectableDTO = connectionDTO.getSource();
    final ConnectableDTO destinationConnectableDTO = connectionDTO.getDestination();
    // ensure both are specified
    if (sourceConnectableDTO == null || destinationConnectableDTO == null) {
        throw new IllegalArgumentException("Both source and destinations must be specified.");
    }
    // if the source/destination connectable's group id has not been set, its inferred to be the current group
    if (sourceConnectableDTO.getGroupId() == null) {
        sourceConnectableDTO.setGroupId(groupId);
    }
    if (destinationConnectableDTO.getGroupId() == null) {
        destinationConnectableDTO.setGroupId(groupId);
    }
    // validate the proposed configuration
    final List<String> validationErrors = validateProposedConfiguration(groupId, connectionDTO);
    // ensure there was no validation errors
    if (!validationErrors.isEmpty()) {
        throw new ValidationException(validationErrors);
    }
    // find the source
    final Connectable source;
    if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceConnectableDTO.getType())) {
        final ProcessGroup sourceParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = sourceParentGroup.getRemoteProcessGroup(sourceConnectableDTO.getGroupId());
        source = remoteProcessGroup.getOutputPort(sourceConnectableDTO.getId());
    } else {
        final ProcessGroup sourceGroup = locateProcessGroup(flowController, sourceConnectableDTO.getGroupId());
        source = sourceGroup.getConnectable(sourceConnectableDTO.getId());
    }
    // find the destination
    final Connectable destination;
    if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationConnectableDTO.getType())) {
        final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(destinationConnectableDTO.getGroupId());
        destination = remoteProcessGroup.getInputPort(destinationConnectableDTO.getId());
    } else {
        final ProcessGroup destinationGroup = locateProcessGroup(flowController, destinationConnectableDTO.getGroupId());
        destination = destinationGroup.getConnectable(destinationConnectableDTO.getId());
    }
    // determine the relationships
    final Set<String> relationships = new HashSet<>();
    if (isNotNull(connectionDTO.getSelectedRelationships())) {
        relationships.addAll(connectionDTO.getSelectedRelationships());
    }
    // create the connection
    final Connection connection = flowController.createConnection(connectionDTO.getId(), connectionDTO.getName(), source, destination, relationships);
    // configure the connection
    configureConnection(connection, connectionDTO);
    // add the connection to the group
    group.addConnection(connection);
    return connection;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ValidationException(org.apache.nifi.controller.exception.ValidationException) Connectable(org.apache.nifi.connectable.Connectable) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Connection(org.apache.nifi.connectable.Connection) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) HashSet(java.util.HashSet)

Aggregations

Connectable (org.apache.nifi.connectable.Connectable)35 Connection (org.apache.nifi.connectable.Connection)18 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)12 ProcessGroup (org.apache.nifi.groups.ProcessGroup)12 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)10 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)10 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)9 VersionedConnection (org.apache.nifi.registry.flow.VersionedConnection)9 Relationship (org.apache.nifi.processor.Relationship)8 HashMap (java.util.HashMap)7 Collection (java.util.Collection)6 LinkedHashSet (java.util.LinkedHashSet)6 Funnel (org.apache.nifi.connectable.Funnel)6 Port (org.apache.nifi.connectable.Port)6 ProcessorNode (org.apache.nifi.controller.ProcessorNode)6 RootGroupPort (org.apache.nifi.remote.RootGroupPort)6 IOException (java.io.IOException)5 List (java.util.List)5 VersionedRemoteProcessGroup (org.apache.nifi.registry.flow.VersionedRemoteProcessGroup)5