Search in sources :

Example 1 with IndexSetRegistry

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

the class CountsTest method setUp.

@Before
public void setUp() throws Exception {
    final Map<String, Object> settings = ImmutableMap.of("number_of_shards", 1, "index.number_of_replicas", 0);
    final CreateIndexResponse createIndexResponse1 = client.admin().indices().prepareCreate(INDEX_NAME_1).setSettings(settings).setTimeout(TimeValue.timeValueSeconds(10L)).execute().get();
    assumeTrue(createIndexResponse1.isAcknowledged());
    final CreateIndexResponse createIndexResponse2 = client.admin().indices().prepareCreate(INDEX_NAME_2).setSettings(settings).setTimeout(TimeValue.timeValueSeconds(10L)).execute().get();
    assumeTrue(createIndexResponse2.isAcknowledged());
    final ClusterHealthResponse clusterHealthResponse1 = client.admin().cluster().prepareHealth(INDEX_NAME_1).setWaitForGreenStatus().execute().get();
    assumeTrue(clusterHealthResponse1.getStatus() == ClusterHealthStatus.GREEN);
    final ClusterHealthResponse clusterHealthResponse2 = client.admin().cluster().prepareHealth(INDEX_NAME_2).setWaitForGreenStatus().execute().get();
    assumeTrue(clusterHealthResponse2.getStatus() == ClusterHealthStatus.GREEN);
    counts = new Counts(client, indexSetRegistry);
    indexSetConfig1 = IndexSetConfig.builder().id("id-1").title("title-1").indexPrefix("index_set_1_counts_test").shards(1).replicas(0).rotationStrategyClass(MessageCountRotationStrategy.class.getCanonicalName()).rotationStrategy(MessageCountRotationStrategyConfig.createDefault()).retentionStrategyClass(DeletionRetentionStrategy.class.getCanonicalName()).retentionStrategy(DeletionRetentionStrategyConfig.createDefault()).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-1").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    indexSetConfig2 = IndexSetConfig.builder().id("id-2").title("title-2").indexPrefix("index_set_2_counts_test").shards(1).replicas(0).rotationStrategyClass(MessageCountRotationStrategy.class.getCanonicalName()).rotationStrategy(MessageCountRotationStrategyConfig.createDefault()).retentionStrategyClass(DeletionRetentionStrategy.class.getCanonicalName()).retentionStrategy(DeletionRetentionStrategyConfig.createDefault()).creationDate(ZonedDateTime.of(2016, 10, 13, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-2").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    when(indexSetRegistry.getManagedIndices()).thenReturn(new String[] { INDEX_NAME_1, INDEX_NAME_2 });
    when(indexSetRegistry.get(indexSetConfig1.id())).thenReturn(Optional.of(indexSet1));
    when(indexSetRegistry.get(indexSetConfig2.id())).thenReturn(Optional.of(indexSet2));
    when(indexSet1.getManagedIndices()).thenReturn(new String[] { INDEX_NAME_1 });
    when(indexSet2.getManagedIndices()).thenReturn(new String[] { INDEX_NAME_2 });
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) DeletionRetentionStrategy(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) Before(org.junit.Before)

Example 2 with IndexSetRegistry

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

the class IndexRetentionThread method doRun.

@Override
public void doRun() {
    if (!cluster.isConnected() || !cluster.isHealthy()) {
        LOG.info("Elasticsearch cluster not available, skipping index retention checks.");
        return;
    }
    for (final IndexSet indexSet : indexSetRegistry) {
        if (!indexSet.getConfig().isWritable()) {
            LOG.debug("Skipping non-writable index set <{}> ({})", indexSet.getConfig().id(), indexSet.getConfig().title());
            continue;
        }
        final IndexSetConfig config = indexSet.getConfig();
        final Provider<RetentionStrategy> retentionStrategyProvider = retentionStrategyMap.get(config.retentionStrategyClass());
        if (retentionStrategyProvider == null) {
            LOG.warn("Retention strategy \"{}\" not found, not running index retention!", config.retentionStrategyClass());
            retentionProblemNotification("Index Retention Problem!", "Index retention strategy " + config.retentionStrategyClass() + " not found! Please fix your index retention configuration!");
            continue;
        }
        retentionStrategyProvider.get().retain(indexSet);
    }
}
Also used : RetentionStrategy(org.graylog2.plugin.indexer.retention.RetentionStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet)

Example 3 with IndexSetRegistry

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

the class IndicesResource method indexSetClosed.

@GET
@Timed
@Path("/{indexSetId}/closed")
@ApiOperation(value = "Get a list of closed indices that can be reopened.")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetClosed(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> closedIndices = indices.getClosedIndices(indexSet).stream().filter(index -> isPermitted(RestPermissions.INDICES_READ, index)).collect(Collectors.toSet());
    return ClosedIndices.create(closedIndices, closedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) PathParam(javax.ws.rs.PathParam) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Api(io.swagger.annotations.Api) IndexSet(org.graylog2.indexer.IndexSet) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) ApiResponse(io.swagger.annotations.ApiResponse) AuditEventTypes(org.graylog2.audit.AuditEventTypes) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) NodeInfoCache(org.graylog2.indexer.NodeInfoCache) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) 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)

Example 4 with IndexSetRegistry

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

the class IndicesResource method indexSetReopened.

@GET
@Timed
@Path("/{indexSetId}/reopened")
@ApiOperation(value = "Get a list of reopened indices, which will not be cleaned by retention cleaning")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetReopened(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> reopenedIndices = indices.getReopenedIndices(indexSet).stream().filter(index -> isPermitted(RestPermissions.INDICES_READ, index)).collect(Collectors.toSet());
    return ClosedIndices.create(reopenedIndices, reopenedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) PathParam(javax.ws.rs.PathParam) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Api(io.swagger.annotations.Api) IndexSet(org.graylog2.indexer.IndexSet) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) ApiResponse(io.swagger.annotations.ApiResponse) AuditEventTypes(org.graylog2.audit.AuditEventTypes) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) NodeInfoCache(org.graylog2.indexer.NodeInfoCache) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) 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)

Example 5 with IndexSetRegistry

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

the class DeflectorResource method cycle.

@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index in index set")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/{indexSetId}/cycle")
@RestrictToLeader
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
public void cycle(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    checkCycle(indexSet);
    final String msg = "Cycling deflector for index set <" + indexSetId + ">. Reason: REST request.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, DeflectorResource.class));
    indexSet.cycle();
}
Also used : Activity(org.graylog2.shared.system.activities.Activity) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) RestrictToLeader(org.graylog2.shared.security.RestrictToLeader) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Aggregations

IndexSet (org.graylog2.indexer.IndexSet)10 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 Path (javax.ws.rs.Path)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 ApiResponses (io.swagger.annotations.ApiResponses)4 DELETE (javax.ws.rs.DELETE)4 NotFoundException (javax.ws.rs.NotFoundException)4 POST (javax.ws.rs.POST)4 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3