use of org.graylog2.rest.models.system.SystemJobSummary 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.rest.models.system.SystemJobSummary 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.rest.models.system.SystemJobSummary in project graylog2-server by Graylog2.
the class SystemJobResource method get.
@GET
@Timed
@Path("/{jobId}")
@ApiOperation(value = "Get information of a specific currently running job")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Job not found.") })
public SystemJobSummary get(@ApiParam(name = "jobId", required = true) @PathParam("jobId") @NotEmpty String jobId) {
// 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)
checkPermission(RestPermissions.SYSTEMJOBS_READ, jobId);
SystemJob systemJob = systemJobManager.getRunningJobs().get(jobId);
if (systemJob == null) {
throw new NotFoundException("No system job with ID <" + jobId + "> found");
}
return SystemJobSummary.create(UUID.fromString(systemJob.getId()), systemJob.getDescription(), systemJob.getClassName(), systemJob.getInfo(), nodeId.toString(), systemJob.getStartedAt(), systemJob.getProgress(), systemJob.isCancelable(), systemJob.providesProgress());
}
Aggregations