Search in sources :

Example 1 with ShardRouting

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

the class SizeBasedRotationStrategyTest method testDontRotate.

@Test
public void testDontRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100000L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, never()).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Example 2 with ShardRouting

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

the class SizeBasedRotationStrategyTest method testRotate.

@Test
public void testRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, times(1)).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Example 3 with ShardRouting

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

use of org.graylog2.rest.models.system.indexer.responses.ShardRouting 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)4 ImmutableList (com.google.common.collect.ImmutableList)2 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)2 StoreStats (org.elasticsearch.index.store.StoreStats)2 ShardRouting (org.graylog2.rest.models.system.indexer.responses.ShardRouting)2 Test (org.junit.Test)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