Search in sources :

Example 1 with CountersDTO

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

the class StandardNiFiServiceFacade method getCounters.

@Override
public CountersDTO getCounters() {
    final List<Counter> counters = controllerFacade.getCounters();
    final Set<CounterDTO> counterDTOs = new LinkedHashSet<>(counters.size());
    for (final Counter counter : counters) {
        counterDTOs.add(dtoFactory.createCounterDto(counter));
    }
    final CountersSnapshotDTO snapshotDto = dtoFactory.createCountersDto(counterDTOs);
    final CountersDTO countersDto = new CountersDTO();
    countersDto.setAggregateSnapshot(snapshotDto);
    return countersDto;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CounterDTO(org.apache.nifi.web.api.dto.CounterDTO) Counter(org.apache.nifi.controller.Counter) CountersDTO(org.apache.nifi.web.api.dto.CountersDTO) CountersSnapshotDTO(org.apache.nifi.web.api.dto.CountersSnapshotDTO)

Example 2 with CountersDTO

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

the class CountersResource method getCounters.

/**
 * Retrieves the counters report for this NiFi.
 *
 * @return A countersEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
// necessary due to a bug in swagger
@Path("")
@ApiOperation(value = "Gets the current counters for this NiFi", notes = NON_GUARANTEED_ENDPOINT, response = CountersEntity.class, authorizations = { @Authorization(value = "Read - /counters") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getCounters(@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 {
    authorizeCounters(RequestAction.READ);
    // ensure a valid request
    if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) {
        throw new IllegalArgumentException("Nodewise requests cannot be directed at a specific node.");
    }
    // replicate if necessary
    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 CountersEntity entity = (CountersEntity) nodeResponse.getUpdatedEntity();
            // ensure there is an updated entity (result of merging) and prune the response as necessary
            if (entity != null && !nodewise) {
                entity.getCounters().setNodeSnapshots(null);
            }
            return nodeResponse.getResponse();
        } else {
            // get the target node and ensure it exists
            final NodeIdentifier targetNode = getClusterCoordinator().getNodeIdentifier(clusterNodeId);
            if (targetNode == null) {
                throw new UnknownNodeException("The specified cluster node does not exist.");
            }
            return replicate(HttpMethod.GET, targetNode);
        }
    }
    final CountersDTO countersReport = serviceFacade.getCounters();
    // create the response entity
    final CountersEntity entity = new CountersEntity();
    entity.setCounters(countersReport);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : UnknownNodeException(org.apache.nifi.cluster.manager.exception.UnknownNodeException) CountersEntity(org.apache.nifi.web.api.entity.CountersEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) CountersDTO(org.apache.nifi.web.api.dto.CountersDTO) Path(javax.ws.rs.Path) 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 3 with CountersDTO

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

the class CountersEndpointMerger method mergeResponses.

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

Aggregations

CountersDTO (org.apache.nifi.web.api.dto.CountersDTO)3 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 UnknownNodeException (org.apache.nifi.cluster.manager.exception.UnknownNodeException)1 Counter (org.apache.nifi.controller.Counter)1 CounterDTO (org.apache.nifi.web.api.dto.CounterDTO)1 CountersSnapshotDTO (org.apache.nifi.web.api.dto.CountersSnapshotDTO)1 NodeCountersSnapshotDTO (org.apache.nifi.web.api.dto.NodeCountersSnapshotDTO)1 CountersEntity (org.apache.nifi.web.api.entity.CountersEntity)1