Search in sources :

Example 26 with ExceptionMetered

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();
}
Also used : PathParam(javax.ws.rs.PathParam) AclDAO(keywhiz.service.daos.AclDAO) Produces(javax.ws.rs.Produces) ClientDAO(keywhiz.service.daos.ClientDAO) GET(javax.ws.rs.GET) Event(keywhiz.log.Event) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) Auth(io.dropwizard.auth.Auth) HashMap(java.util.HashMap) ClientsResource(keywhiz.service.resources.admin.ClientsResource) Inject(javax.inject.Inject) Valid(javax.validation.Valid) AutomationClient(keywhiz.api.model.AutomationClient) ClientDAOFactory(keywhiz.service.daos.ClientDAO.ClientDAOFactory) QueryParam(javax.ws.rs.QueryParam) ImmutableList(com.google.common.collect.ImmutableList) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) Client(keywhiz.api.model.Client) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) DELETE(javax.ws.rs.DELETE) ClientResource(keywhiz.service.resources.automation.v2.ClientResource) AuditLog(keywhiz.log.AuditLog) Group(keywhiz.api.model.Group) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) AclDAOFactory(keywhiz.service.daos.AclDAO.AclDAOFactory) LongParam(io.dropwizard.jersey.params.LongParam) ConflictException(keywhiz.service.exceptions.ConflictException) Instant(java.time.Instant) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) EventTag(keywhiz.log.EventTag) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ClientDetailResponse(keywhiz.api.ClientDetailResponse) CreateClientRequest(keywhiz.api.CreateClientRequest) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Group(keywhiz.api.model.Group) NotFoundException(javax.ws.rs.NotFoundException) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) ClientDetailResponse(keywhiz.api.ClientDetailResponse) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 27 with ExceptionMetered

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();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) Event(keywhiz.log.Event) Client(keywhiz.api.model.Client) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 28 with ExceptionMetered

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;
}
Also used : Metered(com.codahale.metrics.annotation.Metered) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) RequestDispatcher(com.sun.jersey.spi.dispatch.RequestDispatcher)

Example 29 with ExceptionMetered

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));
    }
}
Also used : ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) Method(java.lang.reflect.Method) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 30 with ExceptionMetered

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;
}
Also used : HostStatus(com.spotify.helios.common.descriptors.HostStatus) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)54 Timed (com.codahale.metrics.annotation.Timed)53 Path (javax.ws.rs.Path)36 Event (keywhiz.log.Event)29 HashMap (java.util.HashMap)28 NotFoundException (javax.ws.rs.NotFoundException)27 POST (javax.ws.rs.POST)25 Consumes (javax.ws.rs.Consumes)20 Produces (javax.ws.rs.Produces)20 DELETE (javax.ws.rs.DELETE)18 GET (javax.ws.rs.GET)17 Group (keywhiz.api.model.Group)16 SanitizedSecret (keywhiz.api.model.SanitizedSecret)16 Response (javax.ws.rs.core.Response)12 AutomationClient (keywhiz.api.model.AutomationClient)12 ConflictException (keywhiz.service.exceptions.ConflictException)12 Client (keywhiz.api.model.Client)11 Secret (keywhiz.api.model.Secret)11 URI (java.net.URI)9 PUT (javax.ws.rs.PUT)9