public static void merge(final CountersDTO target, final CountersDTO toMerge, final String nodeId, final String nodeAddress, final Integer nodeApiPort) { merge(target.getAggregateSnapshot(), toMerge.getAggregateSnapshot()); List<NodeCountersSnapshotDTO> nodeSnapshots = target.getNodeSnapshots(); if (nodeSnapshots == null) { nodeSnapshots = new ArrayList<>(); } final NodeCountersSnapshotDTO nodeCountersSnapshot = new NodeCountersSnapshotDTO(); nodeCountersSnapshot.setNodeId(nodeId); nodeCountersSnapshot.setAddress(nodeAddress); nodeCountersSnapshot.setApiPort(nodeApiPort); nodeCountersSnapshot.setSnapshot(toMerge.getAggregateSnapshot()); nodeSnapshots.add(nodeCountersSnapshot); target.setNodeSnapshots(nodeSnapshots); }
@Override protected void mergeResponses(CountersDTO clientDto, Map<NodeIdentifier, CountersDTO> dtoMap, NodeIdentifier selectedNodeId) { final CountersDTO mergedCounters = clientDto; mergedCounters.setNodeSnapshots(new ArrayList<NodeCountersSnapshotDTO>()); final NodeCountersSnapshotDTO selectedNodeSnapshot = new NodeCountersSnapshotDTO(); selectedNodeSnapshot.setSnapshot(clientDto.getAggregateSnapshot().clone()); selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress()); selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort()); selectedNodeSnapshot.setNodeId(selectedNodeId.getId()); mergedCounters.getNodeSnapshots().add(selectedNodeSnapshot); for (final Map.Entry<NodeIdentifier, CountersDTO> entry : dtoMap.entrySet()) { final NodeIdentifier nodeId = entry.getKey(); final CountersDTO toMerge = entry.getValue(); if (toMerge == clientDto) { continue; } StatusMerger.merge(mergedCounters, toMerge, nodeId.getId(), nodeId.getApiAddress(), nodeId.getApiPort()); } }
@Override public NodeCountersSnapshotDTO clone() { final NodeCountersSnapshotDTO other = new NodeCountersSnapshotDTO(); other.setNodeId(getNodeId()); other.setAddress(getAddress()); other.setApiPort(getApiPort()); other.setSnapshot(getSnapshot().clone()); return other; }