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