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();
}
}
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());
}
// }
}
Aggregations