Search in sources :

Example 6 with IndexStatistics

use of org.graylog2.indexer.indices.IndexStatistics in project graylog2-server by Graylog2.

the class IndicesResource method single.

@GET
@Timed
@Path("/{index}")
@ApiOperation(value = "Get information of an index and its shards.")
@Produces(MediaType.APPLICATION_JSON)
public IndexInfo single(@ApiParam(name = "index") @PathParam("index") String index) {
    checkPermission(RestPermissions.INDICES_READ, index);
    if (!indexSetRegistry.isManagedIndex(index)) {
        final String msg = "Index [" + index + "] doesn't look like an index managed by Graylog.";
        LOG.info(msg);
        throw new NotFoundException(msg);
    }
    final IndexStatistics stats = indices.getIndexStats(index);
    if (stats == null) {
        final String msg = "Index [" + index + "] not found.";
        LOG.error(msg);
        throw new NotFoundException(msg);
    }
    final ImmutableList.Builder<ShardRouting> routing = ImmutableList.builder();
    for (org.elasticsearch.cluster.routing.ShardRouting shardRouting : stats.shardRoutings()) {
        routing.add(shardRouting(shardRouting));
    }
    return IndexInfo.create(indexStats(stats.primaries()), indexStats(stats.total()), routing.build(), indices.isReopened(index));
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) ImmutableList(com.google.common.collect.ImmutableList) NotFoundException(javax.ws.rs.NotFoundException) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) 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)

Aggregations

IndexStatistics (org.graylog2.indexer.indices.IndexStatistics)6 ImmutableList (com.google.common.collect.ImmutableList)3 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)3 ShardRouting (org.graylog2.rest.models.system.indexer.responses.ShardRouting)3 Timed (com.codahale.metrics.annotation.Timed)2 ApiOperation (io.swagger.annotations.ApiOperation)2 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 NotFoundException (javax.ws.rs.NotFoundException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 StoreStats (org.elasticsearch.index.store.StoreStats)2 IndexInfo (org.graylog2.rest.models.system.indexer.responses.IndexInfo)2 Test (org.junit.Test)2 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 MessageFormat (java.text.MessageFormat)1 Locale (java.util.Locale)1