Search in sources :

Example 51 with IndexSet

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

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

the class IndexSetsResource method save.

@POST
@Timed
@ApiOperation(value = "Create index set")
@RequiresPermissions(RestPermissions.INDEXSETS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.INDEX_SET_CREATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetSummary save(@ApiParam(name = "Index set configuration", required = true) @Valid @NotNull IndexSetSummary indexSet) {
    try {
        final IndexSetConfig indexSetConfig = indexSet.toIndexSetConfig();
        final Optional<IndexSetValidator.Violation> violation = indexSetValidator.validate(indexSetConfig);
        if (violation.isPresent()) {
            throw new BadRequestException(violation.get().message());
        }
        final IndexSetConfig savedObject = indexSetService.save(indexSetConfig);
        final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
        return IndexSetSummary.fromIndexSetConfig(savedObject, savedObject.equals(defaultIndexSet));
    } catch (DuplicateKeyException e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) BadRequestException(javax.ws.rs.BadRequestException) DuplicateKeyException(com.mongodb.DuplicateKeyException) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 53 with IndexSet

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

the class IndexerOverviewResource method getIndexerOverview.

private IndexerOverview getIndexerOverview(IndexSet indexSet) throws TooManyAliasesException {
    final String indexSetId = indexSet.getConfig().id();
    final DeflectorSummary deflectorSummary = deflectorResource.deflector(indexSetId);
    final List<IndexRangeSummary> indexRanges = indexRangesResource.list().ranges();
    final Map<String, IndexStats> allDocCounts = indices.getAllDocCounts(indexSet).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    final Map<String, Boolean> areReopened = indices.areReopened(allDocCounts.keySet());
    final Map<String, IndexSummary> indicesSummaries = allDocCounts.values().stream().parallel().collect(Collectors.toMap(IndexStats::getIndex, (indexStats) -> IndexSummary.create(IndexSizeSummary.create(indexStats.getPrimaries().getDocs().getCount(), indexStats.getPrimaries().getDocs().getDeleted(), indexStats.getPrimaries().getStore().sizeInBytes()), indexRanges.stream().filter((indexRangeSummary) -> indexRangeSummary.indexName().equals(indexStats.getIndex())).findFirst().orElse(null), deflectorSummary.currentTarget() != null && deflectorSummary.currentTarget().equals(indexStats.getIndex()), false, areReopened.get(indexStats.getIndex()))));
    indices.getClosedIndices(indexSet).forEach(indexName -> indicesSummaries.put(indexName, IndexSummary.create(null, indexRanges.stream().filter((indexRangeSummary) -> indexRangeSummary.indexName().equals(indexName)).findFirst().orElse(null), deflectorSummary.currentTarget() != null && deflectorSummary.currentTarget().equals(indexName), true, false)));
    return IndexerOverview.create(deflectorSummary, IndexerClusterOverview.create(indexerClusterResource.clusterHealth(), indexerClusterResource.clusterName().name()), countResource.total(indexSetId), indicesSummaries);
}
Also used : DeflectorSummary(org.graylog2.rest.models.system.deflector.responses.DeflectorSummary) IndexerOverview(org.graylog2.rest.models.system.indexer.responses.IndexerOverview) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) DeflectorSummary(org.graylog2.rest.models.system.deflector.responses.DeflectorSummary) IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) IndexSummary(org.graylog2.rest.models.system.indexer.responses.IndexSummary) Api(io.swagger.annotations.Api) IndexSet(org.graylog2.indexer.IndexSet) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) DeflectorResource(org.graylog2.rest.resources.system.DeflectorResource) Cluster(org.graylog2.indexer.cluster.Cluster) RestResource(org.graylog2.shared.rest.resources.RestResource) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) List(java.util.List) IndexSizeSummary(org.graylog2.rest.models.system.indexer.responses.IndexSizeSummary) IndexerClusterOverview(org.graylog2.rest.models.system.indexer.responses.IndexerClusterOverview) IndexRangesResource(org.graylog2.rest.resources.system.IndexRangesResource) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) CountResource(org.graylog2.rest.resources.count.CountResource) IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) Map(java.util.Map) IndexSummary(org.graylog2.rest.models.system.indexer.responses.IndexSummary)

Example 54 with IndexSet

use of org.graylog2.indexer.IndexSet 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> indicesStats = indices.getIndicesStats(indexSet).stream().filter(indexStats -> indexSetRegistry.isManagedIndex(indexStats.indexName())).collect(Collectors.toSet());
    return getOpenIndicesInfo(indicesStats);
}
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) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) 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)

Example 55 with IndexSet

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

the class DeflectorResource method deprecatedCycle.

@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
@Deprecated
public void deprecatedCycle() {
    final IndexSet indexSet = indexSetRegistry.getDefault();
    checkCycle(indexSet);
    final String msg = "Cycling deflector for default index set <" + indexSet.getConfig().id() + ">. 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)

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