Search in sources :

Example 1 with MAX_BULLETINS_FOR_CONTROLLER

use of org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_FOR_CONTROLLER in project nifi by apache.

the class ControllerBulletinsEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ControllerBulletinsEntity clientEntity, Map<NodeIdentifier, ControllerBulletinsEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final Map<NodeIdentifier, List<BulletinEntity>> bulletinDtos = new HashMap<>();
    final Map<NodeIdentifier, List<BulletinEntity>> controllerServiceBulletinDtos = new HashMap<>();
    final Map<NodeIdentifier, List<BulletinEntity>> reportingTaskBulletinDtos = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, ControllerBulletinsEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeIdentifier = entry.getKey();
        final ControllerBulletinsEntity entity = entry.getValue();
        final String nodeAddress = nodeIdentifier.getApiAddress() + ":" + nodeIdentifier.getApiPort();
        // consider the bulletins if present and authorized
        if (entity.getBulletins() != null) {
            entity.getBulletins().forEach(bulletin -> {
                if (bulletin.getNodeAddress() == null) {
                    bulletin.setNodeAddress(nodeAddress);
                }
                bulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
            });
        }
        if (entity.getControllerServiceBulletins() != null) {
            entity.getControllerServiceBulletins().forEach(bulletin -> {
                if (bulletin.getNodeAddress() == null) {
                    bulletin.setNodeAddress(nodeAddress);
                }
                controllerServiceBulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
            });
        }
        if (entity.getReportingTaskBulletins() != null) {
            entity.getReportingTaskBulletins().forEach(bulletin -> {
                if (bulletin.getNodeAddress() == null) {
                    bulletin.setNodeAddress(nodeAddress);
                }
                reportingTaskBulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
            });
        }
    }
    clientEntity.setBulletins(BulletinMerger.mergeBulletins(bulletinDtos, entityMap.size()));
    clientEntity.setControllerServiceBulletins(BulletinMerger.mergeBulletins(controllerServiceBulletinDtos, entityMap.size()));
    clientEntity.setReportingTaskBulletins(BulletinMerger.mergeBulletins(reportingTaskBulletinDtos, entityMap.size()));
    // sort the bulletins
    Collections.sort(clientEntity.getBulletins(), BULLETIN_COMPARATOR);
    Collections.sort(clientEntity.getControllerServiceBulletins(), BULLETIN_COMPARATOR);
    Collections.sort(clientEntity.getReportingTaskBulletins(), BULLETIN_COMPARATOR);
    // prune the response to only include the max number of bulletins
    if (clientEntity.getBulletins().size() > MAX_BULLETINS_FOR_CONTROLLER) {
        clientEntity.setBulletins(clientEntity.getBulletins().subList(0, MAX_BULLETINS_FOR_CONTROLLER));
    }
    if (clientEntity.getControllerServiceBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
        clientEntity.setControllerServiceBulletins(clientEntity.getControllerServiceBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
    }
    if (clientEntity.getReportingTaskBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
        clientEntity.setReportingTaskBulletins(clientEntity.getReportingTaskBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
    }
}
Also used : ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) BULLETIN_COMPARATOR(org.apache.nifi.cluster.manager.BulletinMerger.BULLETIN_COMPARATOR) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Set(java.util.Set) HashMap(java.util.HashMap) EndpointResponseMerger(org.apache.nifi.cluster.coordination.http.EndpointResponseMerger) ArrayList(java.util.ArrayList) List(java.util.List) BulletinMerger(org.apache.nifi.cluster.manager.BulletinMerger) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Map(java.util.Map) MAX_BULLETINS_PER_COMPONENT(org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_PER_COMPONENT) URI(java.net.URI) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ControllerBulletinsEntity(org.apache.nifi.web.api.entity.ControllerBulletinsEntity) MAX_BULLETINS_FOR_CONTROLLER(org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_FOR_CONTROLLER) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 EndpointResponseMerger (org.apache.nifi.cluster.coordination.http.EndpointResponseMerger)1 BulletinMerger (org.apache.nifi.cluster.manager.BulletinMerger)1 BULLETIN_COMPARATOR (org.apache.nifi.cluster.manager.BulletinMerger.BULLETIN_COMPARATOR)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 MAX_BULLETINS_FOR_CONTROLLER (org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_FOR_CONTROLLER)1 MAX_BULLETINS_PER_COMPONENT (org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_PER_COMPONENT)1 BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)1 ControllerBulletinsEntity (org.apache.nifi.web.api.entity.ControllerBulletinsEntity)1