Search in sources :

Example 1 with NodePortStatusSnapshotDTO

use of org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO in project nifi by apache.

the class StatusMerger method merge.

public static void merge(final PortStatusDTO target, final boolean targetReadablePermission, final PortStatusDTO toMerge, final boolean toMergeReadablePermission, final String nodeId, final String nodeAddress, final Integer nodeApiPort) {
    if (targetReadablePermission && !toMergeReadablePermission) {
        target.setGroupId(toMerge.getGroupId());
        target.setId(toMerge.getId());
        target.setName(toMerge.getName());
    }
    merge(target.getAggregateSnapshot(), targetReadablePermission, toMerge.getAggregateSnapshot(), toMergeReadablePermission);
    target.setTransmitting(Boolean.TRUE.equals(target.isTransmitting()) || Boolean.TRUE.equals(toMerge.isTransmitting()));
    if (target.getNodeSnapshots() != null) {
        final NodePortStatusSnapshotDTO nodeSnapshot = new NodePortStatusSnapshotDTO();
        nodeSnapshot.setStatusSnapshot(toMerge.getAggregateSnapshot());
        nodeSnapshot.setAddress(nodeAddress);
        nodeSnapshot.setApiPort(nodeApiPort);
        nodeSnapshot.setNodeId(nodeId);
        target.getNodeSnapshots().add(nodeSnapshot);
    }
}
Also used : NodePortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO)

Example 2 with NodePortStatusSnapshotDTO

use of org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO in project nifi by apache.

the class PortStatusEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(PortStatusEntity clientEntity, Map<NodeIdentifier, PortStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final PortStatusDTO mergedPortStatus = clientEntity.getPortStatus();
    mergedPortStatus.setNodeSnapshots(new ArrayList<>());
    final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
    if (selectedNodeId == null) {
        throw new IllegalArgumentException("Attempted to merge Status request but could not find the appropriate Node Identifier");
    }
    final NodePortStatusSnapshotDTO selectedNodeSnapshot = new NodePortStatusSnapshotDTO();
    selectedNodeSnapshot.setStatusSnapshot(mergedPortStatus.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedPortStatus.getNodeSnapshots().add(selectedNodeSnapshot);
    // merge the other nodes
    for (final Map.Entry<NodeIdentifier, PortStatusEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final PortStatusEntity nodePortStatusEntity = entry.getValue();
        final PortStatusDTO nodePortStatus = nodePortStatusEntity.getPortStatus();
        if (nodePortStatus == mergedPortStatus) {
            continue;
        }
        mergeStatus(mergedPortStatus, clientEntity.getCanRead(), nodePortStatus, nodePortStatusEntity.getCanRead(), nodeId);
    }
}
Also used : PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PortStatusEntity(org.apache.nifi.web.api.entity.PortStatusEntity) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) NodePortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO) URI(java.net.URI) Pattern(java.util.regex.Pattern) ComponentEntityStatusMerger(org.apache.nifi.cluster.manager.ComponentEntityStatusMerger) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ArrayList(java.util.ArrayList) NodePortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO) PortStatusEntity(org.apache.nifi.web.api.entity.PortStatusEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) Map(java.util.Map)

Aggregations

NodePortStatusSnapshotDTO (org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 ComponentEntityStatusMerger (org.apache.nifi.cluster.manager.ComponentEntityStatusMerger)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 StatusMerger (org.apache.nifi.cluster.manager.StatusMerger)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 PortStatusDTO (org.apache.nifi.web.api.dto.status.PortStatusDTO)1 PortStatusEntity (org.apache.nifi.web.api.entity.PortStatusEntity)1