Search in sources :

Example 1 with NodeJVMDiagnosticsSnapshotDTO

use of org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO 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());
            }
        }
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Set(java.util.Set) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) List(java.util.List) NodeJVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO) ThreadDumpDTO(org.apache.nifi.web.api.dto.diagnostics.ThreadDumpDTO) Map(java.util.Map) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ProcessorDiagnosticsEntity(org.apache.nifi.web.api.entity.ProcessorDiagnosticsEntity) ThreadDumpDTO(org.apache.nifi.web.api.dto.diagnostics.ThreadDumpDTO) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) ArrayList(java.util.ArrayList) NodeJVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO) NodeJVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) ProcessorDiagnosticsEntity(org.apache.nifi.web.api.entity.ProcessorDiagnosticsEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 ControllerServiceDiagnosticsDTO (org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO)1 JVMDiagnosticsSnapshotDTO (org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO)1 NodeJVMDiagnosticsSnapshotDTO (org.apache.nifi.web.api.dto.diagnostics.NodeJVMDiagnosticsSnapshotDTO)1 ProcessorDiagnosticsDTO (org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO)1 ThreadDumpDTO (org.apache.nifi.web.api.dto.diagnostics.ThreadDumpDTO)1 ControllerServiceEntity (org.apache.nifi.web.api.entity.ControllerServiceEntity)1 ProcessorDiagnosticsEntity (org.apache.nifi.web.api.entity.ProcessorDiagnosticsEntity)1