Search in sources :

Example 61 with NodeIdentifier

use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.

the class CurrentUserEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(final CurrentUserEntity clientEntity, final Map<NodeIdentifier, CurrentUserEntity> entityMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
    for (final Map.Entry<NodeIdentifier, CurrentUserEntity> entry : entityMap.entrySet()) {
        final CurrentUserEntity entity = entry.getValue();
        if (entity != clientEntity) {
            mergePermissions(clientEntity.getControllerPermissions(), entity.getControllerPermissions());
            mergePermissions(clientEntity.getCountersPermissions(), entity.getCountersPermissions());
            mergePermissions(clientEntity.getPoliciesPermissions(), entity.getPoliciesPermissions());
            mergePermissions(clientEntity.getProvenancePermissions(), entity.getProvenancePermissions());
            mergePermissions(clientEntity.getTenantsPermissions(), entity.getTenantsPermissions());
            mergePermissions(clientEntity.getSystemPermissions(), entity.getSystemPermissions());
            mergePermissions(clientEntity.getTenantsPermissions(), entity.getTenantsPermissions());
            final Set<ComponentRestrictionPermissionDTO> clientEntityComponentRestrictionsPermissions = clientEntity.getComponentRestrictionPermissions();
            final Set<ComponentRestrictionPermissionDTO> entityComponentRestrictionsPermissions = entity.getComponentRestrictionPermissions();
            // only retain the component restriction permissions in common
            clientEntityComponentRestrictionsPermissions.retainAll(entityComponentRestrictionsPermissions);
            // merge the component restriction permissions
            clientEntityComponentRestrictionsPermissions.forEach(clientEntityPermission -> {
                final ComponentRestrictionPermissionDTO entityPermission = entityComponentRestrictionsPermissions.stream().filter(entityComponentRestrictionsPermission -> {
                    return entityComponentRestrictionsPermission.getRequiredPermission().getId().equals(clientEntityPermission.getRequiredPermission().getId());
                }).findFirst().orElse(null);
                mergePermissions(clientEntityPermission.getPermissions(), entityPermission.getPermissions());
            });
        }
    }
}
Also used : ComponentRestrictionPermissionDTO(org.apache.nifi.web.api.dto.ComponentRestrictionPermissionDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) CurrentUserEntity(org.apache.nifi.web.api.entity.CurrentUserEntity) Map(java.util.Map)

Example 62 with NodeIdentifier

use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.

the class DropRequestEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(DropRequestDTO clientDto, Map<NodeIdentifier, DropRequestDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    boolean nodeWaiting = false;
    int originalCount = 0;
    long originalSize = 0;
    int currentCount = 0;
    long currentSize = 0;
    int droppedCount = 0;
    long droppedSize = 0;
    DropFlowFileState state = null;
    boolean allFinished = true;
    String failureReason = null;
    for (final Map.Entry<NodeIdentifier, DropRequestDTO> nodeEntry : dtoMap.entrySet()) {
        final DropRequestDTO nodeDropRequest = nodeEntry.getValue();
        if (!nodeDropRequest.isFinished()) {
            allFinished = false;
        }
        if (nodeDropRequest.getFailureReason() != null) {
            failureReason = nodeDropRequest.getFailureReason();
        }
        currentCount += nodeDropRequest.getCurrentCount();
        currentSize += nodeDropRequest.getCurrentSize();
        droppedCount += nodeDropRequest.getDroppedCount();
        droppedSize += nodeDropRequest.getDroppedSize();
        if (nodeDropRequest.getOriginalCount() == null) {
            nodeWaiting = true;
        } else {
            originalCount += nodeDropRequest.getOriginalCount();
            originalSize += nodeDropRequest.getOriginalSize();
        }
        final DropFlowFileState nodeState = DropFlowFileState.valueOfDescription(nodeDropRequest.getState());
        if (state == null || state.ordinal() > nodeState.ordinal()) {
            state = nodeState;
        }
    }
    clientDto.setCurrentCount(currentCount);
    clientDto.setCurrentSize(currentSize);
    clientDto.setCurrent(FormatUtils.formatCount(currentCount) + " / " + FormatUtils.formatDataSize(currentSize));
    clientDto.setDroppedCount(droppedCount);
    clientDto.setDroppedSize(droppedSize);
    clientDto.setDropped(FormatUtils.formatCount(droppedCount) + " / " + FormatUtils.formatDataSize(droppedSize));
    clientDto.setFinished(allFinished);
    clientDto.setFailureReason(failureReason);
    if (originalCount == 0) {
        clientDto.setPercentCompleted(allFinished ? 100 : 0);
    } else {
        clientDto.setPercentCompleted((int) ((double) droppedCount / (double) originalCount * 100D));
    }
    if (!nodeWaiting) {
        clientDto.setOriginalCount(originalCount);
        clientDto.setOriginalSize(originalSize);
        clientDto.setOriginal(FormatUtils.formatCount(originalCount) + " / " + FormatUtils.formatDataSize(originalSize));
    }
    if (state != null) {
        clientDto.setState(state.toString());
    }
}
Also used : DropRequestDTO(org.apache.nifi.web.api.dto.DropRequestDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) DropFlowFileState(org.apache.nifi.controller.queue.DropFlowFileState) Map(java.util.Map)

Example 63 with NodeIdentifier

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

Example 64 with NodeIdentifier

use of org.apache.nifi.cluster.protocol.NodeIdentifier 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 65 with NodeIdentifier

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

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