Search in sources :

Example 1 with JobInfo

use of org.apache.stanbol.commons.jobs.api.JobInfo in project stanbol by apache.

the class JobsResource method get.

/**
     * GET info about a Background Job
     * 
     * @param id
     * @return Response
     */
@GET
@Path("/{jid}")
public Response get(@PathParam("jid") String id) {
    log.info("Called get() with id {}", id);
    // No id
    if (id == null || id.equals("")) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    JobManager m = jobManager;
    // If the job exists
    if (m.hasJob(id)) {
        log.info("Found job with id {}", id);
        Future<?> f = m.ping(id);
        //this.info = new JobInfoImpl();
        final JobInfo info = new JobInfoImpl();
        if (f.isDone()) {
            // The job is finished
            if (f.isCancelled()) {
                // NOTE: Canceled jobs should never exist. 
                // The web service remove any deleted process from the manager
                // If a process have been canceled programmatically, it cannot be managed by the service anymore 
                // (except for DELETE)
                log.warn("Job with id {} have been canceled. Returning 404 Not found.", id);
                return Response.status(Response.Status.NOT_FOUND).build();
            } else {
                // Job is complete
                info.setFinished();
                info.addMessage("You can remove this job using DELETE");
            }
        } else {
            // the job exists but it is not complete
            info.setRunning();
            info.addMessage("You can interrupt this job using DELETE");
        }
        // Returns 200, the job exists
        info.setOutputLocation(getPublicBaseUri() + m.getResultLocation(id));
        if (isHTML()) {
            // Result as HTML
            return Response.ok(new Viewable("info", new JobsResultData(info))).build();
        } else {
            // Result as application/json, text/plain
            return Response.ok(info).build();
        }
    } else {
        log.info("No job found with id {}", id);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
}
Also used : JobInfo(org.apache.stanbol.commons.jobs.api.JobInfo) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) JobManager(org.apache.stanbol.commons.jobs.api.JobManager) JobInfoImpl(org.apache.stanbol.commons.jobs.impl.JobInfoImpl) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 JobInfo (org.apache.stanbol.commons.jobs.api.JobInfo)1 JobManager (org.apache.stanbol.commons.jobs.api.JobManager)1 JobInfoImpl (org.apache.stanbol.commons.jobs.impl.JobInfoImpl)1 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)1