Search in sources :

Example 1 with SystemDiagnosticsDTO

use of org.apache.nifi.web.api.dto.SystemDiagnosticsDTO in project nifi by apache.

the class SystemDiagnosticsResource method getSystemDiagnostics.

/**
 * Gets the system diagnostics for this NiFi instance.
 *
 * @return A systemDiagnosticsEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the diagnostics for the system NiFi is running on", response = SystemDiagnosticsEntity.class, authorizations = { @Authorization(value = "Read - /system") })
@ApiResponses(value = { @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request.") })
public Response getSystemDiagnostics(@ApiParam(value = "Whether or not to include the breakdown per node. Optional, defaults to false", required = false) @QueryParam("nodewise") @DefaultValue(NODEWISE) final Boolean nodewise, @ApiParam(value = "The id of the node where to get the status.", required = false) @QueryParam("clusterNodeId") final String clusterNodeId) throws InterruptedException {
    authorizeSystem();
    // ensure a valid request
    if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) {
        throw new IllegalArgumentException("Nodewise requests cannot be directed at a specific node.");
    }
    if (isReplicateRequest()) {
        // determine where this request should be sent
        if (clusterNodeId == null) {
            final NodeResponse nodeResponse;
            // to the cluster nodes themselves.
            if (getReplicationTarget() == ReplicationTarget.CLUSTER_NODES) {
                nodeResponse = getRequestReplicator().replicate(HttpMethod.GET, getAbsolutePath(), getRequestParameters(), getHeaders()).awaitMergedResponse();
            } else {
                nodeResponse = getRequestReplicator().forwardToCoordinator(getClusterCoordinatorNode(), HttpMethod.GET, getAbsolutePath(), getRequestParameters(), getHeaders()).awaitMergedResponse();
            }
            final SystemDiagnosticsEntity entity = (SystemDiagnosticsEntity) nodeResponse.getUpdatedEntity();
            // ensure there is an updated entity (result of merging) and prune the response as necessary
            if (entity != null && !nodewise) {
                entity.getSystemDiagnostics().setNodeSnapshots(null);
            }
            return nodeResponse.getResponse();
        } else {
            return replicate(HttpMethod.GET);
        }
    }
    final SystemDiagnosticsDTO systemDiagnosticsDto = serviceFacade.getSystemDiagnostics();
    // create the response
    final SystemDiagnosticsEntity entity = new SystemDiagnosticsEntity();
    entity.setSystemDiagnostics(systemDiagnosticsDto);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) SystemDiagnosticsEntity(org.apache.nifi.web.api.entity.SystemDiagnosticsEntity) SystemDiagnosticsDTO(org.apache.nifi.web.api.dto.SystemDiagnosticsDTO) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with SystemDiagnosticsDTO

use of org.apache.nifi.web.api.dto.SystemDiagnosticsDTO in project nifi by apache.

the class SystemDiagnosticsEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(SystemDiagnosticsDTO clientDto, Map<NodeIdentifier, SystemDiagnosticsDTO> dtoMap, NodeIdentifier selectedNodeId) {
    final SystemDiagnosticsDTO mergedSystemDiagnostics = clientDto;
    mergedSystemDiagnostics.setNodeSnapshots(new ArrayList<NodeSystemDiagnosticsSnapshotDTO>());
    final NodeSystemDiagnosticsSnapshotDTO selectedNodeSnapshot = new NodeSystemDiagnosticsSnapshotDTO();
    selectedNodeSnapshot.setSnapshot(clientDto.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedSystemDiagnostics.getNodeSnapshots().add(selectedNodeSnapshot);
    for (final Map.Entry<NodeIdentifier, SystemDiagnosticsDTO> entry : dtoMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final SystemDiagnosticsDTO toMerge = entry.getValue();
        if (toMerge == clientDto) {
            continue;
        }
        StatusMerger.merge(mergedSystemDiagnostics, toMerge, nodeId.getId(), nodeId.getApiAddress(), nodeId.getApiPort());
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeSystemDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.NodeSystemDiagnosticsSnapshotDTO) SystemDiagnosticsDTO(org.apache.nifi.web.api.dto.SystemDiagnosticsDTO) Map(java.util.Map)

Aggregations

SystemDiagnosticsDTO (org.apache.nifi.web.api.dto.SystemDiagnosticsDTO)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Map (java.util.Map)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 NodeSystemDiagnosticsSnapshotDTO (org.apache.nifi.web.api.dto.NodeSystemDiagnosticsSnapshotDTO)1 SystemDiagnosticsEntity (org.apache.nifi.web.api.entity.SystemDiagnosticsEntity)1