Search in sources :

Example 31 with IndexSetConfig

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

the class IndexSetsResourceTest method updateDenied.

@Test
public void updateDenied() {
    notPermitted();
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    expectedException.expect(ForbiddenException.class);
    expectedException.expectMessage("Not authorized to access resource id <wrong-id>");
    try {
        indexSetsResource.update("wrong-id", IndexSetUpdateRequest.fromIndexSetConfig(indexSetConfig));
    } finally {
        verifyZeroInteractions(indexSetService);
    }
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) Test(org.junit.Test)

Example 32 with IndexSetConfig

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

the class IndexSetsResourceTest method listDenied.

@Test
public void listDenied() {
    notPermitted();
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    final IndexSetResponse list = indexSetsResource.list(0, 0, false);
    verify(indexSetService, times(1)).findAll();
    verify(indexSetService, times(1)).getDefault();
    verifyNoMoreInteractions(indexSetService);
    assertThat(list.total()).isEqualTo(0);
    assertThat(list.indexSets()).isEmpty();
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Test(org.junit.Test)

Example 33 with IndexSetConfig

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

the class IndexSetsResourceTest method get.

@Test
public void get() {
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    when(indexSetService.get("id")).thenReturn(Optional.of(indexSetConfig));
    final IndexSetSummary summary = indexSetsResource.get("id");
    verify(indexSetService, times(1)).get("id");
    verify(indexSetService, times(1)).getDefault();
    verifyNoMoreInteractions(indexSetService);
    assertThat(summary).isEqualTo(IndexSetSummary.fromIndexSetConfig(indexSetConfig, false));
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Test(org.junit.Test)

Example 34 with IndexSetConfig

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

the class MongoIndexSetService method save.

/**
     * {@inheritDoc}
     */
@Override
public IndexSetConfig save(IndexSetConfig indexSetConfig) {
    final WriteResult<IndexSetConfig, ObjectId> writeResult = collection.save(indexSetConfig);
    final IndexSetConfig savedObject = writeResult.getSavedObject();
    final IndexSetCreatedEvent createdEvent = IndexSetCreatedEvent.create(savedObject);
    clusterEventBus.post(createdEvent);
    return savedObject;
}
Also used : IndexSetCreatedEvent(org.graylog2.indexer.indexset.events.IndexSetCreatedEvent) ObjectId(org.bson.types.ObjectId)

Example 35 with IndexSetConfig

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

the class IndexSetCleanupJob method execute.

@Override
public void execute() {
    final IndexSetConfig config = indexSet.getConfig();
    final String[] managedIndices = indexSet.getManagedIndices();
    this.total = managedIndices.length;
    try {
        LOG.info("Deleting index template <{}> from Elasticsearch", config.indexTemplateName());
        indices.deleteIndexTemplate(indexSet);
    } catch (IndexTemplateMissingException ignored) {
        LOG.debug("Unable to delete index template <{}> because it does not exist.", config.indexTemplateName());
    } catch (Exception e) {
        LOG.error("Unable to delete index template <{}>", config.indexTemplateName(), e);
    }
    for (String indexName : managedIndices) {
        if (cancel) {
            LOG.info("Cancel requested. Deleted <{}> of <{}> indices.", deleted, total);
            break;
        }
        try {
            LOG.info("Removing index range information for index: {}", indexName);
            indexRangeService.remove(indexName);
            LOG.info("Deleting index <{}> in index set <{}> ({})", indexName, config.id(), config.title());
            indices.delete(indexName);
            deleted.incrementAndGet();
        } catch (Exception e) {
            LOG.error("Unable to delete index <{}>", indexName, e);
        }
    }
}
Also used : IndexTemplateMissingException(org.elasticsearch.indices.IndexTemplateMissingException) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexTemplateMissingException(org.elasticsearch.indices.IndexTemplateMissingException)

Aggregations

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)53 Test (org.junit.Test)39 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)21 IndexSet (org.graylog2.indexer.IndexSet)11 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)10 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)10 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)8 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)5 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 NotFoundException (javax.ws.rs.NotFoundException)4 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 IndexSetService (org.graylog2.indexer.indexset.IndexSetService)4 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)4