use of org.graylog2.system.jobs.SystemJob in project graylog2-server by Graylog2.
the class SetIndexReadOnlyAndCalculateRangeJob method execute.
@Override
public void execute() {
final SystemJob setIndexReadOnlyJob = setIndexReadOnlyJobFactory.create(indexName);
setIndexReadOnlyJob.execute();
final SystemJob createNewSingleIndexRangeJob = createNewSingleIndexRangeJobFactory.create(indexSetRegistry.getAll(), indexName);
createNewSingleIndexRangeJob.execute();
}
use of org.graylog2.system.jobs.SystemJob in project graylog2-server by Graylog2.
the class IndexRangesResource method rebuildIndexSet.
@POST
@Timed
@Path("/index_set/{indexSetId}/rebuild")
@RequiresPermissions(RestPermissions.INDEXRANGES_REBUILD)
@ApiOperation(value = "Rebuild/sync index range information for the given index set.", notes = "This triggers a systemjob that scans every index in the given index set and stores meta information " + "about what indices contain messages in what timeranges. It atomically overwrites " + "already existing meta information.")
@ApiResponses(value = { @ApiResponse(code = 202, message = "Rebuild/sync systemjob triggered.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ES_INDEX_RANGE_UPDATE_JOB)
public Response rebuildIndexSet(@ApiParam(name = "indexSetId") @PathParam("indexSetId") @NotBlank final String indexSetId) {
final IndexSet indexSet = indexSetRegistry.get(indexSetId).orElseThrow(() -> new javax.ws.rs.NotFoundException("Index set <" + indexSetId + "> not found!"));
submitIndexRangesJob(Collections.singleton(indexSet));
return Response.accepted().build();
}
use of org.graylog2.system.jobs.SystemJob in project graylog2-server by Graylog2.
the class SystemJobResource method list.
@GET
@Timed
@ApiOperation(value = "List currently running jobs")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, List<SystemJobSummary>> list() {
final List<SystemJobSummary> jobs = Lists.newArrayListWithCapacity(systemJobManager.getRunningJobs().size());
for (Map.Entry<String, SystemJob> entry : systemJobManager.getRunningJobs().entrySet()) {
// TODO jobId is ephemeral, this is not a good key for permission checks. we should use the name of the job type (but there is no way to get it yet)
if (isPermitted(RestPermissions.SYSTEMJOBS_READ, entry.getKey())) {
final SystemJob systemJob = entry.getValue();
jobs.add(SystemJobSummary.create(UUID.fromString(systemJob.getId()), systemJob.getDescription(), systemJob.getClassName(), systemJob.getInfo(), nodeId.toString(), systemJob.getStartedAt(), systemJob.getProgress(), systemJob.isCancelable(), systemJob.providesProgress()));
}
}
return ImmutableMap.of("jobs", jobs);
}
use of org.graylog2.system.jobs.SystemJob in project graylog2-server by Graylog2.
the class SystemJobResource method cancel.
@DELETE
@Timed
@Path("/{jobId}")
@ApiOperation(value = "Cancel running job")
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.SYSTEM_JOB_STOP)
public SystemJobSummary cancel(@ApiParam(name = "jobId", required = true) @PathParam("jobId") @NotEmpty String jobId) {
SystemJob systemJob = systemJobManager.getRunningJobs().get(jobId);
if (systemJob == null) {
throw new NotFoundException("No system job with ID <" + jobId + "> found");
}
checkPermission(RestPermissions.SYSTEMJOBS_DELETE, systemJob.getClassName());
if (systemJob.isCancelable()) {
systemJob.requestCancel();
} else {
throw new ForbiddenException("System job with ID <" + jobId + "> cannot be cancelled");
}
return SystemJobSummary.create(UUID.fromString(systemJob.getId()), systemJob.getDescription(), systemJob.getClassName(), systemJob.getInfo(), nodeId.toString(), systemJob.getStartedAt(), systemJob.getProgress(), systemJob.isCancelable(), systemJob.providesProgress());
}
use of org.graylog2.system.jobs.SystemJob 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();
}
Aggregations