use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class SecretResource method backfillHmac.
/**
* Backfill content hmac for this secret.
*/
@Timed
@ExceptionMetered
@Path("{name}/backfill-hmac")
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public boolean backfillHmac(@Auth AutomationClient automationClient, @PathParam("name") String name, List<String> passwords) {
Optional<SecretSeriesAndContent> secret = secretDAO.getSecretByName(name);
if (!secret.isPresent()) {
return false;
}
logger.info("backfill-hmac {}: processing secret", name);
SecretContent secretContent = secret.get().content();
if (!secretContent.hmac().isEmpty()) {
// No need to backfill
return true;
}
String hmac = cryptographer.computeHmac(cryptographer.decrypt(secretContent.encryptedContent()).getBytes(UTF_8));
// We expect only one row to be changed
return secretSeriesDAO.setHmac(secretContent.id(), hmac) == 1;
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class GroupsResource method createGroup.
/**
* Create Group
*
* @excludeParams user
* @param request the JSON client request used to formulate the Group
*
* @description Creates a Group with the name from a valid group request.
* Used by Keywhiz CLI and the web ui.
* @responseMessage 200 Successfully created Group
* @responseMessage 400 Group with given name already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public Response createGroup(@Auth User user, @Valid CreateGroupRequest request) {
logger.info("User '{}' creating group.", user);
if (groupDAO.getGroup(request.name).isPresent()) {
throw new BadRequestException("Group already exists.");
}
long groupId = groupDAO.createGroup(request.name, user.getName(), nullToEmpty(request.description), request.metadata);
URI uri = UriBuilder.fromResource(GroupsResource.class).build(groupId);
Response response = Response.created(uri).entity(groupDetailResponseFromId(groupId)).build();
if (response.getStatus() == HttpStatus.SC_CREATED) {
Map<String, String> extraInfo = new HashMap<>();
if (request.description != null) {
extraInfo.put("description", request.description);
}
if (request.metadata != null) {
extraInfo.put("metadata", request.metadata.toString());
}
auditLog.recordEvent(new Event(Instant.now(), EventTag.GROUP_CREATE, user.getName(), request.name, extraInfo));
}
return response;
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class SecretsResource method createSecret.
/**
* Create Secret
*
* @excludeParams user
* @param request the JSON client request used to formulate the Secret
*
* @description Creates a Secret with the name from a valid secret request.
* Used by Keywhiz CLI and the web ui.
* @responseMessage 200 Successfully created Secret
* @responseMessage 400 Secret with given name already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public Response createSecret(@Auth User user, @Valid CreateSecretRequest request) {
logger.info("User '{}' creating secret '{}'.", user, request.name);
Secret secret;
try {
SecretController.SecretBuilder builder = secretController.builder(request.name, request.content, user.getName(), request.expiry);
if (request.description != null) {
builder.withDescription(request.description);
}
if (request.metadata != null) {
builder.withMetadata(request.metadata);
}
secret = builder.create();
} catch (DataAccessException e) {
logger.info(format("Cannot create secret %s", request.name), e);
throw new ConflictException(format("Cannot create secret %s.", request.name));
}
URI uri = UriBuilder.fromResource(SecretsResource.class).path("{secretId}").build(secret.getId());
Response response = Response.created(uri).entity(secretDetailResponseFromId(secret.getId())).build();
if (response.getStatus() == HttpStatus.SC_CREATED) {
Map<String, String> extraInfo = new HashMap<>();
if (request.description != null) {
extraInfo.put("description", request.description);
}
if (request.metadata != null) {
extraInfo.put("metadata", request.metadata.toString());
}
extraInfo.put("expiry", Long.toString(request.expiry));
auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_CREATE, user.getName(), request.name, extraInfo));
}
return response;
}
use of com.codahale.metrics.annotation.ExceptionMetered in project dropwizard by dropwizard.
the class TaskServlet method add.
public void add(Task task) {
tasks.put('/' + task.getName(), task);
TaskExecutor taskExecutor = new TaskExecutor(task);
try {
final Method executeMethod = task.getClass().getMethod("execute", Map.class, PrintWriter.class);
if (executeMethod.isAnnotationPresent(Timed.class)) {
final Timed annotation = executeMethod.getAnnotation(Timed.class);
final String name = chooseName(annotation.name(), annotation.absolute(), task);
taskExecutor = new TimedTask(taskExecutor, metricRegistry.timer(name));
}
if (executeMethod.isAnnotationPresent(Metered.class)) {
final Metered annotation = executeMethod.getAnnotation(Metered.class);
final String name = chooseName(annotation.name(), annotation.absolute(), task);
taskExecutor = new MeteredTask(taskExecutor, metricRegistry.meter(name));
}
if (executeMethod.isAnnotationPresent(ExceptionMetered.class)) {
final ExceptionMetered annotation = executeMethod.getAnnotation(ExceptionMetered.class);
final String name = chooseName(annotation.name(), annotation.absolute(), task, ExceptionMetered.DEFAULT_NAME_SUFFIX);
taskExecutor = new ExceptionMeteredTask(taskExecutor, metricRegistry.meter(name), annotation.cause());
}
} catch (NoSuchMethodException ignored) {
}
taskExecutors.put(task, taskExecutor);
}
use of com.codahale.metrics.annotation.ExceptionMetered in project helios by spotify.
the class DeploymentGroupResource method getDeploymentGroupStatus.
@GET
@Path("/{name}/status")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public Response getDeploymentGroupStatus(@PathParam("name") @Valid final String name) {
try {
final DeploymentGroup deploymentGroup = model.getDeploymentGroup(name);
final DeploymentGroupStatus deploymentGroupStatus = model.getDeploymentGroupStatus(name);
final List<String> hosts = model.getDeploymentGroupHosts(name);
final List<DeploymentGroupStatusResponse.HostStatus> result = Lists.newArrayList();
for (final String host : hosts) {
final HostStatus hostStatus = model.getHostStatus(host);
JobId deployedJobId = null;
TaskStatus.State state = null;
if (hostStatus != null && hostStatus.getStatus().equals(HostStatus.Status.UP)) {
for (final Map.Entry<JobId, Deployment> entry : hostStatus.getJobs().entrySet()) {
if (name.equals(entry.getValue().getDeploymentGroupName())) {
deployedJobId = entry.getKey();
final TaskStatus taskStatus = hostStatus.getStatuses().get(deployedJobId);
if (taskStatus != null) {
state = taskStatus.getState();
}
break;
}
}
result.add(new DeploymentGroupStatusResponse.HostStatus(host, deployedJobId, state));
}
}
final DeploymentGroupStatusResponse.Status status;
if (deploymentGroupStatus == null) {
status = DeploymentGroupStatusResponse.Status.IDLE;
} else if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.FAILED) {
status = DeploymentGroupStatusResponse.Status.FAILED;
} else if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.ROLLING_OUT) {
status = DeploymentGroupStatusResponse.Status.ROLLING_OUT;
} else {
status = DeploymentGroupStatusResponse.Status.ACTIVE;
}
final String error = deploymentGroupStatus == null ? "" : deploymentGroupStatus.getError();
return Response.ok(new DeploymentGroupStatusResponse(deploymentGroup, status, error, result, deploymentGroupStatus)).build();
} catch (final DeploymentGroupDoesNotExistException e) {
return Response.status(Response.Status.NOT_FOUND).build();
}
}
Aggregations