Search in sources :

Example 51 with NotFoundException

use of javax.ws.rs.NotFoundException in project keywhiz by square.

the class ClientsResource method clientDetailResponseFromId.

private ClientDetailResponse clientDetailResponseFromId(long clientId) {
    Optional<Client> optionalClient = clientDAO.getClientById(clientId);
    if (!optionalClient.isPresent()) {
        throw new NotFoundException("Client not found.");
    }
    Client client = optionalClient.get();
    ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
    ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(client));
    return ClientDetailResponse.fromClient(client, groups, sanitizedSecrets);
}
Also used : Group(keywhiz.api.model.Group) SanitizedSecret(keywhiz.api.model.SanitizedSecret) NotFoundException(javax.ws.rs.NotFoundException) Client(keywhiz.api.model.Client)

Example 52 with NotFoundException

use of javax.ws.rs.NotFoundException in project keywhiz by square.

the class SecretsResourceTest method rollbackThrowsException.

@Test(expected = NotFoundException.class)
public void rollbackThrowsException() {
    doThrow(new NotFoundException()).when(secretDAO).setCurrentSecretVersionByName(eq("name2"), anyLong());
    resource.resetSecretVersion(user, "name2", new LongParam("125"));
}
Also used : LongParam(io.dropwizard.jersey.params.LongParam) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.Test)

Example 53 with NotFoundException

use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.

the class MetricsResource method singleMetric.

@GET
@Timed
@Path("/{metricName}")
@ApiOperation(value = "Get a single metric")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric") })
@Produces(MediaType.APPLICATION_JSON)
public Metric singleMetric(@ApiParam(name = "metricName", required = true) @PathParam("metricName") String metricName) {
    checkPermission(RestPermissions.METRICS_READ, metricName);
    final Metric metric = metricRegistry.getMetrics().get(metricName);
    if (metric == null) {
        final String msg = "I do not have a metric called [" + metricName + "].";
        LOG.debug(msg);
        throw new NotFoundException(msg);
    }
    return metric;
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) Metric(com.codahale.metrics.Metric) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 54 with NotFoundException

use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.

the class MetricsResource method byNamespace.

@GET
@Timed
@Path("/namespace/{namespace}")
@ApiOperation(value = "Get all metrics of a namespace")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric namespace") })
@Produces(MediaType.APPLICATION_JSON)
public MetricsSummaryResponse byNamespace(@ApiParam(name = "namespace", required = true) @PathParam("namespace") String namespace) {
    final List<Map<String, Object>> metrics = Lists.newArrayList();
    for (Map.Entry<String, Metric> e : metricRegistry.getMetrics().entrySet()) {
        final String metricName = e.getKey();
        if (metricName.startsWith(namespace) && isPermitted(RestPermissions.METRICS_READ, metricName)) {
            try {
                final Metric metric = e.getValue();
                metrics.add(MetricUtils.map(metricName, metric));
            } catch (Exception ex) {
                LOG.warn("Could not read metric in namespace list.", ex);
            }
        }
    }
    if (metrics.isEmpty()) {
        final String msg = "No metrics with namespace [" + namespace + "] found.";
        LOG.debug(msg);
        throw new NotFoundException(msg);
    }
    return MetricsSummaryResponse.create(metrics);
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) Metric(com.codahale.metrics.Metric) Map(java.util.Map) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 55 with NotFoundException

use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.

the class IndexSetsResource method delete.

@DELETE
@Path("{id}")
@Timed
@ApiOperation(value = "Delete index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_DELETE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public void delete(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "delete_indices") @QueryParam("delete_indices") @DefaultValue("true") boolean deleteIndices) {
    checkPermission(RestPermissions.INDEXSETS_DELETE, id);
    final IndexSet indexSet = getIndexSet(indexSetRegistry, id);
    final IndexSet defaultIndexSet = indexSetRegistry.getDefault();
    if (indexSet.equals(defaultIndexSet)) {
        throw new BadRequestException("Default index set <" + indexSet.getConfig().id() + "> cannot be deleted!");
    }
    if (indexSetService.delete(id) == 0) {
        throw new NotFoundException("Couldn't delete index set with ID <" + id + ">");
    } else {
        if (deleteIndices) {
            try {
                systemJobManager.submit(indexSetCleanupJobFactory.create(indexSet));
            } catch (SystemJobConcurrencyException e) {
                LOG.error("Error running system job", e);
            }
        }
    }
}
Also used : SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NotFoundException (javax.ws.rs.NotFoundException)68 Path (javax.ws.rs.Path)46 Timed (com.codahale.metrics.annotation.Timed)45 ApiOperation (io.swagger.annotations.ApiOperation)27 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)25 GET (javax.ws.rs.GET)22 ApiResponses (io.swagger.annotations.ApiResponses)20 DELETE (javax.ws.rs.DELETE)20 Produces (javax.ws.rs.Produces)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)16 HashMap (java.util.HashMap)15 PUT (javax.ws.rs.PUT)15 Group (keywhiz.api.model.Group)14 SanitizedSecret (keywhiz.api.model.SanitizedSecret)14 Event (keywhiz.log.Event)14 Consumes (javax.ws.rs.Consumes)12 Client (keywhiz.api.model.Client)11 POST (javax.ws.rs.POST)10 BadRequestException (javax.ws.rs.BadRequestException)9 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)9