Search in sources :

Example 61 with IndexSet

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

the class IndexSetsResourceTest method delete0.

@Test
public void delete0() throws Exception {
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetRegistry.getDefault()).thenReturn(null);
    when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
    when(indexSetService.delete("id")).thenReturn(0);
    expectedException.expect(NotFoundException.class);
    expectedException.expectMessage("Couldn't delete index set with ID <id>");
    try {
        indexSetsResource.delete("id", false);
    } finally {
        verify(indexSetRegistry, times(1)).getDefault();
        verify(indexSetService, times(1)).delete("id");
        verifyNoMoreInteractions(indexSetService);
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 62 with IndexSet

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

the class IndexSetsResourceTest method setDefaultMakesIndexDefaultIfWritable.

@Test
public void setDefaultMakesIndexDefaultIfWritable() throws Exception {
    final String indexSetId = "newDefaultIndexSetId";
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = IndexSetConfig.create(indexSetId, "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(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetService.get(indexSetId)).thenReturn(Optional.of(indexSetConfig));
    indexSetsResource.setDefault(indexSetId);
    final ArgumentCaptor<DefaultIndexSetConfig> defaultIndexSetIdCaptor = ArgumentCaptor.forClass(DefaultIndexSetConfig.class);
    verify(clusterConfigService, times(1)).write(defaultIndexSetIdCaptor.capture());
    final DefaultIndexSetConfig defaultIndexSetConfig = defaultIndexSetIdCaptor.getValue();
    assertThat(defaultIndexSetConfig).isNotNull();
    assertThat(defaultIndexSetConfig.defaultIndexSetId()).isEqualTo(indexSetId);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) 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 63 with IndexSet

use of org.graylog2.indexer.IndexSet 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)

Aggregations

IndexSet (org.graylog2.indexer.IndexSet)31 Test (org.junit.Test)26 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)22 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 Path (javax.ws.rs.Path)12 AuditEvent (org.graylog2.audit.jersey.AuditEvent)11 ApiResponses (io.swagger.annotations.ApiResponses)10 Map (java.util.Map)9 POST (javax.ws.rs.POST)9 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)9 BadRequestException (javax.ws.rs.BadRequestException)8 NotFoundException (javax.ws.rs.NotFoundException)8 Produces (javax.ws.rs.Produces)8 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)8 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 Inject (javax.inject.Inject)7 IndexSetRegistry (org.graylog2.indexer.IndexSetRegistry)7 Api (io.swagger.annotations.Api)6