Search in sources :

Example 1 with IndexSetResponse

use of org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse in project graylog2-server by Graylog2.

the class IndexSetsResource method list.

@GET
@Timed
@ApiOperation(value = "Get a list of all index sets")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetResponse list(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("0") int limit, @ApiParam(name = "stats", value = "Include index set stats.") @QueryParam("stats") @DefaultValue("false") boolean computeStats) {
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    List<IndexSetSummary> indexSets;
    int count;
    if (limit > 0) {
        // First collect all index set ids the user is allowed to see.
        final Set<String> allowedIds = indexSetService.findAll().stream().filter(indexSet -> isPermitted(RestPermissions.INDEXSETS_READ, indexSet.id())).map(IndexSetConfig::id).collect(Collectors.toSet());
        indexSets = indexSetService.findPaginated(allowedIds, limit, skip).stream().map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
        count = allowedIds.size();
    } else {
        indexSets = indexSetService.findAll().stream().filter(indexSetConfig -> isPermitted(RestPermissions.INDEXSETS_READ, indexSetConfig.id())).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
        count = indexSets.size();
    }
    final Map<String, IndexSetStats> stats;
    if (computeStats) {
        stats = indexSetRegistry.getAll().stream().collect(Collectors.toMap(indexSet -> indexSet.getConfig().id(), indexSetStatsCreator::getForIndexSet));
    } else {
        stats = Collections.emptyMap();
    }
    return IndexSetResponse.create(count, indexSets, stats);
}
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) Indices(org.graylog2.indexer.indices.Indices) 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) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) 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) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with IndexSetResponse

use of org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse 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, 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", null, 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 3 with IndexSetResponse

use of org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method list0.

@Test
public void list0() {
    when(indexSetService.findAll()).thenReturn(Collections.emptyList());
    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 : IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Test(org.junit.Test)

Example 4 with IndexSetResponse

use of org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method list.

@Test
public void list() {
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "title", "description", true, 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", null, 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)

Aggregations

IndexSetResponse (org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse)4 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)3 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)3 Test (org.junit.Test)2 Timed (com.codahale.metrics.annotation.Timed)1 DuplicateKeyException (com.mongodb.DuplicateKeyException)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Valid (javax.validation.Valid)1