Search in sources :

Example 1 with SystemJobSummary

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);
}
Also used : SystemJob(org.graylog2.system.jobs.SystemJob) SystemJobSummary(org.graylog2.rest.models.system.SystemJobSummary) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with SystemJobSummary

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());
}
Also used : SystemJob(org.graylog2.system.jobs.SystemJob) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 3 with SystemJobSummary

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());
}
Also used : SystemJob(org.graylog2.system.jobs.SystemJob) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Produces (javax.ws.rs.Produces)3 SystemJob (org.graylog2.system.jobs.SystemJob)3 GET (javax.ws.rs.GET)2 NotFoundException (javax.ws.rs.NotFoundException)2 Path (javax.ws.rs.Path)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Map (java.util.Map)1 DELETE (javax.ws.rs.DELETE)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 AuditEvent (org.graylog2.audit.jersey.AuditEvent)1 SystemJobSummary (org.graylog2.rest.models.system.SystemJobSummary)1