Package org.apache.stanbol.commons.jobs.api

Examples of org.apache.stanbol.commons.jobs.api.JobManager


        // No id
        if(id == null || id.equals("")){
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
       
        JobManager m = getJobManager();

        // If the job exists
        if (m.hasJob(id)) {
            log.info("Found job with id {}", id);
            Future<?> f = m.ping(id);
            this.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", this)).build();
            }else{
View Full Code Here


    @Path("/{jid}")
    public Response delete(@PathParam(value = "jid") String jid){
        log.info("Called DELETE ({})", jid);
        if(!jid.equals("")){
            log.info("Looking for test job {}", jid);
            JobManager m = getJobManager();

            // If the job exists
            if (m.hasJob(jid)){
                log.info("Deleting Job id {}", jid);
                m.remove(jid);
                return Response.ok("Job deleted.").build();
            }else {
                log.info("No job found with id {}", jid);
                return Response.status(Response.Status.NOT_FOUND).build();
            }
View Full Code Here

     * @return
     */
    @DELETE
    public Response delete(){
        log.info("Called DELETE all jobs");
        JobManager manager = getJobManager();
        manager.removeAll();
        return Response.ok("All jobs have been deleted.").build();
    }
View Full Code Here

        log.info("Called GET (create test job)");

        // If an Id have been provided, check whether the job has finished and return the result
        if(!jid.equals("")){
            log.info("Looking for test job {}", jid);
            JobManager m = getJobManager();
            // Remove first slash from param value
            jid = jid.substring(1);
           
            // If the job exists
            if (m.hasJob(jid)){
                log.info("Found job with id {}", jid);
                Future<?> f = m.ping(jid);
                if(f.isDone() && (!f.isCancelled())){
                    /**
                     * We return OK with the result
                     */
                    Object o;
                    try {
                        o = f.get();
                        if(o instanceof JobResult){
                            JobResult result = (JobResult) o;
                            return Response.ok(result.getMessage()).build();
                        }else{
                            log.error("Job {} is not a test job", jid);
                            throw new WebApplicationException(Response.Status.NOT_FOUND);
                        }
                    } catch (InterruptedException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    } catch (ExecutionException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    }
                   
                }else{
                    /**
                     * We return 404 with additional info (Content-Location, the related job resource)
                     *
                     * TODO
                     * Change into json representations
                     */
                    String location = getPublicBaseUri() + "jobs/" + jid;
                    String info = new StringBuilder().append("Result not ready.\n").append("Job Location: ").append(location).toString();
                    return Response.status(404).header("Content-Location", location).header("Content-type","text/plain").entity(info).build();
                }
            }else {
                log.info("No job found with id {}", jid);
                return Response.status(Response.Status.NOT_FOUND).build();
            }
        }else{
            // No id have been provided, we create a new test job
            JobManager m = getJobManager();
            String id = m.execute(new Job() {
                @Override
                public JobResult call() throws Exception {
                    for (int i = 0; i < 30; i++) {
                        try {
                            log.info("Test Process is working");
View Full Code Here

            ResponseBuilder rb = Response.status(Status.BAD_REQUEST);
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        }
       
        JobManager m = getJobManager();

        // If the job exists
        if (m.hasJob(id)) {
            log.info("Found job with id {}", id);
            Future<?> f = m.ping(id);
            if(f.isDone() && (!f.isCancelled())){
                /**
                 * We return OK with the result
                 */
                Object o;
View Full Code Here

            ResponseBuilder rb = Response.status(Status.BAD_REQUEST);
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        }
       
        JobManager m = getJobManager();

        // If the job exists
        if (m.hasJob(id)) {
            log.info("Found job with id {}", id);
            Future<?> f = m.ping(id);
            if(f.isDone() && (!f.isCancelled())){
                /**
                 * We return OK with the result
                 */
                Object o;
View Full Code Here

        // No id
        if(id == null || id.equals("")){
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
       
        JobManager m = getJobManager();

        // If the job exists
        if (m.hasJob(id)) {
            log.info("Found job with id {}", id);
            Future<?> f = m.ping(id);
            this.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", this)).build();
            }else{
View Full Code Here

    @Path("/{jid}")
    public Response delete(@PathParam(value = "jid") String jid){
        log.info("Called DELETE ({})", jid);
        if(!jid.equals("")){
            log.info("Looking for test job {}", jid);
            JobManager m = getJobManager();

            // If the job exists
            if (m.hasJob(jid)){
                log.info("Deleting Job id {}", jid);
                m.remove(jid);
                return Response.ok("Job deleted.").build();
            }else {
                log.info("No job found with id {}", jid);
                return Response.status(Response.Status.NOT_FOUND).build();
            }
View Full Code Here

     * @return
     */
    @DELETE
    public Response delete(){
        log.info("Called DELETE all jobs");
        JobManager manager = getJobManager();
        manager.removeAll();
        return Response.ok("All jobs have been deleted.").build();
    }
View Full Code Here

        log.info("Called GET (create test job)");

        // If an Id have been provided, check whether the job has finished and return the result
        if(!jid.equals("")){
            log.info("Looking for test job {}", jid);
            JobManager m = getJobManager();
            // Remove first slash from param value
            jid = jid.substring(1);
           
            // If the job exists
            if (m.hasJob(jid)){
                log.info("Found job with id {}", jid);
                Future<?> f = m.ping(jid);
                if(f.isDone() && (!f.isCancelled())){
                    /**
                     * We return OK with the result
                     */
                    Object o;
                    try {
                        o = f.get();
                        if(o instanceof JobResult){
                            JobResult result = (JobResult) o;
                            return Response.ok(result.getMessage()).build();
                        }else{
                            log.error("Job {} is not a test job", jid);
                            throw new WebApplicationException(Response.Status.NOT_FOUND);
                        }
                    } catch (InterruptedException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    } catch (ExecutionException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    }
                   
                }else{
                    /**
                     * We return 404 with additional info (Content-Location, the related job resource)
                     *
                     * TODO
                     * Change into json representations
                     */
                    String location = getPublicBaseUri() + "jobs/" + jid;
                    String info = new StringBuilder().append("Result not ready.\n").append("Job Location: ").append(location).toString();
                    return Response.status(404).header("Content-Location", location).header("Content-type","text/plain").entity(info).build();
                }
            }else {
                log.info("No job found with id {}", jid);
                return Response.status(Response.Status.NOT_FOUND).build();
            }
        }else{
            // No id have been provided, we create a new test job
            JobManager m = getJobManager();
            String id = m.execute(new Job() {
                @Override
                public JobResult call() throws Exception {
                    for (int i = 0; i < 30; i++) {
                        try {
                            log.info("Test Process is working");
View Full Code Here

TOP

Related Classes of org.apache.stanbol.commons.jobs.api.JobManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.