use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class BulletinBoardEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(BulletinBoardDTO clientDto, Map<NodeIdentifier, BulletinBoardDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
final Map<NodeIdentifier, List<BulletinEntity>> bulletinEntities = new HashMap<>();
for (final Map.Entry<NodeIdentifier, BulletinBoardDTO> entry : dtoMap.entrySet()) {
final NodeIdentifier nodeIdentifier = entry.getKey();
final BulletinBoardDTO boardDto = entry.getValue();
boardDto.getBulletins().forEach(bulletin -> {
bulletinEntities.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
});
}
clientDto.setBulletins(BulletinMerger.mergeBulletins(bulletinEntities, dtoMap.size()));
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class ConnectionStatusEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(ConnectionStatusEntity clientEntity, Map<NodeIdentifier, ConnectionStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
final ConnectionStatusDTO mergedConnectionStatus = clientEntity.getConnectionStatus();
mergedConnectionStatus.setNodeSnapshots(new ArrayList<>());
final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
final NodeConnectionStatusSnapshotDTO selectedNodeSnapshot = new NodeConnectionStatusSnapshotDTO();
selectedNodeSnapshot.setStatusSnapshot(mergedConnectionStatus.getAggregateSnapshot().clone());
selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
mergedConnectionStatus.getNodeSnapshots().add(selectedNodeSnapshot);
// merge the other nodes
for (final Map.Entry<NodeIdentifier, ConnectionStatusEntity> entry : entityMap.entrySet()) {
final NodeIdentifier nodeId = entry.getKey();
final ConnectionStatusEntity nodeConnectionStatusEntity = entry.getValue();
final ConnectionStatusDTO nodeConnectionStatus = nodeConnectionStatusEntity.getConnectionStatus();
if (nodeConnectionStatus == mergedConnectionStatus) {
continue;
}
mergeStatus(mergedConnectionStatus, clientEntity.getCanRead(), nodeConnectionStatus, nodeConnectionStatusEntity.getCanRead(), nodeId);
}
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class ConnectionsEndpointMerger method merge.
@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
if (!canHandle(uri, method)) {
throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
}
final ConnectionsEntity responseEntity = clientResponse.getClientResponse().readEntity(ConnectionsEntity.class);
final Set<ConnectionEntity> connectionEntities = responseEntity.getConnections();
final Map<String, Map<NodeIdentifier, ConnectionEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final ConnectionsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ConnectionsEntity.class);
final Set<ConnectionEntity> nodeConnectionEntities = nodeResponseEntity.getConnections();
for (final ConnectionEntity nodeConnectionEntity : nodeConnectionEntities) {
final String nodeConnectionEntityId = nodeConnectionEntity.getId();
Map<NodeIdentifier, ConnectionEntity> innerMap = entityMap.get(nodeConnectionEntityId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeConnectionEntityId, innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodeConnectionEntity);
}
}
ConnectionsEntityMerger.mergeConnections(connectionEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class ControllerServicesEndpointMerger method merge.
@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
if (!canHandle(uri, method)) {
throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
}
final ControllerServicesEntity responseEntity = clientResponse.getClientResponse().readEntity(ControllerServicesEntity.class);
final Set<ControllerServiceEntity> controllerServiceEntities = responseEntity.getControllerServices();
final Map<String, Map<NodeIdentifier, ControllerServiceEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final ControllerServicesEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ControllerServicesEntity.class);
final Set<ControllerServiceEntity> nodeControllerServiceEntities = nodeResponseEntity.getControllerServices();
for (final ControllerServiceEntity nodeControllerServiceEntity : nodeControllerServiceEntities) {
final NodeIdentifier nodeId = nodeResponse.getNodeId();
Map<NodeIdentifier, ControllerServiceEntity> innerMap = entityMap.get(nodeId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeControllerServiceEntity.getId(), innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodeControllerServiceEntity);
}
}
ControllerServicesEntityMerger.mergeControllerServices(controllerServiceEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class CountersEndpointMerger method mergeResponses.
@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());
}
}
Aggregations