Search in sources :

Example 46 with NodeResponse

use of org.apache.nifi.cluster.manager.NodeResponse in project nifi by apache.

the class AbstractSingleEntityEndpoint 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 EntityType responseEntity = clientResponse.getClientResponse().readEntity(getEntityClass());
    final Map<NodeIdentifier, EntityType> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final EntityType nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(getEntityClass());
        entityMap.put(nodeResponse.getNodeId(), nodeResponseEntity);
    }
    mergeResponses(responseEntity, entityMap, successfulResponses, problematicResponses);
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse)

Example 47 with NodeResponse

use of org.apache.nifi.cluster.manager.NodeResponse 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)

Example 48 with NodeResponse

use of org.apache.nifi.cluster.manager.NodeResponse in project nifi by apache.

the class ControllerServiceReferenceEndpointMerger method merge.

@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, 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 ControllerServiceReferencingComponentsEntity responseEntity = clientResponse.getClientResponse().readEntity(ControllerServiceReferencingComponentsEntity.class);
    final Set<ControllerServiceReferencingComponentEntity> referencingComponents = responseEntity.getControllerServiceReferencingComponents();
    final Map<NodeIdentifier, Set<ControllerServiceReferencingComponentEntity>> resultsMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final ControllerServiceReferencingComponentsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ControllerServiceReferencingComponentsEntity.class);
        final Set<ControllerServiceReferencingComponentEntity> nodeReferencingComponents = nodeResponseEntity.getControllerServiceReferencingComponents();
        resultsMap.put(nodeResponse.getNodeId(), nodeReferencingComponents);
    }
    ControllerServiceEntityMerger.mergeControllerServiceReferences(referencingComponents, resultsMap);
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : ControllerServiceReferencingComponentsEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity) Set(java.util.Set) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse)

Example 49 with NodeResponse

use of org.apache.nifi.cluster.manager.NodeResponse in project nifi by apache.

the class InputPortsEndpointMerger 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 InputPortsEntity responseEntity = clientResponse.getClientResponse().readEntity(InputPortsEntity.class);
    final Set<PortEntity> portEntities = responseEntity.getInputPorts();
    final Map<String, Map<NodeIdentifier, PortEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final InputPortsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(InputPortsEntity.class);
        final Set<PortEntity> nodePortEntities = nodeResponseEntity.getInputPorts();
        for (final PortEntity nodePortEntity : nodePortEntities) {
            final NodeIdentifier nodeId = nodeResponse.getNodeId();
            Map<NodeIdentifier, PortEntity> innerMap = entityMap.get(nodeId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodePortEntity.getId(), innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodePortEntity);
        }
    }
    PortsEntityMerger.mergePorts(portEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : InputPortsEntity(org.apache.nifi.web.api.entity.InputPortsEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) Map(java.util.Map) HashMap(java.util.HashMap) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 50 with NodeResponse

use of org.apache.nifi.cluster.manager.NodeResponse in project nifi by apache.

the class PortStatusEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(PortStatusEntity clientEntity, Map<NodeIdentifier, PortStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final PortStatusDTO mergedPortStatus = clientEntity.getPortStatus();
    mergedPortStatus.setNodeSnapshots(new ArrayList<>());
    final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
    if (selectedNodeId == null) {
        throw new IllegalArgumentException("Attempted to merge Status request but could not find the appropriate Node Identifier");
    }
    final NodePortStatusSnapshotDTO selectedNodeSnapshot = new NodePortStatusSnapshotDTO();
    selectedNodeSnapshot.setStatusSnapshot(mergedPortStatus.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedPortStatus.getNodeSnapshots().add(selectedNodeSnapshot);
    // merge the other nodes
    for (final Map.Entry<NodeIdentifier, PortStatusEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final PortStatusEntity nodePortStatusEntity = entry.getValue();
        final PortStatusDTO nodePortStatus = nodePortStatusEntity.getPortStatus();
        if (nodePortStatus == mergedPortStatus) {
            continue;
        }
        mergeStatus(mergedPortStatus, clientEntity.getCanRead(), nodePortStatus, nodePortStatusEntity.getCanRead(), nodeId);
    }
}
Also used : PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PortStatusEntity(org.apache.nifi.web.api.entity.PortStatusEntity) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) NodePortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO) URI(java.net.URI) Pattern(java.util.regex.Pattern) ComponentEntityStatusMerger(org.apache.nifi.cluster.manager.ComponentEntityStatusMerger) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ArrayList(java.util.ArrayList) NodePortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodePortStatusSnapshotDTO) PortStatusEntity(org.apache.nifi.web.api.entity.PortStatusEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) Map(java.util.Map)

Aggregations

NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)64 HashMap (java.util.HashMap)44 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)44 Map (java.util.Map)38 URI (java.net.URI)32 Set (java.util.Set)23 URISyntaxException (java.net.URISyntaxException)17 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)16 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)15 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 HashSet (java.util.HashSet)12 Collectors (java.util.stream.Collectors)12 Consumes (javax.ws.rs.Consumes)12 GET (javax.ws.rs.GET)12 Produces (javax.ws.rs.Produces)12 Response (javax.ws.rs.core.Response)12 ArrayList (java.util.ArrayList)11 Pattern (java.util.regex.Pattern)11 Path (javax.ws.rs.Path)11