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