Search in sources :

Example 1 with CounterDTO

use of org.apache.nifi.web.api.dto.CounterDTO 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 CounterDTO

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

the class StatusMerger method merge.

public static void merge(final CountersSnapshotDTO target, final CountersSnapshotDTO toMerge) {
    final Map<String, CounterDTO> counters = new HashMap<>();
    for (final CounterDTO counter : target.getCounters()) {
        counters.put(counter.getId(), counter);
    }
    for (final CounterDTO counter : toMerge.getCounters()) {
        final CounterDTO existing = counters.get(counter.getId());
        if (existing == null) {
            counters.put(counter.getId(), counter);
        } else {
            merge(existing, counter);
        }
    }
    target.setCounters(counters.values());
}
Also used : CounterDTO(org.apache.nifi.web.api.dto.CounterDTO) HashMap(java.util.HashMap)

Example 3 with CounterDTO

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

the class CountersResource method updateCounter.

/**
 * Update the specified counter. This will reset the counter value to 0.
 *
 * @param httpServletRequest request
 * @param id                 The id of the counter.
 * @return A counterEntity.
 */
@PUT
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates the specified counter. This will reset the counter value to 0", notes = NON_GUARANTEED_ENDPOINT, response = CounterEntity.class, authorizations = { @Authorization(value = "Write - /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 = 404, message = "The specified resource could not be found."), @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 updateCounter(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The id of the counter.") @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT);
    }
    final ComponentEntity requestComponentEntity = new ComponentEntity();
    requestComponentEntity.setId(id);
    return withWriteLock(serviceFacade, requestComponentEntity, lookup -> {
        authorizeCounters(RequestAction.WRITE);
    }, null, (componentEntity) -> {
        // reset the specified counter
        final CounterDTO counter = serviceFacade.updateCounter(componentEntity.getId());
        // create the response entity
        final CounterEntity entity = new CounterEntity();
        entity.setCounter(counter);
        // generate the response
        return generateOkResponse(entity).build();
    });
}
Also used : CounterDTO(org.apache.nifi.web.api.dto.CounterDTO) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) CounterEntity(org.apache.nifi.web.api.entity.CounterEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

CounterDTO (org.apache.nifi.web.api.dto.CounterDTO)3 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Counter (org.apache.nifi.controller.Counter)1 CountersDTO (org.apache.nifi.web.api.dto.CountersDTO)1 CountersSnapshotDTO (org.apache.nifi.web.api.dto.CountersSnapshotDTO)1 ComponentEntity (org.apache.nifi.web.api.entity.ComponentEntity)1 CounterEntity (org.apache.nifi.web.api.entity.CounterEntity)1