Search in sources :

Example 26 with NodeResponse

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

the class FlowSnippetEndpointMerger method merge.

@Override
public NodeResponse merge(final URI uri, final String method, Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
    final FlowEntity responseEntity = clientResponse.getClientResponse().readEntity(FlowEntity.class);
    final FlowDTO flowDto = responseEntity.getFlow();
    if (flowDto == null) {
        return clientResponse;
    } else {
        final Map<String, Map<NodeIdentifier, ProcessorEntity>> processorMap = new HashMap<>();
        final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> remoteProcessGroupMap = new HashMap<>();
        for (final NodeResponse nodeResponse : successfulResponses) {
            final FlowEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(FlowEntity.class);
            final FlowDTO nodeContents = nodeResponseEntity.getFlow();
            for (final ProcessorEntity nodeProcessor : nodeContents.getProcessors()) {
                Map<NodeIdentifier, ProcessorEntity> innerMap = processorMap.computeIfAbsent(nodeProcessor.getId(), id -> new HashMap<>());
                innerMap.put(nodeResponse.getNodeId(), nodeProcessor);
            }
            for (final RemoteProcessGroupEntity nodeRemoteProcessGroup : nodeContents.getRemoteProcessGroups()) {
                Map<NodeIdentifier, RemoteProcessGroupEntity> innerMap = remoteProcessGroupMap.computeIfAbsent(nodeRemoteProcessGroup.getId(), id -> new HashMap<>());
                innerMap.put(nodeResponse.getNodeId(), nodeRemoteProcessGroup);
            }
        }
        final ProcessorEndpointMerger procMerger = new ProcessorEndpointMerger();
        for (final ProcessorEntity processor : flowDto.getProcessors()) {
            final String procId = processor.getId();
            final Map<NodeIdentifier, ProcessorEntity> mergeMap = processorMap.get(procId);
            procMerger.mergeResponses(processor, mergeMap, successfulResponses, problematicResponses);
        }
        final RemoteProcessGroupEndpointMerger rpgMerger = new RemoteProcessGroupEndpointMerger();
        for (final RemoteProcessGroupEntity remoteProcessGroup : flowDto.getRemoteProcessGroups()) {
            final String remoteProcessGroupId = remoteProcessGroup.getId();
            final Map<NodeIdentifier, RemoteProcessGroupEntity> mergeMap = remoteProcessGroupMap.get(remoteProcessGroupId);
            rpgMerger.mergeResponses(remoteProcessGroup, mergeMap, successfulResponses, problematicResponses);
        }
    }
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) HashMap(java.util.HashMap) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap)

Example 27 with NodeResponse

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

the class FunnelsEndpointMerger 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 FunnelsEntity responseEntity = clientResponse.getClientResponse().readEntity(FunnelsEntity.class);
    final Set<FunnelEntity> funnelEntities = responseEntity.getFunnels();
    final Map<String, Map<NodeIdentifier, FunnelEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final FunnelsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(FunnelsEntity.class);
        final Set<FunnelEntity> nodeFunnelEntities = nodeResponseEntity.getFunnels();
        for (final FunnelEntity nodeFunnelEntity : nodeFunnelEntities) {
            final String nodeFunnelEntityId = nodeFunnelEntity.getId();
            Map<NodeIdentifier, FunnelEntity> innerMap = entityMap.get(nodeFunnelEntityId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodeFunnelEntityId, innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodeFunnelEntity);
        }
    }
    FunnelsEntityMerger.mergeFunnels(funnelEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) FunnelsEntity(org.apache.nifi.web.api.entity.FunnelsEntity) 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)

Example 28 with NodeResponse

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

the class GroupStatusEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ProcessGroupStatusEntity clientEntity, Map<NodeIdentifier, ProcessGroupStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final ProcessGroupStatusDTO mergedProcessGroupStatus = clientEntity.getProcessGroupStatus();
    mergedProcessGroupStatus.setNodeSnapshots(new ArrayList<>());
    final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
    final NodeProcessGroupStatusSnapshotDTO selectedNodeSnapshot = new NodeProcessGroupStatusSnapshotDTO();
    selectedNodeSnapshot.setStatusSnapshot(mergedProcessGroupStatus.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedProcessGroupStatus.getNodeSnapshots().add(selectedNodeSnapshot);
    for (final Map.Entry<NodeIdentifier, ProcessGroupStatusEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final ProcessGroupStatusEntity nodeProcessGroupStatusEntity = entry.getValue();
        final ProcessGroupStatusDTO nodeProcessGroupStatus = nodeProcessGroupStatusEntity.getProcessGroupStatus();
        if (nodeProcessGroupStatus == mergedProcessGroupStatus) {
            continue;
        }
        mergeStatus(mergedProcessGroupStatus, clientEntity.getCanRead(), nodeProcessGroupStatus, nodeProcessGroupStatusEntity.getCanRead(), nodeId);
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) NodeProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeProcessGroupStatusSnapshotDTO) ProcessGroupStatusEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusEntity) 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) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessGroupStatusEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusEntity) Map(java.util.Map) NodeProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeProcessGroupStatusSnapshotDTO)

Example 29 with NodeResponse

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

the class LabelsEndpointMerger 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 LabelsEntity responseEntity = clientResponse.getClientResponse().readEntity(LabelsEntity.class);
    final Set<LabelEntity> labelEntities = responseEntity.getLabels();
    final Map<String, Map<NodeIdentifier, LabelEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final LabelsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(LabelsEntity.class);
        final Set<LabelEntity> nodeLabelEntities = nodeResponseEntity.getLabels();
        for (final LabelEntity nodeLabelEntity : nodeLabelEntities) {
            final String nodeLabelEntityId = nodeLabelEntity.getId();
            Map<NodeIdentifier, LabelEntity> innerMap = entityMap.get(nodeLabelEntityId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodeLabelEntityId, innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodeLabelEntity);
        }
    }
    LabelsEntityMerger.mergeLabels(labelEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : LabelsEntity(org.apache.nifi.web.api.entity.LabelsEntity) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) 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)

Example 30 with NodeResponse

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

the class OutputPortsEndpointMerger 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 OutputPortsEntity responseEntity = clientResponse.getClientResponse().readEntity(OutputPortsEntity.class);
    final Set<PortEntity> portEntities = responseEntity.getOutputPorts();
    final Map<String, Map<NodeIdentifier, PortEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final OutputPortsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(OutputPortsEntity.class);
        final Set<PortEntity> nodePortEntities = nodeResponseEntity.getOutputPorts();
        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 : HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) OutputPortsEntity(org.apache.nifi.web.api.entity.OutputPortsEntity) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) Map(java.util.Map) HashMap(java.util.HashMap) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

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