Search in sources :

Example 11 with SimpleJobStatus

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);
        }
    }
}
Also used : HttpRequest(org.restlet.engine.adapter.HttpRequest) SimpleJobStatusQuerySpec(cbit.vcell.server.SimpleJobStatusQuerySpec) SimpleJobStatusRepresentation(org.vcell.api.common.SimpleJobStatusRepresentation) Form(org.restlet.data.Form) Gson(com.google.gson.Gson) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus) VCellApiApplication(org.vcell.rest.VCellApiApplication) JsonRepresentation(org.restlet.ext.json.JsonRepresentation)

Example 12 with SimpleJobStatus

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;
}
Also used : SimulationDatabase(cbit.vcell.message.server.dispatcher.SimulationDatabase) SimulationDatabaseDirect(cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Example 13 with SimpleJobStatus

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()]);
}
Also used : StateInfo(cbit.vcell.server.StateInfo) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) ArrayList(java.util.ArrayList) SimpleJobStatusPersistent(cbit.vcell.server.SimpleJobStatusPersistent) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Aggregations

SimpleJobStatus (cbit.vcell.server.SimpleJobStatus)13 SimpleJobStatusQuerySpec (cbit.vcell.server.SimpleJobStatusQuerySpec)4 ArrayList (java.util.ArrayList)4 BigString (org.vcell.util.BigString)4 BioModelLink (cbit.vcell.server.BioModelLink)3 MathModelLink (cbit.vcell.server.MathModelLink)3 SQLException (java.sql.SQLException)3 Date (java.util.Date)3 DataAccessException (org.vcell.util.DataAccessException)3 PermissionException (org.vcell.util.PermissionException)3 MappingException (cbit.vcell.mapping.MappingException)2 MathException (cbit.vcell.math.MathException)2 MatrixException (cbit.vcell.matrix.MatrixException)2 VCMessageSession (cbit.vcell.message.VCMessageSession)2 SimulationDatabase (cbit.vcell.message.server.dispatcher.SimulationDatabase)2 SimulationDatabaseDirect (cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect)2 ModelException (cbit.vcell.model.ModelException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)2 SchedulerStatus (cbit.vcell.server.SimulationJobStatus.SchedulerStatus)2