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);
}
Aggregations