use of cbit.vcell.server.SimpleJobStatus in project vcell by virtualcell.
the class AdminJobsRestlet method handle.
@Override
public void handle(Request req, Response response) {
if (req.getMethod().equals(Method.GET)) {
try {
VCellApiApplication application = ((VCellApiApplication) getApplication());
// User vcellUser = application.getVCellUser(req.getChallengeResponse(),AuthenticationPolicy.prohibitInvalidCredentials);
// User adminUser = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
// if (!vcellUser.equals(adminUser)) {
// getLogger().severe("AdminJobsRestlet: user '"+vcellUser.toString()+"' is not authorized");
// response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
// response.setEntity("not authorized for this service", MediaType.TEXT_PLAIN);
// return;
// }
HttpRequest request = (HttpRequest) req;
Form form = request.getResourceRef().getQueryAsForm();
String jsonQuery = form.getFirstValue(PARAM_JSON_QUERY, true);
Gson gson = new Gson();
SimpleJobStatusQuerySpec querySpec = new SimpleJobStatusQuerySpec();
if (jsonQuery != null) {
querySpec = gson.fromJson(jsonQuery, SimpleJobStatusQuerySpec.class);
} else {
querySpec.submitLowMS = getLongParam(form, PARAM_SUBMIT_LOW, null);
querySpec.submitHighMS = getLongParam(form, PARAM_SUBMIT_HIGH, null);
querySpec.startLowMS = getLongParam(form, PARAM_START_LOW, null);
querySpec.startHighMS = getLongParam(form, PARAM_START_HIGH, null);
querySpec.endLowMS = getLongParam(form, PARAM_END_LOW, null);
querySpec.endHighMS = getLongParam(form, PARAM_END_HIGH, null);
querySpec.startRow = getIntegerParam(form, PARAM_START_ROW, 0);
querySpec.maxRows = getIntegerParam(form, PARAM_MAX_ROWS, 100);
querySpec.serverId = getStringParam(form, PARAM_SERVERID, null);
querySpec.computeHost = getStringParam(form, PARAM_COMPUTEHOST, null);
querySpec.userid = getStringParam(form, PARAM_USERID, null);
querySpec.simId = getLongParam(form, PARAM_SIMID, null);
querySpec.jobId = getLongParam(form, PARAM_JOBID, null);
querySpec.taskId = getLongParam(form, PARAM_TASKID, null);
querySpec.hasData = getBooleanParam(form, PARAM_HAS_DATA, null);
querySpec.waiting = getBooleanParam(form, PARAM_STATUS_WAITING, true);
querySpec.queued = getBooleanParam(form, PARAM_STATUS_QUEUED, true);
querySpec.dispatched = getBooleanParam(form, PARAM_STATUS_DISPATCHED, true);
querySpec.running = getBooleanParam(form, PARAM_STATUS_RUNNING, true);
querySpec.completed = getBooleanParam(form, PARAM_STATUS_COMPLETED, true);
querySpec.failed = getBooleanParam(form, PARAM_STATUS_FAILED, true);
querySpec.stopped = getBooleanParam(form, PARAM_STATUS_STOPPED, true);
}
if (querySpec.serverId != null) {
querySpec.serverId = querySpec.serverId.toLowerCase();
}
AdminService adminService = application.getAdminService();
SimpleJobStatus[] jobStatusArray = adminService.query(querySpec);
SimpleJobStatusRepresentation[] reps = new SimpleJobStatusRepresentation[jobStatusArray.length];
for (int i = 0; i < jobStatusArray.length; i++) {
reps[i] = jobStatusArray[i].toRep();
}
String jobStatusArrayJson = gson.toJson(reps);
response.setStatus(Status.SUCCESS_OK);
response.setEntity(new JsonRepresentation(jobStatusArrayJson));
} catch (Exception e) {
getLogger().severe("failed to retrieve job status: " + e.getMessage());
e.printStackTrace();
response.setStatus(Status.SERVER_ERROR_INTERNAL);
response.setEntity("failed to retrieve job status: " + e.getMessage(), MediaType.TEXT_PLAIN);
}
}
}
use of cbit.vcell.server.SimpleJobStatus in project vcell by virtualcell.
the class AdminService method query.
public SimpleJobStatus[] query(SimpleJobStatusQuerySpec querySpec) throws ObjectNotFoundException, DataAccessException {
SimulationDatabase simDatabase = new SimulationDatabaseDirect(adminDbTop, dbServerImpl, false);
SimpleJobStatus[] resultList = simDatabase.getSimpleJobStatus(null, querySpec);
return resultList;
}
use of cbit.vcell.server.SimpleJobStatus in project vcell by virtualcell.
the class SimulationDatabaseDirect method getSimpleJobStatus.
@Override
public SimpleJobStatus[] getSimpleJobStatus(User user, SimpleJobStatusQuerySpec simStatusQuerySpec) throws ObjectNotFoundException, DataAccessException {
//
// create corresponding SimpleJobStatus[] from SimpleJobStatusPersistent[]
// 1) get SimpleJobStatusPersistent from database (with stored status, metadata, and documentLinks - but no stateInfo)
// 2) if already in cache, use SimulationJobStatus and stateInfo from cache.
// 3) if not in cache, use SimulationJobStatus from database and no stateInfo, populate cache.
//
List<SimpleJobStatusPersistent> simpleJobStatusPersistentList = databaseServerImpl.getSimpleJobStatus(simStatusQuerySpec);
ArrayList<SimpleJobStatus> simpleJobStatusList = new ArrayList<SimpleJobStatus>();
for (SimpleJobStatusPersistent simpleJobStatusPersistent : simpleJobStatusPersistentList) {
SimulationJobStatusPersistent simJobStatusDb = simpleJobStatusPersistent.jobStatus;
SimJobStatusKey key = new SimJobStatusKey(simpleJobStatusPersistent.simulationMetadata.vcSimID.getSimulationKey(), simJobStatusDb.getJobIndex(), simJobStatusDb.getTaskID());
SimStatusCacheEntry simStatusCacheEntry = cache.get(key);
// TODO need to get this from memory cache.
StateInfo cachedStateInfo = null;
SimulationJobStatus latestSimulationJobStatus = null;
if (simStatusCacheEntry != null) {
cachedStateInfo = simStatusCacheEntry.stateInfo;
latestSimulationJobStatus = simStatusCacheEntry.jobStatus;
} else {
latestSimulationJobStatus = translateToSimulationJobStatusTransient(simJobStatusDb);
cache.put(key, new SimStatusCacheEntry(latestSimulationJobStatus, null));
}
SimpleJobStatus bestSimpleJobStatus = translateToSimpleJobStatusTransient(simpleJobStatusPersistent, latestSimulationJobStatus, cachedStateInfo);
// uses latest SimulationJobStatus and StateInfo.
simpleJobStatusList.add(bestSimpleJobStatus);
}
return simpleJobStatusList.toArray(new SimpleJobStatus[simpleJobStatusList.size()]);
}
Aggregations