Search in sources :

Example 56 with IndexSetConfig

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

the class IndexSetsResourceTest method setDefaultDoesNotDoAnythingIfIndexSetIsNotWritable.

@Test
public void setDefaultDoesNotDoAnythingIfIndexSetIsNotWritable() throws Exception {
    final String readOnlyIndexSetId = "newDefaultIndexSetId";
    final IndexSet readOnlyIndexSet = mock(IndexSet.class);
    final IndexSetConfig readOnlyIndexSetConfig = IndexSetConfig.create(readOnlyIndexSetId, "title", "description", false, "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(readOnlyIndexSet.getConfig()).thenReturn(readOnlyIndexSetConfig);
    when(indexSetService.get(readOnlyIndexSetId)).thenReturn(Optional.of(readOnlyIndexSetConfig));
    expectedException.expect(ClientErrorException.class);
    expectedException.expectMessage("Default index set must be writable.");
    try {
        indexSetsResource.setDefault(readOnlyIndexSetId);
    } finally {
        verifyZeroInteractions(clusterConfigService);
    }
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 57 with IndexSetConfig

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

the class IndexSetsResourceTest method update.

@Test
public void update() {
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "new 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);
    final IndexSetConfig updatedIndexSetConfig = indexSetConfig.toBuilder().title("new title").build();
    when(indexSetService.get("id")).thenReturn(Optional.of(indexSetConfig));
    when(indexSetService.save(indexSetConfig)).thenReturn(updatedIndexSetConfig);
    final IndexSetSummary summary = indexSetsResource.update("id", IndexSetUpdateRequest.fromIndexSetConfig(indexSetConfig));
    verify(indexSetService, times(1)).get("id");
    verify(indexSetService, times(1)).save(indexSetConfig);
    verify(indexSetService, times(1)).getDefault();
    verifyNoMoreInteractions(indexSetService);
    // The real update wouldn't replace the index template nameā€¦
    final IndexSetConfig actual = summary.toIndexSetConfig().toBuilder().indexTemplateName("index-template").build();
    assertThat(actual).isEqualTo(updatedIndexSetConfig);
}
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 58 with IndexSetConfig

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

the class IndexSetsResourceTest method saveDenied.

@Test
@Ignore("Currently doesn't work with @RequiresPermissions")
public void saveDenied() {
    notPermitted();
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("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 <id>");
    try {
        indexSetsResource.save(IndexSetSummary.fromIndexSetConfig(indexSetConfig, false));
    } 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 59 with IndexSetConfig

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

the class IndexSetsResourceTest method list.

@Test
public void list() {
    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(1);
    assertThat(list.indexSets()).containsExactly(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) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Test(org.junit.Test)

Example 60 with IndexSetConfig

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

the class IndexSetsResourceTest method updateFailsWhenDefaultSetIsSetReadOnly.

@Test
public void updateFailsWhenDefaultSetIsSetReadOnly() throws Exception {
    final String defaultIndexSetId = "defaultIndexSet";
    final IndexSetConfig defaultIndexSetConfig = IndexSetConfig.create(defaultIndexSetId, "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.getDefault()).thenReturn(defaultIndexSetConfig);
    when(indexSetService.get(defaultIndexSetId)).thenReturn(Optional.of(defaultIndexSetConfig));
    final IndexSetConfig defaultIndexSetConfigSetReadOnly = defaultIndexSetConfig.toBuilder().isWritable(false).build();
    expectedException.expect(ClientErrorException.class);
    expectedException.expectMessage("Default index set must be writable.");
    try {
        indexSetsResource.update("defaultIndexSet", IndexSetUpdateRequest.fromIndexSetConfig(defaultIndexSetConfigSetReadOnly));
    } finally {
        verify(indexSetService, never()).save(any());
    }
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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