use of org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO in project nifi by apache.
the class StandardNiFiServiceFacade method getProcessorDiagnostics.
@Override
public ProcessorDiagnosticsEntity getProcessorDiagnostics(final String id) {
final ProcessorNode processor = processorDAO.getProcessor(id);
final ProcessorStatus processorStatus = controllerFacade.getProcessorStatus(id);
// Generate Processor Diagnostics
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final ProcessorDiagnosticsDTO dto = controllerFacade.getProcessorDiagnostics(processor, processorStatus, bulletinRepository, serviceId -> createControllerServiceEntity(serviceId, user));
// Filter anything out of diagnostics that the user is not authorized to see.
final List<JVMDiagnosticsSnapshotDTO> jvmDiagnosticsSnaphots = new ArrayList<>();
final JVMDiagnosticsDTO jvmDiagnostics = dto.getJvmDiagnostics();
jvmDiagnosticsSnaphots.add(jvmDiagnostics.getAggregateSnapshot());
// filter controller-related information
final boolean canReadController = authorizableLookup.getController().isAuthorized(authorizer, RequestAction.READ, user);
if (!canReadController) {
for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
snapshot.setControllerDiagnostics(null);
}
}
// filter system diagnostics information
final boolean canReadSystem = authorizableLookup.getSystem().isAuthorized(authorizer, RequestAction.READ, user);
if (!canReadSystem) {
for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
snapshot.setSystemDiagnosticsDto(null);
}
}
final boolean canReadFlow = authorizableLookup.getFlow().isAuthorized(authorizer, RequestAction.READ, user);
if (!canReadFlow) {
for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
snapshot.setFlowDiagnosticsDto(null);
}
}
// filter connections
final Predicate<ConnectionDiagnosticsDTO> connectionAuthorized = connectionDiagnostics -> {
final String connectionId = connectionDiagnostics.getConnection().getId();
return authorizableLookup.getConnection(connectionId).getAuthorizable().isAuthorized(authorizer, RequestAction.READ, user);
};
// Filter incoming connections by what user is authorized to READ
final Set<ConnectionDiagnosticsDTO> incoming = dto.getIncomingConnections();
final Set<ConnectionDiagnosticsDTO> filteredIncoming = incoming.stream().filter(connectionAuthorized).collect(Collectors.toSet());
dto.setIncomingConnections(filteredIncoming);
// Filter outgoing connections by what user is authorized to READ
final Set<ConnectionDiagnosticsDTO> outgoing = dto.getOutgoingConnections();
final Set<ConnectionDiagnosticsDTO> filteredOutgoing = outgoing.stream().filter(connectionAuthorized).collect(Collectors.toSet());
dto.setOutgoingConnections(filteredOutgoing);
// Filter out any controller services that are referenced by the Processor
final Set<ControllerServiceDiagnosticsDTO> referencedServices = dto.getReferencedControllerServices();
final Set<ControllerServiceDiagnosticsDTO> filteredReferencedServices = referencedServices.stream().filter(csDiagnostics -> {
final String csId = csDiagnostics.getControllerService().getId();
return authorizableLookup.getControllerService(csId).getAuthorizable().isAuthorized(authorizer, RequestAction.READ, user);
}).map(csDiagnostics -> {
// Filter out any referencing components because those are generally not relevant from this context.
final ControllerServiceDTO serviceDto = csDiagnostics.getControllerService().getComponent();
if (serviceDto != null) {
serviceDto.setReferencingComponents(null);
}
return csDiagnostics;
}).collect(Collectors.toSet());
dto.setReferencedControllerServices(filteredReferencedServices);
final Revision revision = revisionManager.getRevision(id);
final RevisionDTO revisionDto = dtoFactory.createRevisionDTO(revision);
final PermissionsDTO permissionsDto = dtoFactory.createPermissionsDto(processor);
final List<BulletinEntity> bulletins = bulletinRepository.findBulletinsForSource(id).stream().map(bulletin -> dtoFactory.createBulletinDto(bulletin)).map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissionsDto.getCanRead())).collect(Collectors.toList());
final ProcessorStatusDTO processorStatusDto = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processor.getIdentifier()));
return entityFactory.createProcessorDiagnosticsEntity(dto, revisionDto, permissionsDto, processorStatusDto, bulletins);
}
use of org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO 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.web.api.dto.diagnostics.ProcessorDiagnosticsDTO in project nifi by apache.
the class DtoFactory method createProcessorDiagnosticsDto.
/**
* Creates a ProcessorDiagnosticsDTO from the given Processor and status information with some additional supporting information
*
* @param procNode the processor to create diagnostics for
* @param procStatus the status of given processor
* @param bulletinRepo the bulletin repository
* @param flowController flowController
* @param serviceEntityFactory function for creating a ControllerServiceEntity from a given ID
* @return ProcessorDiagnosticsDTO for the given Processor
*/
public ProcessorDiagnosticsDTO createProcessorDiagnosticsDto(final ProcessorNode procNode, final ProcessorStatus procStatus, final BulletinRepository bulletinRepo, final FlowController flowController, final Function<String, ControllerServiceEntity> serviceEntityFactory) {
final ProcessorDiagnosticsDTO procDiagnostics = new ProcessorDiagnosticsDTO();
procDiagnostics.setClassLoaderDiagnostics(createClassLoaderDiagnosticsDto(procNode));
procDiagnostics.setIncomingConnections(procNode.getIncomingConnections().stream().map(this::createConnectionDiagnosticsDto).collect(Collectors.toSet()));
procDiagnostics.setOutgoingConnections(procNode.getConnections().stream().map(this::createConnectionDiagnosticsDto).collect(Collectors.toSet()));
procDiagnostics.setJvmDiagnostics(createJvmDiagnosticsDto(flowController));
procDiagnostics.setProcessor(createProcessorDto(procNode));
procDiagnostics.setProcessorStatus(createProcessorStatusDto(procStatus));
procDiagnostics.setThreadDumps(createThreadDumpDtos(procNode));
final Set<ControllerServiceDiagnosticsDTO> referencedServiceDiagnostics = createReferencedServiceDiagnostics(procNode.getProperties(), flowController, serviceEntityFactory);
procDiagnostics.setReferencedControllerServices(referencedServiceDiagnostics);
return procDiagnostics;
}
Aggregations