Search in sources :

Example 91 with NodeIdentifier

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

the class ProcessorDiagnosticsEntityMerger method mergeComponents.

@Override
public void mergeComponents(final ProcessorDiagnosticsEntity clientEntity, final Map<NodeIdentifier, ProcessorDiagnosticsEntity> entityMap) {
    final ProcessorDiagnosticsDTO clientDto = clientEntity.getComponent();
    final List<NodeJVMDiagnosticsSnapshotDTO> nodeJvmDiagnosticsSnapshots = new ArrayList<>(entityMap.size());
    // before we start merging the values, in the second iteration over the map.
    for (final Map.Entry<NodeIdentifier, ProcessorDiagnosticsEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final ProcessorDiagnosticsEntity diagnosticsEntity = entry.getValue();
        final ProcessorDiagnosticsDTO diagnosticsDto = diagnosticsEntity.getComponent();
        StatusMerger.merge(clientDto.getProcessorStatus(), clientEntity.getPermissions().getCanRead(), diagnosticsDto.getProcessorStatus(), diagnosticsEntity.getPermissions().getCanRead(), nodeId.getId(), nodeId.getApiAddress(), nodeId.getApiPort());
        final NodeJVMDiagnosticsSnapshotDTO nodeJvmDiagnosticsSnapshot = new NodeJVMDiagnosticsSnapshotDTO();
        nodeJvmDiagnosticsSnapshot.setAddress(nodeId.getApiAddress());
        nodeJvmDiagnosticsSnapshot.setApiPort(nodeId.getApiPort());
        nodeJvmDiagnosticsSnapshot.setNodeId(nodeId.getId());
        nodeJvmDiagnosticsSnapshot.setSnapshot(diagnosticsDto.getJvmDiagnostics().getAggregateSnapshot());
        nodeJvmDiagnosticsSnapshots.add(nodeJvmDiagnosticsSnapshot);
    }
    clientDto.getJvmDiagnostics().setNodeSnapshots(nodeJvmDiagnosticsSnapshots);
    // Merge JVM Diagnostics and thread dumps
    final JVMDiagnosticsSnapshotDTO mergedJvmDiagnosticsSnapshot = clientDto.getJvmDiagnostics().getAggregateSnapshot().clone();
    for (final Map.Entry<NodeIdentifier, ProcessorDiagnosticsEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final ProcessorDiagnosticsEntity diagnosticsEntity = entry.getValue();
        if (diagnosticsEntity == clientEntity) {
            for (final ThreadDumpDTO threadDump : clientDto.getThreadDumps()) {
                threadDump.setNodeAddress(nodeId.getApiAddress());
                threadDump.setApiPort(nodeId.getApiPort());
                threadDump.setNodeId(nodeId.getId());
            }
            continue;
        }
        final ProcessorDiagnosticsDTO diagnosticsDto = diagnosticsEntity.getComponent();
        final JVMDiagnosticsSnapshotDTO snapshot = diagnosticsDto.getJvmDiagnostics().getAggregateSnapshot();
        StatusMerger.merge(mergedJvmDiagnosticsSnapshot, snapshot, componentStatusSnapshotMillis);
        final List<ThreadDumpDTO> threadDumps = diagnosticsEntity.getComponent().getThreadDumps();
        for (final ThreadDumpDTO threadDump : threadDumps) {
            threadDump.setNodeAddress(nodeId.getApiAddress());
            threadDump.setApiPort(nodeId.getApiPort());
            threadDump.setNodeId(nodeId.getId());
            clientDto.getThreadDumps().add(threadDump);
        }
    }
    clientDto.getJvmDiagnostics().setAggregateSnapshot(mergedJvmDiagnosticsSnapshot);
    // Merge permissions on referenced controller services
    final Map<String, ControllerServiceEntity> serviceEntityById = clientDto.getReferencedControllerServices().stream().map(diagnosticsDto -> diagnosticsDto.getControllerService()).collect(Collectors.toMap(ControllerServiceEntity::getId, Function.identity()));
    for (final Map.Entry<NodeIdentifier, ProcessorDiagnosticsEntity> entry : entityMap.entrySet()) {
        final ProcessorDiagnosticsEntity procDiagnostics = entry.getValue();
        final Set<ControllerServiceDiagnosticsDTO> serviceDtos = procDiagnostics.getComponent().getReferencedControllerServices();
        for (final ControllerServiceDiagnosticsDTO serviceDto : serviceDtos) {
            final ControllerServiceEntity serviceEntity = serviceDto.getControllerService();
            final ControllerServiceEntity targetEntity = serviceEntityById.get(serviceEntity.getId());
            if (targetEntity != null) {
                PermissionsDtoMerger.mergePermissions(targetEntity.getPermissions(), serviceEntity.getPermissions());
            }
        }
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Set(java.util.Set) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) List(java.util.List) NodeJVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO) ThreadDumpDTO(org.apache.nifi.web.api.dto.diagnostics.ThreadDumpDTO) Map(java.util.Map) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ProcessorDiagnosticsEntity(org.apache.nifi.web.api.entity.ProcessorDiagnosticsEntity) ThreadDumpDTO(org.apache.nifi.web.api.dto.diagnostics.ThreadDumpDTO) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) ArrayList(java.util.ArrayList) NodeJVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO) NodeJVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) ProcessorDiagnosticsEntity(org.apache.nifi.web.api.entity.ProcessorDiagnosticsEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) Map(java.util.Map)

Example 92 with NodeIdentifier

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

the class RemoteProcessGroupEntityMerger method mergeComponents.

/**
 * Merges the RemoteProcessGroupEntity responses.
 *
 * @param clientEntity the entity being returned to the client
 * @param entityMap all node responses
 */
@Override
public void mergeComponents(final RemoteProcessGroupEntity clientEntity, final Map<NodeIdentifier, RemoteProcessGroupEntity> entityMap) {
    final RemoteProcessGroupDTO clientDto = clientEntity.getComponent();
    final Map<NodeIdentifier, RemoteProcessGroupDTO> dtoMap = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, RemoteProcessGroupEntity> entry : entityMap.entrySet()) {
        final RemoteProcessGroupEntity nodeProcEntity = entry.getValue();
        final RemoteProcessGroupDTO nodeProcDto = nodeProcEntity.getComponent();
        dtoMap.put(entry.getKey(), nodeProcDto);
    }
    mergeDtos(clientDto, dtoMap);
}
Also used : HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Map(java.util.Map) HashMap(java.util.HashMap) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity)

Example 93 with NodeIdentifier

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

the class RemoteProcessGroupEntityMerger method mergeDtos.

private static void mergeDtos(final RemoteProcessGroupDTO clientDto, final Map<NodeIdentifier, RemoteProcessGroupDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }
    final RemoteProcessGroupContentsDTO remoteProcessGroupContents = clientDto.getContents();
    final Map<String, Set<NodeIdentifier>> authorizationErrorMap = new HashMap<>();
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    Boolean mergedIsTargetSecure = null;
    Set<RemoteProcessGroupPortDTO> mergedInputPorts = null;
    Set<RemoteProcessGroupPortDTO> mergedOutputPorts = null;
    for (final Map.Entry<NodeIdentifier, RemoteProcessGroupDTO> nodeEntry : dtoMap.entrySet()) {
        final RemoteProcessGroupDTO nodeRemoteProcessGroup = nodeEntry.getValue();
        // consider the node remote process group when authorized
        if (nodeRemoteProcessGroup != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            // merge the authorization errors
            ErrorMerger.mergeErrors(authorizationErrorMap, nodeId, nodeRemoteProcessGroup.getAuthorizationIssues());
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeRemoteProcessGroup.getValidationErrors());
            // use the first target secure flag since they will all be the same
            final Boolean nodeIsTargetSecure = nodeRemoteProcessGroup.isTargetSecure();
            if (mergedIsTargetSecure == null) {
                mergedIsTargetSecure = nodeIsTargetSecure;
            }
            // merge the ports in the contents
            final RemoteProcessGroupContentsDTO nodeRemoteProcessGroupContentsDto = nodeRemoteProcessGroup.getContents();
            if (remoteProcessGroupContents != null && nodeRemoteProcessGroupContentsDto != null) {
                final Set<RemoteProcessGroupPortDTO> nodeInputPorts = nodeRemoteProcessGroupContentsDto.getInputPorts();
                if (nodeInputPorts != null) {
                    if (mergedInputPorts == null) {
                        mergedInputPorts = new HashSet<>(nodeInputPorts);
                    } else {
                        mergedInputPorts.retainAll(nodeInputPorts);
                    }
                }
                final Set<RemoteProcessGroupPortDTO> nodeOutputPorts = nodeRemoteProcessGroupContentsDto.getOutputPorts();
                if (nodeOutputPorts != null) {
                    if (mergedOutputPorts == null) {
                        mergedOutputPorts = new HashSet<>(nodeOutputPorts);
                    } else {
                        mergedOutputPorts.retainAll(nodeOutputPorts);
                    }
                }
            }
        }
    }
    if (remoteProcessGroupContents != null) {
        if (mergedInputPorts != null && !mergedInputPorts.isEmpty()) {
            remoteProcessGroupContents.setInputPorts(mergedInputPorts);
        }
        if (mergedOutputPorts != null && !mergedOutputPorts.isEmpty()) {
            remoteProcessGroupContents.setOutputPorts(mergedOutputPorts);
        }
    }
    if (mergedIsTargetSecure != null) {
        clientDto.setTargetSecure(mergedIsTargetSecure);
    }
    // set the merged the validation errors
    clientDto.setAuthorizationIssues(ErrorMerger.normalizedMergedErrors(authorizationErrorMap, dtoMap.size()));
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap)

Example 94 with NodeIdentifier

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

the class ReportingTaskEntityMerger method mergeDtos.

private static void mergeDtos(final ReportingTaskDTO clientDto, final Map<NodeIdentifier, ReportingTaskDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
    int activeThreadCount = 0;
    for (final Map.Entry<NodeIdentifier, ReportingTaskDTO> nodeEntry : dtoMap.entrySet()) {
        final ReportingTaskDTO nodeReportingTask = nodeEntry.getValue();
        // consider the node reporting task if authorized
        if (nodeReportingTask != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            if (nodeReportingTask.getActiveThreadCount() != null) {
                activeThreadCount += nodeReportingTask.getActiveThreadCount();
            }
            // merge the validation errors
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeReportingTask.getValidationErrors());
            // aggregate the property descriptors
            nodeReportingTask.getDescriptors().values().stream().forEach(propertyDescriptor -> {
                propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor);
            });
        }
    }
    // merge property descriptors
    for (Map<NodeIdentifier, PropertyDescriptorDTO> propertyDescriptorByNodeId : propertyDescriptorMap.values()) {
        final Collection<PropertyDescriptorDTO> nodePropertyDescriptors = propertyDescriptorByNodeId.values();
        if (!nodePropertyDescriptors.isEmpty()) {
            // get the name of the property descriptor and find that descriptor being returned to the client
            final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next();
            final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName());
            PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId);
        }
    }
    // set the merged active thread counts
    clientDto.setActiveThreadCount(activeThreadCount);
    // set the merged the validation errors
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) ReportingTaskEntity(org.apache.nifi.web.api.entity.ReportingTaskEntity) Collection(java.util.Collection) Map(java.util.Map) Set(java.util.Set) HashMap(java.util.HashMap) ReportingTaskDTO(org.apache.nifi.web.api.dto.ReportingTaskDTO) Set(java.util.Set) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ReportingTaskDTO(org.apache.nifi.web.api.dto.ReportingTaskDTO) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 95 with NodeIdentifier

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

the class UserEntityMerger method mergeDtos.

private static void mergeDtos(final UserDTO clientDto, final Map<NodeIdentifier, UserDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }
    final Set<AccessPolicySummaryEntity> accessPolicyEntities = new HashSet<>(clientDto.getAccessPolicies());
    final Set<TenantEntity> tenantEntities = new HashSet<>(clientDto.getUserGroups());
    for (final Map.Entry<NodeIdentifier, UserDTO> nodeEntry : dtoMap.entrySet()) {
        final UserDTO nodeUser = nodeEntry.getValue();
        if (nodeUser != null) {
            accessPolicyEntities.retainAll(nodeUser.getAccessPolicies());
            tenantEntities.retainAll(nodeUser.getUserGroups());
        }
    }
    clientDto.setAccessPolicies(accessPolicyEntities);
    clientDto.setUserGroups(tenantEntities);
}
Also used : TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) UserDTO(org.apache.nifi.web.api.dto.UserDTO) Map(java.util.Map) HashMap(java.util.HashMap) AccessPolicySummaryEntity(org.apache.nifi.web.api.entity.AccessPolicySummaryEntity) HashSet(java.util.HashSet)

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