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);
}
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);
}
}
}
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);
}
}
}
}
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();
}
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();
}
Aggregations