use of com.codahale.metrics.annotation.ExceptionMetered in project helios by spotify.
the class HostsResource method list.
/**
* Returns the list of hostnames of known hosts/agents.
* @return The list of hostnames.
*/
@GET
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public List<String> list(@QueryParam("namePattern") final String namePattern, @QueryParam("selector") final List<String> hostSelectors) {
List<String> hosts = model.listHosts();
if (namePattern != null) {
final Predicate<String> matchesPattern = Pattern.compile(namePattern).asPredicate();
hosts = hosts.stream().filter(matchesPattern).collect(Collectors.toList());
}
if (!hostSelectors.isEmpty()) {
// check that all supplied selectors are parseable/valid
final List<HostSelector> selectors = hostSelectors.stream().map(selectorStr -> {
final HostSelector parsed = HostSelector.parse(selectorStr);
if (parsed == null) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Invalid host selector: " + selectorStr).build());
}
return parsed;
}).collect(Collectors.toList());
final Map<String, Map<String, String>> hostsAndLabels = getLabels(hosts);
final HostMatcher matcher = new HostMatcher(hostsAndLabels);
hosts = matcher.getMatchingHosts(selectors);
}
return hosts;
}
use of com.codahale.metrics.annotation.ExceptionMetered in project helios by spotify.
the class HostsResource method jobPut.
/**
* Sets the deployment of the job identified by its {@link JobId} on the host named by
* {@code host} to {@code deployment}.
* @param host The host to deploy to.
* @param jobId The job to deploy.
* @param deployment Deployment information.
* @param username The user deploying.
* @param token The authorization token for this deployment.
* @return The response.
*/
@PUT
@Path("/{host}/jobs/{job}")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public JobDeployResponse jobPut(@PathParam("host") final String host, @PathParam("job") final JobId jobId, @Valid final Deployment deployment, @RequestUser final String username, @QueryParam("token") @DefaultValue(EMPTY_TOKEN) final String token) {
if (!jobId.isFullyQualified()) {
throw badRequest(new JobDeployResponse(JobDeployResponse.Status.INVALID_ID, host, jobId));
}
try {
final Deployment actualDeployment = deployment.toBuilder().setDeployerUser(username).build();
model.deployJob(host, actualDeployment, token);
return new JobDeployResponse(JobDeployResponse.Status.OK, host, jobId);
} catch (JobAlreadyDeployedException e) {
throw badRequest(new JobDeployResponse(JobDeployResponse.Status.JOB_ALREADY_DEPLOYED, host, jobId));
} catch (HostNotFoundException e) {
throw badRequest(new JobDeployResponse(JobDeployResponse.Status.HOST_NOT_FOUND, host, jobId));
} catch (JobDoesNotExistException e) {
throw badRequest(new JobDeployResponse(JobDeployResponse.Status.JOB_NOT_FOUND, host, jobId));
} catch (JobPortAllocationConflictException e) {
throw badRequest(new JobDeployResponse(JobDeployResponse.Status.PORT_CONFLICT, host, jobId));
} catch (TokenVerificationException e) {
throw forbidden(new JobDeployResponse(JobDeployResponse.Status.FORBIDDEN, host, jobId));
}
}
use of com.codahale.metrics.annotation.ExceptionMetered in project helios by spotify.
the class HostsResource method put.
/**
* Registers a host with the cluster. The {@code host} is the name of the host. It SHOULD be
* the hostname of the machine. The {@code id} should be a persistent value for the host, but
* initially randomly generated. This way we don't have two machines claiming to be the same
* host: at least by accident.
* @param host The host to register.
* @param id The randomly generated ID for the host.
* @return The response.
*/
@PUT
@Path("{host}")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public Response.Status put(@PathParam("host") final String host, @QueryParam("id") @DefaultValue("") final String id) {
if (isNullOrEmpty(id)) {
throw badRequest(new HostRegisterResponse(HostRegisterResponse.Status.INVALID_ID, host));
}
model.registerHost(host, id);
log.info("added host {}", host);
return Response.Status.OK;
}
use of com.codahale.metrics.annotation.ExceptionMetered in project helios by spotify.
the class VersionResource method versionCheck.
/**
* Given the client version, returns the version status, i.e. whether or not they should be
* compatible or not.
* @param client The client version.
* @return The VersionCheckResponse object.
*/
@GET
@Path("/check")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public VersionCheckResponse versionCheck(@QueryParam("client") @DefaultValue("") final String client) {
final PomVersion serverVersion = PomVersion.parse(Version.POM_VERSION);
final VersionCompatibility.Status status;
if (isNullOrEmpty(client)) {
return new VersionCheckResponse(VersionCompatibility.Status.MISSING, serverVersion, Version.RECOMMENDED_VERSION);
}
final PomVersion clientVersion = PomVersion.parse(client);
status = VersionCompatibility.getStatus(serverVersion, clientVersion);
return new VersionCheckResponse(status, serverVersion, Version.RECOMMENDED_VERSION);
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class GroupResource method deleteGroup.
/**
* Delete a group
*
* @excludeParams automationClient
* @param name Group name to delete
*
* @responseMessage 204 Group deleted
* @responseMessage 404 Group not found
*/
@Timed
@ExceptionMetered
@DELETE
@Path("{name}")
public Response deleteGroup(@Auth AutomationClient automationClient, @PathParam("name") String name) {
Group group = groupDAOReadWrite.getGroup(name).orElseThrow(NotFoundException::new);
// Group memberships are deleted automatically by DB cascading.
groupDAOReadWrite.deleteGroup(group);
auditLog.recordEvent(new Event(Instant.now(), EventTag.GROUP_DELETE, automationClient.getName(), group.getName()));
return Response.noContent().build();
}
Aggregations