Search in sources :

Example 56 with NodeIdentifier

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()));
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Set(java.util.Set) BulletinBoardDTO(org.apache.nifi.web.api.dto.BulletinBoardDTO) HashMap(java.util.HashMap) BulletinBoardEntity(org.apache.nifi.web.api.entity.BulletinBoardEntity) 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) URI(java.net.URI) Pattern(java.util.regex.Pattern) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) HashMap(java.util.HashMap) BulletinBoardDTO(org.apache.nifi.web.api.dto.BulletinBoardDTO) 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 57 with NodeIdentifier

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);
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) URI(java.net.URI) Pattern(java.util.regex.Pattern) NodeConnectionStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeConnectionStatusSnapshotDTO) ComponentEntityStatusMerger(org.apache.nifi.cluster.manager.ComponentEntityStatusMerger) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ArrayList(java.util.ArrayList) NodeConnectionStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeConnectionStatusSnapshotDTO) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map)

Example 58 with NodeIdentifier

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);
}
Also used : ConnectionsEntity(org.apache.nifi.web.api.entity.ConnectionsEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 59 with NodeIdentifier

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);
}
Also used : ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ControllerServicesEntity(org.apache.nifi.web.api.entity.ControllerServicesEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 60 with NodeIdentifier

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());
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeCountersSnapshotDTO(org.apache.nifi.web.api.dto.NodeCountersSnapshotDTO) CountersDTO(org.apache.nifi.web.api.dto.CountersDTO) Map(java.util.Map)

Aggregations

NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)141 HashMap (java.util.HashMap)72 Map (java.util.Map)71 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)42 Test (org.junit.Test)34 Set (java.util.Set)30 URI (java.net.URI)26 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)24 List (java.util.List)18 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)15 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)15 NodeConnectionStatus (org.apache.nifi.cluster.coordination.node.NodeConnectionStatus)14 NiFiProperties (org.apache.nifi.util.NiFiProperties)11 Collections (java.util.Collections)10 Pattern (java.util.regex.Pattern)10 NiFiUserDetails (org.apache.nifi.authorization.user.NiFiUserDetails)10 NiFiAuthenticationToken (org.apache.nifi.web.security.token.NiFiAuthenticationToken)10 Authentication (org.springframework.security.core.Authentication)10 Response (javax.ws.rs.core.Response)9