Search in sources :

Example 1 with OptRunContext

use of org.vcell.optimization.OptServerImpl.OptRunContext in project vcell by virtualcell.

the class OptServerImplTest method main.

public static void main(String[] args) {
    try {
        System.setProperty(PropertyLoader.installationRoot, "/Users/schaff/Documents/workspace-modular/vcell");
        System.setProperty(PropertyLoader.pythonExe, "/Users/schaff/anaconda/bin/python");
        PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.COPASI, PythonPackage.LIBSBML, PythonPackage.THRIFT });
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        File optProbFile = new File(ResourceUtil.getVCellOptPythonDir(), "optprob.bin");
        System.out.println("using optProblem: " + optProbFile.getAbsolutePath());
        OptServerImpl optServerImpl = new OptServerImpl();
        OptProblem optProblem = CopasiServicePython.readOptProblem(optProbFile);
        ArrayList<String> jobIDs = new ArrayList<String>();
        jobIDs.add(optServerImpl.submit(optProblem));
        jobIDs.add(optServerImpl.submit(optProblem));
        optServerImpl.start();
        jobIDs.add(optServerImpl.submit(optProblem));
        jobIDs.add(optServerImpl.submit(optProblem));
        boolean done = false;
        while (!done) {
            done = true;
            for (String jobID : jobIDs) {
                OptRunContext optRunContext = optServerImpl.getOptRunContextByOptimizationId(jobID);
                if (optRunContext == null) {
                    throw new RuntimeException("optRunContext was null for id = " + jobID);
                }
                OptRunStatus status = optRunContext.getStatus();
                if (status != OptRunStatus.Complete && status != OptRunStatus.Failed) {
                    done = false;
                }
                if (status == OptRunStatus.Complete) {
                    OptRun optRun = CopasiServicePython.readOptRun(optRunContext.getOptRunBinaryFile());
                    System.out.println("job " + jobID + ": status " + status + " " + optRun.getOptResultSet().toString());
                } else {
                    System.out.println("job " + jobID + ": status " + status);
                }
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
        System.out.println("done with all jobs");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : OptProblem(org.vcell.optimization.thrift.OptProblem) ArrayList(java.util.ArrayList) OptRunContext(org.vcell.optimization.OptServerImpl.OptRunContext) OptRunStatus(org.vcell.optimization.thrift.OptRunStatus) OptRun(org.vcell.optimization.thrift.OptRun) File(java.io.File)

Example 2 with OptRunContext

use of org.vcell.optimization.OptServerImpl.OptRunContext 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)

Aggregations

OptRunContext (org.vcell.optimization.OptServerImpl.OptRunContext)2 OptProblem (org.vcell.optimization.thrift.OptProblem)2 OptRun (org.vcell.optimization.thrift.OptRun)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ResourceException (org.restlet.resource.ResourceException)1 OptRunStatus (org.vcell.optimization.thrift.OptRunStatus)1 VCellApiApplication (org.vcell.rest.VCellApiApplication)1 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)1 PermissionException (org.vcell.util.PermissionException)1