Search in sources :

Example 1 with StateMapDTO

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

the class ComponentStateEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ComponentStateDTO clientDto, Map<NodeIdentifier, ComponentStateDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    List<StateEntryDTO> localStateEntries = new ArrayList<>();
    int totalStateEntries = 0;
    for (final Map.Entry<NodeIdentifier, ComponentStateDTO> nodeEntry : dtoMap.entrySet()) {
        final ComponentStateDTO nodeComponentState = nodeEntry.getValue();
        final NodeIdentifier nodeId = nodeEntry.getKey();
        final String nodeAddress = nodeId.getApiAddress() + ":" + nodeId.getApiPort();
        final StateMapDTO nodeLocalStateMap = nodeComponentState.getLocalState();
        if (nodeLocalStateMap.getState() != null) {
            totalStateEntries += nodeLocalStateMap.getTotalEntryCount();
            for (final StateEntryDTO nodeStateEntry : nodeLocalStateMap.getState()) {
                if (nodeStateEntry.getClusterNodeId() == null || nodeStateEntry.getClusterNodeAddress() == null) {
                    nodeStateEntry.setClusterNodeId(nodeId.getId());
                    nodeStateEntry.setClusterNodeAddress(nodeAddress);
                }
                localStateEntries.add(nodeStateEntry);
            }
        }
    }
    // ensure appropriate sort
    Collections.sort(localStateEntries, SortedStateUtils.getEntryDtoComparator());
    // sublist if necessary
    if (localStateEntries.size() > SortedStateUtils.MAX_COMPONENT_STATE_ENTRIES) {
        localStateEntries = localStateEntries.subList(0, SortedStateUtils.MAX_COMPONENT_STATE_ENTRIES);
    }
    // add all the local state entries
    clientDto.getLocalState().setTotalEntryCount(totalStateEntries);
    clientDto.getLocalState().setState(localStateEntries);
}
Also used : StateEntryDTO(org.apache.nifi.web.api.dto.StateEntryDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ArrayList(java.util.ArrayList) StateMapDTO(org.apache.nifi.web.api.dto.StateMapDTO) Map(java.util.Map) ComponentStateDTO(org.apache.nifi.web.api.dto.ComponentStateDTO)

Aggregations

ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 ComponentStateDTO (org.apache.nifi.web.api.dto.ComponentStateDTO)1 StateEntryDTO (org.apache.nifi.web.api.dto.StateEntryDTO)1 StateMapDTO (org.apache.nifi.web.api.dto.StateMapDTO)1