Search in sources :

Example 21 with IndexSetConfig

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

the class IndexSetValidatorTest method validate.

@Test
public void validate() throws Exception {
    final String prefix = "graylog_index";
    final IndexSetConfig newConfig = mock(IndexSetConfig.class);
    final IndexSet indexSet = mock(IndexSet.class);
    when(indexSet.getIndexPrefix()).thenReturn("foo");
    when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
    when(newConfig.indexPrefix()).thenReturn(prefix);
    final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);
    assertThat(violation).isNotPresent();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 22 with IndexSetConfig

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

the class IndexSetValidatorTest method validateWithConflict.

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

Example 23 with IndexSetConfig

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

the class IndexSetValidatorTest method validateWhenAlreadyManaged.

@Test
public void validateWhenAlreadyManaged() throws Exception {
    final String prefix = "graylog_index";
    final IndexSetConfig newConfig = mock(IndexSetConfig.class);
    final IndexSet indexSet = mock(IndexSet.class);
    when(indexSet.getIndexPrefix()).thenReturn("foo");
    when(indexSetRegistry.isManagedIndex("graylog_index_0")).thenReturn(true);
    when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
    when(newConfig.indexPrefix()).thenReturn(prefix);
    final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);
    assertThat(violation).isPresent();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 24 with IndexSetConfig

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

the class MongoIndexSetRegistryTest method getAllShouldBeCachedForNonEmptyList.

@Test
public void getAllShouldBeCachedForNonEmptyList() {
    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);
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    verify(indexSetService, times(1)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 25 with IndexSetConfig

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

the class IndexSetsResource method get.

@GET
@Path("{id}")
@Timed
@ApiOperation(value = "Get index set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public IndexSetSummary get(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
    checkPermission(RestPermissions.INDEXSETS_READ, id);
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    return indexSetService.get(id).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Produces(javax.ws.rs.Produces) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) DELETE(javax.ws.rs.DELETE) IndexSetStatsCreator(org.graylog2.indexer.IndexSetStatsCreator) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) SystemJobManager(org.graylog2.system.jobs.SystemJobManager) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Response(javax.ws.rs.core.Response) AuditEventTypes(org.graylog2.audit.AuditEventTypes) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) DuplicateKeyException(com.mongodb.DuplicateKeyException) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) IndexSetValidator(org.graylog2.indexer.IndexSetValidator) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Objects.requireNonNull(java.util.Objects.requireNonNull) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexSetUpdateRequest(org.graylog2.rest.resources.system.indexer.requests.IndexSetUpdateRequest) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) RestResource(org.graylog2.shared.rest.resources.RestResource) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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