Search in sources :

Example 1 with MAX_BULLETINS_PER_COMPONENT

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

the class ComponentEntityMerger method merge.

/**
 * Merges the ComponentEntity responses according to their {@link org.apache.nifi.web.api.dto.PermissionsDTO}s.  Responsible for invoking
 * {@link ComponentEntityMerger#mergeComponents(EntityType, Map)}.
 *
 * @param clientEntity the entity being returned to the client
 * @param entityMap    all node responses
 */
@SuppressWarnings("unchecked")
default void merge(final EntityType clientEntity, final Map<NodeIdentifier, EntityType> entityMap) {
    for (final Map.Entry<NodeIdentifier, EntityType> entry : entityMap.entrySet()) {
        final EntityType entity = entry.getValue();
        PermissionsDtoMerger.mergePermissions(clientEntity.getPermissions(), entity.getPermissions());
    }
    if (clientEntity.getPermissions().getCanRead()) {
        final Map<NodeIdentifier, List<BulletinEntity>> bulletinEntities = new HashMap<>();
        for (final Map.Entry<NodeIdentifier, ? extends ComponentEntity> entry : entityMap.entrySet()) {
            final NodeIdentifier nodeIdentifier = entry.getKey();
            final ComponentEntity entity = entry.getValue();
            // consider the bulletins if present and authorized
            if (entity.getBulletins() != null) {
                entity.getBulletins().forEach(bulletin -> {
                    bulletinEntities.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
                });
            }
        }
        clientEntity.setBulletins(BulletinMerger.mergeBulletins(bulletinEntities, entityMap.size()));
        // sort the results
        Collections.sort(clientEntity.getBulletins(), BULLETIN_COMPARATOR);
        // prune the response to only include the max number of bulletins
        if (clientEntity.getBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
            clientEntity.setBulletins(clientEntity.getBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
        }
        mergeComponents(clientEntity, entityMap);
    } else {
        clientEntity.setBulletins(null);
        // unchecked warning suppressed
        clientEntity.setComponent(null);
    }
}
Also used : BULLETIN_COMPARATOR(org.apache.nifi.cluster.manager.BulletinMerger.BULLETIN_COMPARATOR) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) List(java.util.List) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Permissible(org.apache.nifi.web.api.entity.Permissible) 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) HashMap(java.util.HashMap) Collections(java.util.Collections) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with MAX_BULLETINS_PER_COMPONENT

use of org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_PER_COMPONENT 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

ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BULLETIN_COMPARATOR (org.apache.nifi.cluster.manager.BulletinMerger.BULLETIN_COMPARATOR)2 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)2 MAX_BULLETINS_PER_COMPONENT (org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_PER_COMPONENT)2 BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)2 URI (java.net.URI)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 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 MAX_BULLETINS_FOR_CONTROLLER (org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_FOR_CONTROLLER)1 ComponentEntity (org.apache.nifi.web.api.entity.ComponentEntity)1 ControllerBulletinsEntity (org.apache.nifi.web.api.entity.ControllerBulletinsEntity)1 Permissible (org.apache.nifi.web.api.entity.Permissible)1