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;
}
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);
}
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));
}
}
Aggregations