Search in sources :

Example 1 with ConnectionStatusSnapshotEntity

use of org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity in project nifi by apache.

the class EntityFactory method createConnectionStatusSnapshotEntity.

public ConnectionStatusSnapshotEntity createConnectionStatusSnapshotEntity(final ConnectionStatusSnapshotDTO status, final PermissionsDTO permissions) {
    final ConnectionStatusSnapshotEntity entity = new ConnectionStatusSnapshotEntity();
    entity.setId(status.getId());
    entity.setCanRead(permissions.getCanRead());
    // always set the status, as it's always allowed... just need to provide permission context for merging responses
    entity.setConnectionStatusSnapshot(status);
    return entity;
}
Also used : ConnectionStatusSnapshotEntity(org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity)

Example 2 with ConnectionStatusSnapshotEntity

use of org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity in project nifi by apache.

the class StatusMerger method merge.

public static void merge(final ProcessGroupStatusSnapshotDTO target, final boolean targetReadablePermission, final ProcessGroupStatusSnapshotDTO toMerge, final boolean toMergeReadablePermission) {
    if (target == null || toMerge == null) {
        return;
    }
    if (targetReadablePermission && !toMergeReadablePermission) {
        target.setId(toMerge.getId());
        target.setName(toMerge.getName());
    }
    // if the versioned flow state to merge is sync failure allow it to take precedence
    if (VersionedFlowState.SYNC_FAILURE.name().equals(toMerge.getVersionedFlowState())) {
        target.setVersionedFlowState(VersionedFlowState.SYNC_FAILURE.name());
    }
    target.setBytesIn(target.getBytesIn() + toMerge.getBytesIn());
    target.setFlowFilesIn(target.getFlowFilesIn() + toMerge.getFlowFilesIn());
    target.setBytesQueued(target.getBytesQueued() + toMerge.getBytesQueued());
    target.setFlowFilesQueued(target.getFlowFilesQueued() + toMerge.getFlowFilesQueued());
    target.setBytesRead(target.getBytesRead() + toMerge.getBytesRead());
    target.setBytesWritten(target.getBytesWritten() + toMerge.getBytesWritten());
    target.setBytesOut(target.getBytesOut() + toMerge.getBytesOut());
    target.setFlowFilesOut(target.getFlowFilesOut() + toMerge.getFlowFilesOut());
    target.setBytesTransferred(target.getBytesTransferred() + toMerge.getBytesTransferred());
    target.setFlowFilesTransferred(target.getFlowFilesTransferred() + toMerge.getFlowFilesTransferred());
    target.setBytesReceived(target.getBytesReceived() + toMerge.getBytesReceived());
    target.setFlowFilesReceived(target.getFlowFilesReceived() + toMerge.getFlowFilesReceived());
    target.setBytesSent(target.getBytesSent() + toMerge.getBytesSent());
    target.setFlowFilesSent(target.getFlowFilesSent() + toMerge.getFlowFilesSent());
    target.setActiveThreadCount(target.getActiveThreadCount() + toMerge.getActiveThreadCount());
    updatePrettyPrintedFields(target);
    // connection status
    // sort by id
    final Map<String, ConnectionStatusSnapshotEntity> mergedConnectionMap = new HashMap<>();
    for (final ConnectionStatusSnapshotEntity status : replaceNull(target.getConnectionStatusSnapshots())) {
        mergedConnectionMap.put(status.getId(), status);
    }
    for (final ConnectionStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getConnectionStatusSnapshots())) {
        ConnectionStatusSnapshotEntity merged = mergedConnectionMap.get(statusToMerge.getId());
        if (merged == null) {
            mergedConnectionMap.put(statusToMerge.getId(), statusToMerge.clone());
            continue;
        }
        merge(merged, statusToMerge);
    }
    target.setConnectionStatusSnapshots(mergedConnectionMap.values());
    // processor status
    final Map<String, ProcessorStatusSnapshotEntity> mergedProcessorMap = new HashMap<>();
    for (final ProcessorStatusSnapshotEntity status : replaceNull(target.getProcessorStatusSnapshots())) {
        mergedProcessorMap.put(status.getId(), status);
    }
    for (final ProcessorStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getProcessorStatusSnapshots())) {
        ProcessorStatusSnapshotEntity merged = mergedProcessorMap.get(statusToMerge.getId());
        if (merged == null) {
            mergedProcessorMap.put(statusToMerge.getId(), statusToMerge.clone());
            continue;
        }
        merge(merged, statusToMerge);
    }
    target.setProcessorStatusSnapshots(mergedProcessorMap.values());
    // input ports
    final Map<String, PortStatusSnapshotEntity> mergedInputPortMap = new HashMap<>();
    for (final PortStatusSnapshotEntity status : replaceNull(target.getInputPortStatusSnapshots())) {
        mergedInputPortMap.put(status.getId(), status);
    }
    for (final PortStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getInputPortStatusSnapshots())) {
        PortStatusSnapshotEntity merged = mergedInputPortMap.get(statusToMerge.getId());
        if (merged == null) {
            mergedInputPortMap.put(statusToMerge.getId(), statusToMerge.clone());
            continue;
        }
        merge(merged, statusToMerge);
    }
    target.setInputPortStatusSnapshots(mergedInputPortMap.values());
    // output ports
    final Map<String, PortStatusSnapshotEntity> mergedOutputPortMap = new HashMap<>();
    for (final PortStatusSnapshotEntity status : replaceNull(target.getOutputPortStatusSnapshots())) {
        mergedOutputPortMap.put(status.getId(), status);
    }
    for (final PortStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getOutputPortStatusSnapshots())) {
        PortStatusSnapshotEntity merged = mergedOutputPortMap.get(statusToMerge.getId());
        if (merged == null) {
            mergedOutputPortMap.put(statusToMerge.getId(), statusToMerge.clone());
            continue;
        }
        merge(merged, statusToMerge);
    }
    target.setOutputPortStatusSnapshots(mergedOutputPortMap.values());
    // child groups
    final Map<String, ProcessGroupStatusSnapshotEntity> mergedGroupMap = new HashMap<>();
    for (final ProcessGroupStatusSnapshotEntity status : replaceNull(target.getProcessGroupStatusSnapshots())) {
        mergedGroupMap.put(status.getId(), status);
    }
    for (final ProcessGroupStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getProcessGroupStatusSnapshots())) {
        ProcessGroupStatusSnapshotEntity merged = mergedGroupMap.get(statusToMerge.getId());
        if (merged == null) {
            mergedGroupMap.put(statusToMerge.getId(), statusToMerge.clone());
            continue;
        }
        merge(merged, statusToMerge);
    }
    target.setOutputPortStatusSnapshots(mergedOutputPortMap.values());
    // remote groups
    final Map<String, RemoteProcessGroupStatusSnapshotEntity> mergedRemoteGroupMap = new HashMap<>();
    for (final RemoteProcessGroupStatusSnapshotEntity status : replaceNull(target.getRemoteProcessGroupStatusSnapshots())) {
        mergedRemoteGroupMap.put(status.getId(), status);
    }
    for (final RemoteProcessGroupStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getRemoteProcessGroupStatusSnapshots())) {
        RemoteProcessGroupStatusSnapshotEntity merged = mergedRemoteGroupMap.get(statusToMerge.getId());
        if (merged == null) {
            mergedRemoteGroupMap.put(statusToMerge.getId(), statusToMerge.clone());
            continue;
        }
        merge(merged, statusToMerge);
    }
    target.setRemoteProcessGroupStatusSnapshots(mergedRemoteGroupMap.values());
}
Also used : ConnectionStatusSnapshotEntity(org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity) HashMap(java.util.HashMap) ProcessorStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessorStatusSnapshotEntity) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity) ProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusSnapshotEntity) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity) PortStatusSnapshotEntity(org.apache.nifi.web.api.entity.PortStatusSnapshotEntity)

Example 3 with ConnectionStatusSnapshotEntity

use of org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity in project nifi by apache.

the class DtoFactory method createProcessGroupStatusDto.

public ProcessGroupStatusDTO createProcessGroupStatusDto(final ProcessGroup processGroup, final ProcessGroupStatus processGroupStatus) {
    final ProcessGroupStatusDTO processGroupStatusDto = createConciseProcessGroupStatusDto(processGroupStatus);
    final ProcessGroupStatusSnapshotDTO snapshot = processGroupStatusDto.getAggregateSnapshot();
    // processor status
    final Collection<ProcessorStatusSnapshotEntity> processorStatusSnapshotEntities = new ArrayList<>();
    snapshot.setProcessorStatusSnapshots(processorStatusSnapshotEntities);
    final Collection<ProcessorStatus> processorStatusCollection = processGroupStatus.getProcessorStatus();
    if (processorStatusCollection != null) {
        for (final ProcessorStatus processorStatus : processorStatusCollection) {
            final ProcessorStatusDTO processorStatusDto = createProcessorStatusDto(processorStatus);
            final ProcessorNode processor = processGroup.findProcessor(processorStatusDto.getId());
            final PermissionsDTO processorPermissions = createPermissionsDto(processor);
            processorStatusSnapshotEntities.add(entityFactory.createProcessorStatusSnapshotEntity(processorStatusDto.getAggregateSnapshot(), processorPermissions));
        }
    }
    // connection status
    final Collection<ConnectionStatusSnapshotEntity> connectionStatusDtoCollection = new ArrayList<>();
    snapshot.setConnectionStatusSnapshots(connectionStatusDtoCollection);
    final Collection<ConnectionStatus> connectionStatusCollection = processGroupStatus.getConnectionStatus();
    if (connectionStatusCollection != null) {
        for (final ConnectionStatus connectionStatus : connectionStatusCollection) {
            final ConnectionStatusDTO connectionStatusDto = createConnectionStatusDto(connectionStatus);
            final Connection connection = processGroup.findConnection(connectionStatusDto.getId());
            final PermissionsDTO connectionPermissions = createPermissionsDto(connection);
            connectionStatusDtoCollection.add(entityFactory.createConnectionStatusSnapshotEntity(connectionStatusDto.getAggregateSnapshot(), connectionPermissions));
        }
    }
    // local child process groups
    final Collection<ProcessGroupStatusSnapshotEntity> childProcessGroupStatusDtoCollection = new ArrayList<>();
    snapshot.setProcessGroupStatusSnapshots(childProcessGroupStatusDtoCollection);
    final Collection<ProcessGroupStatus> childProcessGroupStatusCollection = processGroupStatus.getProcessGroupStatus();
    if (childProcessGroupStatusCollection != null) {
        for (final ProcessGroupStatus childProcessGroupStatus : childProcessGroupStatusCollection) {
            final ProcessGroupStatusDTO childProcessGroupStatusDto = createProcessGroupStatusDto(processGroup, childProcessGroupStatus);
            final ProcessGroup childProcessGroup = processGroup.findProcessGroup(childProcessGroupStatusDto.getId());
            final PermissionsDTO childProcessGroupPermissions = createPermissionsDto(childProcessGroup);
            childProcessGroupStatusDtoCollection.add(entityFactory.createProcessGroupStatusSnapshotEntity(childProcessGroupStatusDto.getAggregateSnapshot(), childProcessGroupPermissions));
        }
    }
    // remote child process groups
    final Collection<RemoteProcessGroupStatusSnapshotEntity> childRemoteProcessGroupStatusDtoCollection = new ArrayList<>();
    snapshot.setRemoteProcessGroupStatusSnapshots(childRemoteProcessGroupStatusDtoCollection);
    final Collection<RemoteProcessGroupStatus> childRemoteProcessGroupStatusCollection = processGroupStatus.getRemoteProcessGroupStatus();
    if (childRemoteProcessGroupStatusCollection != null) {
        for (final RemoteProcessGroupStatus childRemoteProcessGroupStatus : childRemoteProcessGroupStatusCollection) {
            final RemoteProcessGroupStatusDTO childRemoteProcessGroupStatusDto = createRemoteProcessGroupStatusDto(childRemoteProcessGroupStatus);
            final RemoteProcessGroup remoteProcessGroup = processGroup.findRemoteProcessGroup(childRemoteProcessGroupStatusDto.getId());
            final PermissionsDTO remoteProcessGroupPermissions = createPermissionsDto(remoteProcessGroup);
            childRemoteProcessGroupStatusDtoCollection.add(entityFactory.createRemoteProcessGroupStatusSnapshotEntity(childRemoteProcessGroupStatusDto.getAggregateSnapshot(), remoteProcessGroupPermissions));
        }
    }
    // input ports
    final Collection<PortStatusSnapshotEntity> inputPortStatusDtoCollection = new ArrayList<>();
    snapshot.setInputPortStatusSnapshots(inputPortStatusDtoCollection);
    final Collection<PortStatus> inputPortStatusCollection = processGroupStatus.getInputPortStatus();
    if (inputPortStatusCollection != null) {
        for (final PortStatus portStatus : inputPortStatusCollection) {
            final PortStatusDTO portStatusDto = createPortStatusDto(portStatus);
            final Port inputPort = processGroup.findInputPort(portStatus.getId());
            final PermissionsDTO inputPortPermissions = createPermissionsDto(inputPort);
            inputPortStatusDtoCollection.add(entityFactory.createPortStatusSnapshotEntity(portStatusDto.getAggregateSnapshot(), inputPortPermissions));
        }
    }
    // output ports
    final Collection<PortStatusSnapshotEntity> outputPortStatusDtoCollection = new ArrayList<>();
    snapshot.setOutputPortStatusSnapshots(outputPortStatusDtoCollection);
    final Collection<PortStatus> outputPortStatusCollection = processGroupStatus.getOutputPortStatus();
    if (outputPortStatusCollection != null) {
        for (final PortStatus portStatus : outputPortStatusCollection) {
            final PortStatusDTO portStatusDto = createPortStatusDto(portStatus);
            final Port outputPort = processGroup.findOutputPort(portStatus.getId());
            final PermissionsDTO outputPortPermissions = createPermissionsDto(outputPort);
            outputPortStatusDtoCollection.add(entityFactory.createPortStatusSnapshotEntity(portStatusDto.getAggregateSnapshot(), outputPortPermissions));
        }
    }
    return processGroupStatusDto;
}
Also used : InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) InstantiatedVersionedPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort) ArrayList(java.util.ArrayList) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity) ProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusSnapshotEntity) PortStatusSnapshotEntity(org.apache.nifi.web.api.entity.PortStatusSnapshotEntity) ConnectionStatusSnapshotEntity(org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) InstantiatedVersionedRemoteProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) Connection(org.apache.nifi.connectable.Connection) InstantiatedVersionedConnection(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedConnection) RemoteProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusSnapshotDTO) ProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusSnapshotDTO) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) ProcessorStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessorStatusSnapshotEntity) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) InstantiatedVersionedRemoteProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteProcessGroup) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity)

Aggregations

ConnectionStatusSnapshotEntity (org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity)3 PortStatusSnapshotEntity (org.apache.nifi.web.api.entity.PortStatusSnapshotEntity)2 ProcessGroupStatusSnapshotEntity (org.apache.nifi.web.api.entity.ProcessGroupStatusSnapshotEntity)2 ProcessorStatusSnapshotEntity (org.apache.nifi.web.api.entity.ProcessorStatusSnapshotEntity)2 RemoteProcessGroupStatusSnapshotEntity (org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NodeConnectionStatus (org.apache.nifi.cluster.coordination.node.NodeConnectionStatus)1 Connection (org.apache.nifi.connectable.Connection)1 Port (org.apache.nifi.connectable.Port)1 ProcessorNode (org.apache.nifi.controller.ProcessorNode)1 ConnectionStatus (org.apache.nifi.controller.status.ConnectionStatus)1 PortStatus (org.apache.nifi.controller.status.PortStatus)1 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)1 ProcessorStatus (org.apache.nifi.controller.status.ProcessorStatus)1 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)1 ProcessGroup (org.apache.nifi.groups.ProcessGroup)1 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)1 InstantiatedVersionedConnection (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedConnection)1 InstantiatedVersionedPort (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort)1