Search in sources :

Example 6 with OptRun

use of org.vcell.optimization.thrift.OptRun in project vcell by virtualcell.

the class OptServerImpl method runNextWaitingOptProblem.

public void runNextWaitingOptProblem() {
    OptRunContext optRunContext = null;
    synchronized (optRunContexts) {
        for (int i = 0; i < optRunContexts.size(); i++) {
            if (optRunContexts.get(i).optRunStatus == OptRunStatus.Queued) {
                optRunContext = optRunContexts.get(i);
                optRunContext.optRunStatus = OptRunStatus.Running;
                System.err.println("OptServerImpl - starting optimizationId " + optRunContext.optimizationId);
                break;
            }
        }
    }
    try {
        if (optRunContext != null) {
            OptProblem optProblem = CopasiServicePython.readOptProblem(optRunContext.getOptProblemBinaryFile());
            CopasiServicePython.writeOptProblem(optRunContext.getOptProblemBinaryFile(), optProblem);
            CopasiServicePython.runCopasiPython(optRunContext.getOptProblemBinaryFile(), optRunContext.getOptRunBinaryFile());
            OptRun optRun = CopasiServicePython.readOptRun(optRunContext.getOptRunBinaryFile());
            System.out.println("ran optRun id " + optRunContext.optimizationId + ": status=" + optRun.statusMessage + ": (" + optRun.getOptResultSet().toString() + ")");
            synchronized (optRunContexts) {
                optRunContext.optRunStatus = OptRunStatus.Complete;
                System.err.println("OptServerImpl - optimizationId " + optRunContext.optimizationId + " status=" + OptRunStatus.Complete);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        synchronized (optRunContexts) {
            optRunContext.optRunStatus = OptRunStatus.Failed;
            System.err.println("OptServerImpl - optimizationId " + optRunContext.optimizationId + " status=" + OptRunStatus.Failed);
        }
    }
}
Also used : OptProblem(org.vcell.optimization.thrift.OptProblem) OptRun(org.vcell.optimization.thrift.OptRun) IOException(java.io.IOException)

Example 7 with OptRun

use of org.vcell.optimization.thrift.OptRun in project vcell by virtualcell.

the class OptimizationServerResource method getOptRun.

private OptRun getOptRun(User vcellUser) {
    // }else{
    try {
        String optimizationId = (String) getRequestAttributes().get(VCellApiApplication.OPTIMIZATIONID);
        VCellApiApplication application = ((VCellApiApplication) getApplication());
        OptRunContext optRunContext = application.getOptServerImpl().getOptRunContextByOptimizationId(optimizationId);
        if (optRunContext == null) {
            throw new ObjectNotFoundException("optimization id '" + optimizationId + "' not found");
        }
        switch(optRunContext.getStatus()) {
            case Complete:
                {
                    OptRun optRun = CopasiServicePython.readOptRun(optRunContext.getOptRunBinaryFile());
                    return optRun;
                }
            case Queued:
            case Running:
            case Failed:
                {
                    OptProblem optProblem = CopasiServicePython.readOptProblem(optRunContext.getOptProblemBinaryFile());
                    OptRun optRun = new OptRun();
                    optRun.setOptProblem(optProblem);
                    optRun.setStatus(optRunContext.getStatus());
                    optRun.setStatusMessage(optRunContext.getStatus().name());
                    return optRun;
                }
            default:
                {
                    throw new RuntimeException("unexpected optimization status '" + optRunContext.getStatus() + "'");
                }
        }
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "optimization not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) OptRunContext(org.vcell.optimization.OptServerImpl.OptRunContext) OptProblem(org.vcell.optimization.thrift.OptProblem) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OptRun(org.vcell.optimization.thrift.OptRun) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 8 with OptRun

use of org.vcell.optimization.thrift.OptRun in project vcell by virtualcell.

the class OptimizationServerResource method get_html.

@Override
public Representation get_html() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    OptRun optRun = getOptRun(vcellUser);
    if (optRun == null) {
        throw new RuntimeException("optimization not found");
    }
    try {
        Map<String, Object> dataModel = new HashMap<String, Object>();
        // +"?"+VCellApiApplication.REDIRECTURL_FORMNAME+"="+getRequest().getResourceRef().toUrl());
        dataModel.put("loginurl", "/" + VCellApiApplication.LOGINFORM);
        dataModel.put("logouturl", "/" + VCellApiApplication.LOGOUT + "?" + VCellApiApplication.REDIRECTURL_FORMNAME + "=" + Reference.encode(getRequest().getResourceRef().toUrl().toString()));
        if (vcellUser != null) {
            dataModel.put("userid", vcellUser.getName());
        }
        dataModel.put("optId", getQueryValue(VCellApiApplication.OPTIMIZATIONID));
        TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
        String optRunJson = new String(serializer.serialize(optRun));
        dataModel.put("optimization", new JSONObject(optRunJson));
        dataModel.put("jsonResponse", optRunJson);
        Configuration templateConfiguration = application.getTemplateConfiguration();
        Representation formFtl = new ClientResource(LocalReference.createClapReference("/optimization.ftl")).get();
        TemplateRepresentation templateRepresentation = new TemplateRepresentation(formFtl, templateConfiguration, dataModel, MediaType.TEXT_HTML);
        return templateRepresentation;
    } catch (Exception e) {
        e.printStackTrace();
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) User(org.vcell.util.document.User) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) TemplateRepresentation(org.restlet.ext.freemarker.TemplateRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Representation(org.restlet.representation.Representation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) TSerializer(org.apache.thrift.TSerializer) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) JSONObject(org.json.JSONObject) OptRun(org.vcell.optimization.thrift.OptRun) VCellApiApplication(org.vcell.rest.VCellApiApplication) ClientResource(org.restlet.resource.ClientResource) JSONObject(org.json.JSONObject) ResourceException(org.restlet.resource.ResourceException)

Example 9 with OptRun

use of org.vcell.optimization.thrift.OptRun in project vcell by virtualcell.

the class OptimizationServerResource method get_json.

@Override
public JsonRepresentation get_json() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    OptRun optRun = getOptRun(vcellUser);
    try {
        TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
        String optRunJson = new String(serializer.serialize(optRun));
        JsonRepresentation optRunJsonRep = new JsonRepresentation(optRunJson);
        return optRunJsonRep;
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : TSerializer(org.apache.thrift.TSerializer) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) User(org.vcell.util.document.User) OptRun(org.vcell.optimization.thrift.OptRun) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Aggregations

OptRun (org.vcell.optimization.thrift.OptRun)9 OptProblem (org.vcell.optimization.thrift.OptProblem)6 IOException (java.io.IOException)4 TSerializer (org.apache.thrift.TSerializer)4 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)4 File (java.io.File)3 TDeserializer (org.apache.thrift.TDeserializer)3 ResourceException (org.restlet.resource.ResourceException)3 OptRunStatus (org.vcell.optimization.thrift.OptRunStatus)3 VCellApiApplication (org.vcell.rest.VCellApiApplication)3 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)3 PermissionException (org.vcell.util.PermissionException)3 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)2 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)2 OptRunResultSet (cbit.vcell.opt.OptSolverResultSet.OptRunResultSet)2 OptimizationException (cbit.vcell.opt.OptimizationException)2 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)2 OptimizationStatus (cbit.vcell.opt.OptimizationStatus)2 ArrayList (java.util.ArrayList)2 TException (org.apache.thrift.TException)2