Search in sources :

Example 11 with IndexSetRegistry

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

the class IndexRotationThreadTest method testDoNotPerformRotationIfClusterIsDown.

@Test
public void testDoNotPerformRotationIfClusterIsDown() throws NoTargetIndexException {
    final Provider<RotationStrategy> provider = spy(new RotationStrategyProvider());
    when(cluster.isConnected()).thenReturn(false);
    final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
    rotationThread.doRun();
    verify(indexSet, never()).cycle();
    verify(provider, never()).get();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) Test(org.junit.Test)

Example 12 with IndexSetRegistry

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

the class IndexRotationThreadTest method testPerformRotation.

@Test
public void testPerformRotation() throws NoTargetIndexException {
    final Provider<RotationStrategy> provider = new RotationStrategyProvider() {

        @Override
        public void doRotate(IndexSet indexSet) {
            indexSet.cycle();
        }
    };
    final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
    when(indexSetConfig.rotationStrategyClass()).thenReturn("strategy");
    rotationThread.checkForRotation(indexSet);
    verify(indexSet, times(1)).cycle();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 13 with IndexSetRegistry

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

the class IndexSetsResource method delete.

@DELETE
@Path("{id}")
@Timed
@ApiOperation(value = "Delete index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_DELETE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public void delete(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "delete_indices") @QueryParam("delete_indices") @DefaultValue("true") boolean deleteIndices) {
    checkPermission(RestPermissions.INDEXSETS_DELETE, id);
    final IndexSet indexSet = getIndexSet(indexSetRegistry, id);
    final IndexSet defaultIndexSet = indexSetRegistry.getDefault();
    if (indexSet.equals(defaultIndexSet)) {
        throw new BadRequestException("Default index set <" + indexSet.getConfig().id() + "> cannot be deleted!");
    }
    if (indexSetService.delete(id) == 0) {
        throw new NotFoundException("Couldn't delete index set with ID <" + id + ">");
    } else {
        if (deleteIndices) {
            try {
                systemJobManager.submit(indexSetCleanupJobFactory.create(indexSet));
            } catch (SystemJobConcurrencyException e) {
                LOG.error("Error running system job", e);
            }
        }
    }
}
Also used : SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with IndexSetRegistry

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

the class IndicesResource method indexSetOpen.

@GET
@Path("/{indexSetId}/open")
@Timed
@ApiOperation(value = "Get information of all open indices managed by Graylog and their shards.")
@RequiresPermissions(RestPermissions.INDICES_READ)
@Produces(MediaType.APPLICATION_JSON)
public OpenIndicesInfo indexSetOpen(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<IndexStatistics> indicesInfos = indices.getIndicesStats(indexSet).stream().filter(indexStats -> isPermitted(RestPermissions.INDICES_READ, indexStats.index())).collect(Collectors.toSet());
    return getOpenIndicesInfo(indicesInfos);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) PathParam(javax.ws.rs.PathParam) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Api(io.swagger.annotations.Api) IndexSet(org.graylog2.indexer.IndexSet) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) ApiResponse(io.swagger.annotations.ApiResponse) AuditEventTypes(org.graylog2.audit.AuditEventTypes) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) NodeInfoCache(org.graylog2.indexer.NodeInfoCache) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

IndexSet (org.graylog2.indexer.IndexSet)10 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 Path (javax.ws.rs.Path)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 ApiResponses (io.swagger.annotations.ApiResponses)4 DELETE (javax.ws.rs.DELETE)4 NotFoundException (javax.ws.rs.NotFoundException)4 POST (javax.ws.rs.POST)4 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3