Search in sources :

Example 66 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)

Example 67 with ExceptionMetered

use of com.codahale.metrics.annotation.ExceptionMetered in project helios by spotify.

the class JobsResource method post.

/**
 * Create a job given the definition in {@code job}.
 *
 * @param job      The job to create.
 * @param username The user creating the job.
 *
 * @return The response.
 */
@POST
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) {
    final Job.Builder clone = job.toBuilder().setCreatingUser(username).setCreated(clock.now().getMillis()).setHash(job.getId().getHash());
    final Job actualJob = clone.build();
    final Collection<String> errors = jobValidator.validate(actualJob);
    final String jobIdString = actualJob.getId().toString();
    if (!errors.isEmpty()) {
        throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors), jobIdString));
    }
    try {
        model.addJob(actualJob);
    } catch (JobExistsException e) {
        throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(), jobIdString));
    }
    log.info("created job: {}", actualJob);
    return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(), jobIdString);
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) JobExistsException(com.spotify.helios.master.JobExistsException) Job(com.spotify.helios.common.descriptors.Job) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 68 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)

Aggregations

ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)68 Timed (com.codahale.metrics.annotation.Timed)66 Path (javax.ws.rs.Path)44 Event (keywhiz.log.Event)38 POST (javax.ws.rs.POST)36 HashMap (java.util.HashMap)34 NotFoundException (javax.ws.rs.NotFoundException)32 Consumes (javax.ws.rs.Consumes)28 Produces (javax.ws.rs.Produces)25 SanitizedSecret (keywhiz.api.model.SanitizedSecret)21 DELETE (javax.ws.rs.DELETE)19 GET (javax.ws.rs.GET)19 Group (keywhiz.api.model.Group)18 Response (javax.ws.rs.core.Response)16 ConflictException (keywhiz.service.exceptions.ConflictException)16 Secret (keywhiz.api.model.Secret)15 URI (java.net.URI)13 AutomationClient (keywhiz.api.model.AutomationClient)13 Client (keywhiz.api.model.Client)12 PUT (javax.ws.rs.PUT)9