use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationClientResource method findClient.
/**
* Retrieve Client by a specified name, or all Clients if no name given
*
* @param name the name of the Client to retrieve, if provided
* @excludeParams automationClient
* @optionalParams name
* @description Returns a single Client or a set of all Clients
* @responseMessage 200 Found and retrieved Client(s)
* @responseMessage 404 Client with given name not found (if name provided)
*/
@Timed
@ExceptionMetered
@GET
public Response findClient(@Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) {
logger.info("Automation ({}) - Looking up a name {}", automationClient.getName(), name);
if (name.isPresent()) {
Client client = clientDAO.getClient(name.get()).orElseThrow(NotFoundException::new);
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
return Response.ok().entity(ClientDetailResponse.fromClient(client, groups, ImmutableList.of())).build();
}
List<ClientDetailResponse> clients = clientDAO.getClients().stream().map(c -> ClientDetailResponse.fromClient(c, ImmutableList.copyOf(aclDAO.getGroupsFor(c)), ImmutableList.of())).collect(toList());
return Response.ok().entity(clients).build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class ClientsResource method deleteClient.
/**
* Delete Client by ID
*
* @excludeParams user
* @param clientId the ID of the Client to be deleted
*
* @description Deletes a single Client if found.
* Used by Keywhiz CLI and the web ui.
* @responseMessage 200 Found and deleted Client with given ID
* @responseMessage 404 Client with given ID not Found
*/
@Path("{clientId}")
@Timed
@ExceptionMetered
@DELETE
public Response deleteClient(@Auth User user, @PathParam("clientId") LongParam clientId) {
logger.info("User '{}' deleting client id={}.", user, clientId);
Optional<Client> client = clientDAO.getClientById(clientId.get());
if (!client.isPresent()) {
throw new NotFoundException("Client not found.");
}
clientDAO.deleteClient(client.get());
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_DELETE, user.getName(), client.get().getName()));
return Response.noContent().build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project metrics by dropwizard.
the class InstrumentedResourceMethodDispatchProvider method create.
@Override
public RequestDispatcher create(AbstractResourceMethod method) {
RequestDispatcher dispatcher = provider.create(method);
if (dispatcher == null) {
return null;
}
if (method.getMethod().isAnnotationPresent(Timed.class)) {
final Timed annotation = method.getMethod().getAnnotation(Timed.class);
final String name = chooseName(annotation.name(), annotation.absolute(), method);
final Timer timer = registry.timer(name);
dispatcher = new TimedRequestDispatcher(dispatcher, timer);
}
if (method.getMethod().isAnnotationPresent(Metered.class)) {
final Metered annotation = method.getMethod().getAnnotation(Metered.class);
final String name = chooseName(annotation.name(), annotation.absolute(), method);
final Meter meter = registry.meter(name);
dispatcher = new MeteredRequestDispatcher(dispatcher, meter);
}
if (method.getMethod().isAnnotationPresent(ExceptionMetered.class)) {
final ExceptionMetered annotation = method.getMethod().getAnnotation(ExceptionMetered.class);
final String name = chooseName(annotation.name(), annotation.absolute(), method, ExceptionMetered.DEFAULT_NAME_SUFFIX);
final Meter meter = registry.meter(name);
dispatcher = new ExceptionMeteredRequestDispatcher(dispatcher, meter, annotation.cause());
}
return dispatcher;
}
use of com.codahale.metrics.annotation.ExceptionMetered in project metrics by dropwizard.
the class InstrumentedResourceMethodApplicationListener method registerExceptionMeteredAnnotations.
private void registerExceptionMeteredAnnotations(final ResourceMethod method, final ExceptionMetered classLevelExceptionMetered) {
final Method definitionMethod = method.getInvocable().getDefinitionMethod();
if (classLevelExceptionMetered != null) {
exceptionMeters.putIfAbsent(definitionMethod, new ExceptionMeterMetric(metrics, method, classLevelExceptionMetered));
return;
}
final ExceptionMetered annotation = definitionMethod.getAnnotation(ExceptionMetered.class);
if (annotation != null) {
exceptionMeters.putIfAbsent(definitionMethod, new ExceptionMeterMetric(metrics, method, annotation));
}
}
use of com.codahale.metrics.annotation.ExceptionMetered in project helios by spotify.
the class HostsResource method hostStatus.
/**
* Returns various status information about the host.
* @param host The host id.
* @param statusFilter An optional status filter.
* @return The host status.
*/
@GET
@Path("{id}/status")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public Optional<HostStatus> hostStatus(@PathParam("id") final String host, @QueryParam("status") @DefaultValue("") final String statusFilter) {
final HostStatus status = model.getHostStatus(host);
final Optional<HostStatus> response;
if (status != null && (isNullOrEmpty(statusFilter) || statusFilter.equals(status.getStatus().toString()))) {
response = Optional.of(status);
} else {
response = Optional.absent();
}
log.debug("hostStatus: host={}, statusFilter={}, returning: {}", host, statusFilter, response);
return response;
}
Aggregations