Search in sources :

Example 46 with IndexSetConfig

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

the class IndexSetsResource method save.

@POST
@Timed
@ApiOperation(value = "Create index set")
@RequiresPermissions(RestPermissions.INDEXSETS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.INDEX_SET_CREATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetSummary save(@ApiParam(name = "Index set configuration", required = true) @Valid @NotNull IndexSetSummary indexSet) {
    try {
        final IndexSetConfig indexSetConfig = indexSet.toIndexSetConfig();
        final Optional<IndexSetValidator.Violation> violation = indexSetValidator.validate(indexSetConfig);
        if (violation.isPresent()) {
            throw new BadRequestException(violation.get().message());
        }
        final IndexSetConfig savedObject = indexSetService.save(indexSetConfig);
        final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
        return IndexSetSummary.fromIndexSetConfig(savedObject, savedObject.equals(defaultIndexSet));
    } catch (DuplicateKeyException e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) BadRequestException(javax.ws.rs.BadRequestException) DuplicateKeyException(com.mongodb.DuplicateKeyException) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 47 with IndexSetConfig

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

the class IndexSetValidatorTest method validateWithConflict2.

@Test
public void validateWithConflict2() throws Exception {
    final IndexSetConfig newConfig = mock(IndexSetConfig.class);
    final IndexSet indexSet = mock(IndexSet.class);
    when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
    // Existing index prefix starts with new index prefix
    when(indexSet.getIndexPrefix()).thenReturn("graylog");
    when(newConfig.indexPrefix()).thenReturn("gray");
    final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);
    assertThat(violation).isPresent();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 48 with IndexSetConfig

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

the class MongoIndexSetRegistryTest method indexSetsCacheShouldReturnCachedList.

@Test
public void indexSetsCacheShouldReturnCachedList() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    final List<IndexSetConfig> cachedResult = this.indexSetsCache.get();
    assertThat(cachedResult).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    verify(indexSetService, times(1)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 49 with IndexSetConfig

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

the class MongoIndexSetRegistryTest method indexSetsCacheShouldBeInvalidatedForIndexSetDeletion.

@Test
public void indexSetsCacheShouldBeInvalidatedForIndexSetDeletion() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    this.indexSetsCache.handleIndexSetDeletion(mock(IndexSetDeletedEvent.class));
    final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
    when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);
    final List<IndexSetConfig> newResult = this.indexSetsCache.get();
    assertThat(newResult).isNotNull().hasSize(1).containsExactly(newIndexSetConfig);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexSetDeletedEvent(org.graylog2.indexer.indexset.events.IndexSetDeletedEvent) Test(org.junit.Test)

Example 50 with IndexSetConfig

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

the class MongoIndexSetRegistryTest method getAllShouldNotBeCachedForCallAfterInvalidate.

@Test
public void getAllShouldNotBeCachedForCallAfterInvalidate() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    final MongoIndexSet indexSet = mock(MongoIndexSet.class);
    when(mongoIndexSetFactory.create(indexSetConfig)).thenReturn(indexSet);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    this.indexSetsCache.invalidate();
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

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