Search in sources :

Example 1 with SystemJobConcurrencyException

use of org.graylog2.system.jobs.SystemJobConcurrencyException in project graylog2-server by Graylog2.

the class MongoIndexSetTest method cycleSetsOldIndexToReadOnly.

@Test
public void cycleSetsOldIndexToReadOnly() throws SystemJobConcurrencyException {
    final String newIndexName = "graylog_1";
    final String oldIndexName = "graylog_0";
    final Map<String, Set<String>> indexNameAliases = ImmutableMap.of(oldIndexName, Collections.singleton("graylog_deflector"));
    when(indices.getIndexNamesAndAliases(anyString())).thenReturn(indexNameAliases);
    when(indices.create(newIndexName, mongoIndexSet)).thenReturn(true);
    when(indices.waitForRecovery(newIndexName)).thenReturn(ClusterHealthStatus.GREEN);
    final SetIndexReadOnlyAndCalculateRangeJob rangeJob = mock(SetIndexReadOnlyAndCalculateRangeJob.class);
    when(jobFactory.create(oldIndexName)).thenReturn(rangeJob);
    final MongoIndexSet mongoIndexSet = new MongoIndexSet(config, indices, nodeId, indexRangeService, auditEventSender, systemJobManager, jobFactory, activityWriter);
    mongoIndexSet.cycle();
    verify(jobFactory, times(1)).create(oldIndexName);
    verify(systemJobManager, times(1)).submitWithDelay(rangeJob, 30L, TimeUnit.SECONDS);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) SetIndexReadOnlyAndCalculateRangeJob(org.graylog2.indexer.indices.jobs.SetIndexReadOnlyAndCalculateRangeJob) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with SystemJobConcurrencyException

use of org.graylog2.system.jobs.SystemJobConcurrencyException in project graylog2-server by Graylog2.

the class SetIndexReadOnlyJob method execute.

@Override
public void execute() {
    final Optional<IndexSet> indexSet = indexSetRegistry.getForIndex(index);
    if (!indexSet.isPresent()) {
        log.error("Couldn't find index set for index <{}>", index);
        return;
    }
    log.info("Flushing old index <{}>.", index);
    indices.flush(index);
    log.info("Setting old index <{}> to read-only.", index);
    indices.setReadOnly(index);
    activityWriter.write(new Activity("Flushed and set <" + index + "> to read-only.", SetIndexReadOnlyJob.class));
    if (!indexSet.get().getConfig().indexOptimizationDisabled()) {
        try {
            systemJobManager.submit(optimizeIndexJobFactory.create(index, indexSet.get().getConfig().indexOptimizationMaxNumSegments()));
        } catch (SystemJobConcurrencyException e) {
            // The concurrency limit is very high. This should never happen.
            log.error("Cannot optimize index <" + index + ">.", e);
        }
    }
}
Also used : SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Activity(org.graylog2.shared.system.activities.Activity)

Example 3 with SystemJobConcurrencyException

use of org.graylog2.system.jobs.SystemJobConcurrencyException 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 4 with SystemJobConcurrencyException

use of org.graylog2.system.jobs.SystemJobConcurrencyException in project graylog2-server by Graylog2.

the class SystemJobResource method trigger.

@POST
@Timed
@ApiOperation(value = "Trigger new job")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 202, message = "Job accepted."), @ApiResponse(code = 400, message = "There is no such systemjob type."), @ApiResponse(code = 403, message = "Maximum concurrency level of this systemjob type reached.") })
@AuditEvent(type = AuditEventTypes.SYSTEM_JOB_START)
public Response trigger(@ApiParam(name = "JSON body", required = true) @Valid @NotNull TriggerRequest tr) {
    // TODO cleanup jobId vs jobName checking in permissions
    checkPermission(RestPermissions.SYSTEMJOBS_CREATE, tr.jobName());
    SystemJob job;
    try {
        job = systemJobFactory.build(tr.jobName());
    } catch (NoSuchJobException e) {
        LOG.error("Such a system job type does not exist. Returning HTTP 400.");
        throw new BadRequestException(e);
    }
    try {
        systemJobManager.submit(job);
    } catch (SystemJobConcurrencyException e) {
        LOG.error("Maximum concurrency level of this job reached. ", e);
        throw new ForbiddenException("Maximum concurrency level of this job reached", e);
    }
    return Response.accepted().entity(ImmutableMap.of("system_job_id", job.getId())).build();
}
Also used : SystemJob(org.graylog2.system.jobs.SystemJob) ForbiddenException(javax.ws.rs.ForbiddenException) NoSuchJobException(org.graylog2.system.jobs.NoSuchJobException) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) BadRequestException(javax.ws.rs.BadRequestException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with SystemJobConcurrencyException

use of org.graylog2.system.jobs.SystemJobConcurrencyException in project graylog2-server by Graylog2.

the class IndexRangesResource method rebuildIndex.

@POST
@Timed
@Path("/{index: [a-z_0-9-]+}/rebuild")
@ApiOperation(value = "Rebuild/sync index range information.", notes = "This triggers a system job that scans an index and stores meta information " + "about what indices contain messages in what time ranges. It atomically overwrites " + "already existing meta information.")
@ApiResponses(value = { @ApiResponse(code = 202, message = "Rebuild/sync system job triggered.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ES_INDEX_RANGE_UPDATE_JOB)
public Response rebuildIndex(@ApiParam(name = "index", value = "The name of the Graylog-managed Elasticsearch index", required = true) @PathParam("index") @NotEmpty String index) {
    if (!indexSetRegistry.isManagedIndex(index)) {
        throw new BadRequestException(index + " is not a Graylog-managed Elasticsearch index.");
    }
    checkPermission(RestPermissions.INDEXRANGES_REBUILD, index);
    final SystemJob rebuildJob = singleIndexRangeJobFactory.create(indexSetRegistry.getAll(), index);
    try {
        this.systemJobManager.submit(rebuildJob);
    } catch (SystemJobConcurrencyException e) {
        final String msg = "Concurrency level of this job reached: " + e.getMessage();
        LOG.error(msg);
        throw new ForbiddenException(msg, e);
    }
    return Response.accepted().build();
}
Also used : SystemJob(org.graylog2.system.jobs.SystemJob) ForbiddenException(javax.ws.rs.ForbiddenException) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

SystemJobConcurrencyException (org.graylog2.system.jobs.SystemJobConcurrencyException)4 Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 BadRequestException (javax.ws.rs.BadRequestException)3 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 ForbiddenException (javax.ws.rs.ForbiddenException)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 SystemJob (org.graylog2.system.jobs.SystemJob)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 NotFoundException (javax.ws.rs.NotFoundException)1 IndexSet (org.graylog2.indexer.IndexSet)1 SetIndexReadOnlyAndCalculateRangeJob (org.graylog2.indexer.indices.jobs.SetIndexReadOnlyAndCalculateRangeJob)1 Activity (org.graylog2.shared.system.activities.Activity)1 NoSuchJobException (org.graylog2.system.jobs.NoSuchJobException)1