Search in sources :

Example 1 with IndexInfo

use of org.graylog2.rest.models.system.indexer.responses.IndexInfo in project graylog2-server by Graylog2.

the class IndicesResource method getOpenIndicesInfo.

private OpenIndicesInfo getOpenIndicesInfo(Set<IndexStatistics> indicesStats) {
    final Map<String, IndexInfo> indexInfos = new HashMap<>();
    final Map<String, Boolean> areReopened = indices.areReopened(indicesStats.stream().map(IndexStatistics::indexName).collect(Collectors.toSet()));
    for (IndexStatistics indexStatistics : indicesStats) {
        final ImmutableList.Builder<ShardRouting> routing = ImmutableList.builder();
        for (org.elasticsearch.cluster.routing.ShardRouting shardRouting : indexStatistics.shardRoutings()) {
            routing.add(shardRouting(shardRouting));
        }
        final IndexInfo indexInfo = IndexInfo.create(indexStats(indexStatistics.primaries()), indexStats(indexStatistics.total()), routing.build(), areReopened.get(indexStatistics.indexName()));
        indexInfos.put(indexStatistics.indexName(), indexInfo);
    }
    return OpenIndicesInfo.create(indexInfos);
}
Also used : HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting)

Example 2 with IndexInfo

use of org.graylog2.rest.models.system.indexer.responses.IndexInfo 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

ImmutableList (com.google.common.collect.ImmutableList)2 IndexStatistics (org.graylog2.indexer.indices.IndexStatistics)2 ShardRouting (org.graylog2.rest.models.system.indexer.responses.ShardRouting)2 Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 IndexInfo (org.graylog2.rest.models.system.indexer.responses.IndexInfo)1