Search in sources :

Example 86 with NodeIdentifier

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

the class AccessPolicyEntityMerger method mergeComponents.

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

Example 87 with NodeIdentifier

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

the class AccessPolicyEntityMerger method mergeDtos.

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

Example 88 with NodeIdentifier

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

the class ControllerServiceEntityMerger method mergeDtos.

private static void mergeDtos(final ControllerServiceDTO clientDto, final Map<NodeIdentifier, ControllerServiceDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    final Set<ControllerServiceReferencingComponentEntity> referencingComponents = clientDto.getReferencingComponents();
    final Map<NodeIdentifier, Set<ControllerServiceReferencingComponentEntity>> nodeReferencingComponentsMap = new HashMap<>();
    final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
    String state = null;
    for (final Map.Entry<NodeIdentifier, ControllerServiceDTO> nodeEntry : dtoMap.entrySet()) {
        final ControllerServiceDTO nodeControllerService = nodeEntry.getValue();
        // consider the node controller service if authorized
        if (nodeControllerService != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            if (state == null) {
                if (ControllerServiceState.DISABLING.name().equals(nodeControllerService.getState())) {
                    state = ControllerServiceState.DISABLING.name();
                } else if (ControllerServiceState.ENABLING.name().equals(nodeControllerService.getState())) {
                    state = ControllerServiceState.ENABLING.name();
                }
            }
            nodeReferencingComponentsMap.put(nodeId, nodeControllerService.getReferencingComponents());
            // merge the validation errors
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeControllerService.getValidationErrors());
            // aggregate the property descriptors
            final Map<String, PropertyDescriptorDTO> descriptors = nodeControllerService.getDescriptors();
            if (descriptors != null) {
                descriptors.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);
        }
    }
    // merge the referencing components
    mergeControllerServiceReferences(referencingComponents, nodeReferencingComponentsMap);
    // store the 'transition' state is applicable
    if (state != null) {
        clientDto.setState(state);
    }
    // set the merged the validation errors
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Also used : PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceReferencingComponentDTO(org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) Collection(java.util.Collection) Map(java.util.Map) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Set(java.util.Set) HashMap(java.util.HashMap) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) Set(java.util.Set) HashMap(java.util.HashMap) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 89 with NodeIdentifier

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

the class ControllerServiceEntityMerger method mergeComponents.

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

Example 90 with NodeIdentifier

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

the class PortEntityMerger method mergeComponents.

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

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