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