Search in sources :

Example 26 with IndexSet

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

the class IndexSetsResource method setDefault.

@PUT
@Path("{id}/default")
@Timed
@ApiOperation(value = "Set default index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_UPDATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetSummary setDefault(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
    checkPermission(RestPermissions.INDEXSETS_EDIT, id);
    final IndexSetConfig indexSet = indexSetService.get(id).orElseThrow(() -> new NotFoundException("Index set <" + id + "> does not exist"));
    if (!indexSet.isWritable()) {
        throw new ClientErrorException("Default index set must be writable.", Response.Status.CONFLICT);
    }
    clusterConfigService.write(DefaultIndexSetConfig.create(indexSet.id()));
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    return IndexSetSummary.fromIndexSetConfig(indexSet, indexSet.equals(defaultIndexSet));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 with IndexSet

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

the class IndicesResource method indexSetClosed.

@GET
@Timed
@Path("/{indexSetId}/closed")
@ApiOperation(value = "Get a list of closed indices that can be reopened.")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetClosed(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> closedIndices = indices.getClosedIndices(indexSet).stream().filter((indexName) -> isPermitted(RestPermissions.INDICES_READ, indexName) && indexSetRegistry.isManagedIndex(indexName)).collect(Collectors.toSet());
    return ClosedIndices.create(closedIndices, closedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) IndexStats(org.graylog2.rest.models.system.indexer.responses.IndexStats) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Set(java.util.Set) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) AuditEventTypes(org.graylog2.audit.AuditEventTypes) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) Inject(javax.inject.Inject) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ImmutableList(com.google.common.collect.ImmutableList) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Cluster(org.graylog2.indexer.cluster.Cluster) ForbiddenException(javax.ws.rs.ForbiddenException) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) RestResource(org.graylog2.shared.rest.resources.RestResource) ApiResponse(io.swagger.annotations.ApiResponse) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with IndexSet

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

the class IndicesResource method indexSetReopened.

@GET
@Timed
@Path("/{indexSetId}/reopened")
@ApiOperation(value = "Get a list of reopened indices, which will not be cleaned by retention cleaning")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetReopened(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> reopenedIndices = indices.getReopenedIndices(indexSet).stream().filter((indexName) -> isPermitted(RestPermissions.INDICES_READ, indexName) && indexSetRegistry.isManagedIndex(indexName)).collect(Collectors.toSet());
    return ClosedIndices.create(reopenedIndices, reopenedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) IndexStats(org.graylog2.rest.models.system.indexer.responses.IndexStats) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Set(java.util.Set) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) AuditEventTypes(org.graylog2.audit.AuditEventTypes) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) Inject(javax.inject.Inject) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ImmutableList(com.google.common.collect.ImmutableList) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Cluster(org.graylog2.indexer.cluster.Cluster) ForbiddenException(javax.ws.rs.ForbiddenException) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) RestResource(org.graylog2.shared.rest.resources.RestResource) ApiResponse(io.swagger.annotations.ApiResponse) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 29 with IndexSet

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

the class DeflectorResource method cycle.

@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index in index set")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/{indexSetId}/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
public void cycle(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    checkCycle(indexSet);
    final String msg = "Cycling deflector for index set <" + indexSetId + ">. Reason: REST request.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, DeflectorResource.class));
    indexSet.cycle();
}
Also used : Activity(org.graylog2.shared.system.activities.Activity) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) RestrictToMaster(org.graylog2.shared.security.RestrictToMaster)

Example 30 with IndexSet

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

the class IndexSetsResourceTest method deleteDefaultIndexSet.

@Test
public void deleteDefaultIndexSet() throws Exception {
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetRegistry.getDefault()).thenReturn(indexSet);
    when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
    when(indexSetCleanupJobFactory.create(indexSet)).thenReturn(mock(IndexSetCleanupJob.class));
    when(indexSetService.delete("id")).thenReturn(1);
    expectedException.expect(BadRequestException.class);
    indexSetsResource.delete("id", false);
    indexSetsResource.delete("id", true);
    verify(indexSetService, never()).delete("id");
    verify(systemJobManager, never()).submit(any(IndexSetCleanupJob.class));
    verifyNoMoreInteractions(indexSetService);
}
Also used : IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) 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