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);
}
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);
}
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()));
}
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);
}
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);
}
Aggregations