Search in sources :

Example 21 with NodeResponse

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

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

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

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

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

the class FlowMerger method mergeResponses.

@Override
protected void mergeResponses(final ProcessGroupFlowDTO clientDto, final Map<NodeIdentifier, ProcessGroupFlowDTO> dtoMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
    final FlowDTO flowDto = clientDto.getFlow();
    final Set<ConnectionEntity> clientConnections = flowDto.getConnections();
    final Set<ProcessorEntity> clientProcessors = flowDto.getProcessors();
    final Set<PortEntity> clientInputPorts = flowDto.getInputPorts();
    final Set<PortEntity> clientOutputPorts = flowDto.getOutputPorts();
    final Set<RemoteProcessGroupEntity> clientRemoteProcessGroups = flowDto.getRemoteProcessGroups();
    final Set<ProcessGroupEntity> clientProcessGroups = flowDto.getProcessGroups();
    final Set<LabelEntity> clientLabels = flowDto.getLabels();
    final Set<FunnelEntity> clientFunnels = flowDto.getFunnels();
    final Map<String, Map<NodeIdentifier, ConnectionEntity>> connections = new HashMap<>();
    final Map<String, Map<NodeIdentifier, FunnelEntity>> funnels = new HashMap<>();
    final Map<String, Map<NodeIdentifier, PortEntity>> inputPorts = new HashMap<>();
    final Map<String, Map<NodeIdentifier, LabelEntity>> labels = new HashMap<>();
    final Map<String, Map<NodeIdentifier, PortEntity>> outputPorts = new HashMap<>();
    final Map<String, Map<NodeIdentifier, ProcessorEntity>> processors = new HashMap<>();
    final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> rpgs = new HashMap<>();
    final Map<String, Map<NodeIdentifier, ProcessGroupEntity>> processGroups = new HashMap<>();
    // Create mapping of ComponentID -> [nodeId, entity on that node]
    for (final Map.Entry<NodeIdentifier, ProcessGroupFlowDTO> nodeGroupFlowEntry : dtoMap.entrySet()) {
        final NodeIdentifier nodeIdentifier = nodeGroupFlowEntry.getKey();
        final ProcessGroupFlowDTO nodeGroupFlowDto = nodeGroupFlowEntry.getValue();
        final FlowDTO nodeFlowDto = nodeGroupFlowDto.getFlow();
        // Merge connection statuses
        for (final ConnectionEntity entity : nodeFlowDto.getConnections()) {
            connections.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final FunnelEntity entity : nodeFlowDto.getFunnels()) {
            funnels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final PortEntity entity : nodeFlowDto.getInputPorts()) {
            inputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final PortEntity entity : nodeFlowDto.getOutputPorts()) {
            outputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final LabelEntity entity : nodeFlowDto.getLabels()) {
            labels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final ProcessorEntity entity : nodeFlowDto.getProcessors()) {
            processors.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final RemoteProcessGroupEntity entity : nodeFlowDto.getRemoteProcessGroups()) {
            rpgs.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final ProcessGroupEntity entity : nodeFlowDto.getProcessGroups()) {
            processGroups.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
    }
    // 
    // Merge the components that are grouped together by ID
    // 
    // Merge connections
    ConnectionsEntityMerger.mergeConnections(clientConnections, connections);
    // Merge funnel statuses
    FunnelsEntityMerger.mergeFunnels(clientFunnels, funnels);
    // Merge input ports
    PortsEntityMerger.mergePorts(clientInputPorts, inputPorts);
    // Merge output ports
    PortsEntityMerger.mergePorts(clientOutputPorts, outputPorts);
    // Merge labels
    LabelsEntityMerger.mergeLabels(clientLabels, labels);
    // Merge processors
    ProcessorsEntityMerger.mergeProcessors(clientProcessors, processors);
    // Merge Remote Process Groups
    RemoteProcessGroupsEntityMerger.mergeRemoteProcessGroups(clientRemoteProcessGroups, rpgs);
    // Merge Process Groups
    ProcessGroupsEntityMerger.mergeProcessGroups(clientProcessGroups, processGroups);
}
Also used : LabelsEntityMerger(org.apache.nifi.cluster.manager.LabelsEntityMerger) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionsEntityMerger(org.apache.nifi.cluster.manager.ConnectionsEntityMerger) RemoteProcessGroupsEntityMerger(org.apache.nifi.cluster.manager.RemoteProcessGroupsEntityMerger) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) ProcessGroupsEntityMerger(org.apache.nifi.cluster.manager.ProcessGroupsEntityMerger) FunnelsEntityMerger(org.apache.nifi.cluster.manager.FunnelsEntityMerger) Set(java.util.Set) HashMap(java.util.HashMap) PortEntity(org.apache.nifi.web.api.entity.PortEntity) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) PortsEntityMerger(org.apache.nifi.cluster.manager.PortsEntityMerger) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) Map(java.util.Map) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ProcessorsEntityMerger(org.apache.nifi.cluster.manager.ProcessorsEntityMerger) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) URI(java.net.URI) Pattern(java.util.regex.Pattern) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) HashMap(java.util.HashMap) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) PortEntity(org.apache.nifi.web.api.entity.PortEntity) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) HashMap(java.util.HashMap) 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