Search in sources :

Example 26 with NodeIdentifier

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

the class ProcessGroupEntityMerger method merge.

@Override
public void merge(ProcessGroupEntity clientEntity, Map<NodeIdentifier, ProcessGroupEntity> entityMap) {
    ComponentEntityMerger.super.merge(clientEntity, entityMap);
    for (Map.Entry<NodeIdentifier, ProcessGroupEntity> entry : entityMap.entrySet()) {
        final ProcessGroupEntity entityStatus = entry.getValue();
        if (entityStatus != clientEntity) {
            mergeStatus(clientEntity.getStatus(), clientEntity.getPermissions().getCanRead(), entry.getValue().getStatus(), entry.getValue().getPermissions().getCanRead(), entry.getKey());
            mergeVersionControlInformation(clientEntity, entityStatus);
        }
    }
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map)

Example 27 with NodeIdentifier

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

the class ProcessorEntityMerger method mergeComponents.

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

Example 28 with NodeIdentifier

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

the class ProcessorEntityMerger method mergeDtos.

private static void mergeDtos(final ProcessorDTO clientDto, final Map<NodeIdentifier, ProcessorDTO> 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<>();
    for (final Map.Entry<NodeIdentifier, ProcessorDTO> nodeEntry : dtoMap.entrySet()) {
        final ProcessorDTO nodeProcessor = nodeEntry.getValue();
        // merge the validation errors and aggregate the property descriptors, if authorized
        if (nodeProcessor != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            // merge the validation errors
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeProcessor.getValidationErrors());
            // aggregate the property descriptors
            nodeProcessor.getConfig().getDescriptors().values().stream().forEach(propertyDescriptor -> {
                propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor);
            });
            // if any node does not support multiple versions (null or false), make it unavailable
            if (clientDto.getMultipleVersionsAvailable() == null || !Boolean.TRUE.equals(nodeProcessor.getMultipleVersionsAvailable())) {
                clientDto.setMultipleVersionsAvailable(Boolean.FALSE);
            }
        }
    }
    // 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.getConfig().getDescriptors().get(propertyDescriptor.getName());
            PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId);
        }
    }
    // 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) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) Collection(java.util.Collection) Map(java.util.Map) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Set(java.util.Set) HashMap(java.util.HashMap) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Set(java.util.Set) HashMap(java.util.HashMap) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 29 with NodeIdentifier

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

the class PropertyDescriptorDtoMerger method merge.

public static void merge(PropertyDescriptorDTO clientPropertyDescriptor, Map<NodeIdentifier, PropertyDescriptorDTO> dtoMap) {
    final Map<Integer, List<AllowableValueEntity>> allowableValueMap = new HashMap<>();
    // values are guaranteed to be in order, so map each allowable value for each property descriptor across all node IDs to the index of the value in the descriptor's list of allowable values
    for (final Map.Entry<NodeIdentifier, PropertyDescriptorDTO> nodeEntry : dtoMap.entrySet()) {
        final PropertyDescriptorDTO nodePropertyDescriptor = nodeEntry.getValue();
        final List<AllowableValueEntity> nodePropertyDescriptorAllowableValues = nodePropertyDescriptor.getAllowableValues();
        if (nodePropertyDescriptorAllowableValues != null) {
            nodePropertyDescriptorAllowableValues.stream().forEach(allowableValueEntity -> {
                allowableValueMap.computeIfAbsent(nodePropertyDescriptorAllowableValues.indexOf(allowableValueEntity), propertyDescriptorToAllowableValue -> new ArrayList<>()).add(allowableValueEntity);
            });
        }
    }
    // for each AllowableValueEntity in this PropertyDescriptorDTO, get the corresponding AVs previously aggregated and merge them.
    final List<AllowableValueEntity> clientPropertyDescriptorAllowableValues = clientPropertyDescriptor.getAllowableValues();
    if (clientPropertyDescriptorAllowableValues != null) {
        for (AllowableValueEntity clientAllowableValueEntity : clientPropertyDescriptorAllowableValues) {
            AllowableValueEntityMerger.merge(clientAllowableValueEntity, allowableValueMap.get(clientPropertyDescriptorAllowableValues.indexOf(clientAllowableValueEntity)));
        }
    }
}
Also used : List(java.util.List) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) Map(java.util.Map) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 30 with NodeIdentifier

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

the class ReportingTaskEntityMerger method mergeComponents.

/**
 * Merges the ReportingTaskEntity responses.
 *
 * @param clientEntity the entity being returned to the client
 * @param entityMap all node responses
 */
public void mergeComponents(final ReportingTaskEntity clientEntity, final Map<NodeIdentifier, ReportingTaskEntity> entityMap) {
    final ReportingTaskDTO clientDto = clientEntity.getComponent();
    final Map<NodeIdentifier, ReportingTaskDTO> dtoMap = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, ReportingTaskEntity> entry : entityMap.entrySet()) {
        final ReportingTaskEntity nodeReportingTaskEntity = entry.getValue();
        final ReportingTaskDTO nodeReportingTaskDto = nodeReportingTaskEntity.getComponent();
        dtoMap.put(entry.getKey(), nodeReportingTaskDto);
    }
    mergeDtos(clientDto, dtoMap);
}
Also used : 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) ReportingTaskEntity(org.apache.nifi.web.api.entity.ReportingTaskEntity)

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