*/
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");
Thread.sleep(1000);
} catch (InterruptedException ie) {}
}
return new JobResult(){
@Override
public String getMessage() {
return "This is a test job";
}