Search in sources :

Example 1 with SimpleJobStatusRepresentation

use of org.vcell.api.common.SimpleJobStatusRepresentation 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 2 with SimpleJobStatusRepresentation

use of org.vcell.api.common.SimpleJobStatusRepresentation in project vcell by virtualcell.

the class SimpleJobStatus method toRep.

public SimpleJobStatusRepresentation toRep() {
    String vcellServerID = this.jobStatus.getServerID().toString();
    String simulationKey = this.jobStatus.getVCSimulationIdentifier().getSimulationKey().toString();
    int taskID = this.jobStatus.getTaskID();
    int jobIndex = this.jobStatus.getJobIndex();
    long submitDate = this.jobStatus.getSubmitDate().getTime();
    User owner = this.simulationMetadata.owner;
    SimpleJobStatusRepresentation.SchedulerStatus schedulerStatus = SimpleJobStatusRepresentation.SchedulerStatus.valueOf(this.jobStatus.getSchedulerStatus().name());
    SimpleJobStatusRepresentation.DetailedState detailedState = SimpleJobStatusRepresentation.DetailedState.valueOf(this.jobStatus.getSimulationMessage().getDetailedState().name());
    String detailedStateMessage = this.jobStatus.getSimulationMessage().getDisplayMessage();
    Long htcJobNumber = null;
    String htcComputeServer = null;
    SimpleJobStatusRepresentation.BatchSystemType htcBatchSystemType = null;
    Date simexe_startDate = null;
    Date simexe_latestUpdateDate = null;
    Date simexe_endDate = null;
    String computeHost = null;
    Boolean hasData = null;
    SimulationExecutionStatus simExeStatus = this.jobStatus.getSimulationExecutionStatus();
    if (simExeStatus != null) {
        HtcJobID htcJobID = simExeStatus.getHtcJobID();
        if (htcJobID != null) {
            htcJobNumber = htcJobID.getJobNumber();
            htcComputeServer = htcJobID.getServer();
            htcBatchSystemType = SimpleJobStatusRepresentation.BatchSystemType.valueOf(htcJobID.getBatchSystemType().name());
        }
        simexe_startDate = simExeStatus.getStartDate();
        simexe_latestUpdateDate = simExeStatus.getLatestUpdateDate();
        simexe_endDate = simExeStatus.getEndDate();
        computeHost = simExeStatus.getComputeHost();
        hasData = simExeStatus.hasData();
    }
    Integer queuePriority = null;
    Date queueDate = null;
    SimpleJobStatusRepresentation.SimulationQueueID queueId = null;
    SimulationQueueEntryStatus simQueueStatus = this.jobStatus.getSimulationQueueEntryStatus();
    if (simQueueStatus != null) {
        queuePriority = simQueueStatus.getQueuePriority();
        queueDate = simQueueStatus.getQueueDate();
        queueId = SimpleJobStatusRepresentation.SimulationQueueID.valueOf(simQueueStatus.getQueueID().name());
    }
    SimpleJobStatusRepresentation rep = new SimpleJobStatusRepresentation(vcellServerID, simulationKey, taskID, jobIndex, new Date(submitDate), owner.getName(), owner.getID().toString(), schedulerStatus, detailedState, detailedStateMessage, htcJobNumber, htcComputeServer, htcBatchSystemType, queuePriority, queueDate, queueId, simexe_startDate, simexe_latestUpdateDate, simexe_endDate, computeHost, hasData);
    return rep;
}
Also used : SimpleJobStatusRepresentation(org.vcell.api.common.SimpleJobStatusRepresentation) User(org.vcell.util.document.User) Date(java.util.Date)

Aggregations

SimpleJobStatusRepresentation (org.vcell.api.common.SimpleJobStatusRepresentation)2 SimpleJobStatus (cbit.vcell.server.SimpleJobStatus)1 SimpleJobStatusQuerySpec (cbit.vcell.server.SimpleJobStatusQuerySpec)1 Gson (com.google.gson.Gson)1 Date (java.util.Date)1 Form (org.restlet.data.Form)1 HttpRequest (org.restlet.engine.adapter.HttpRequest)1 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)1 VCellApiApplication (org.vcell.rest.VCellApiApplication)1 User (org.vcell.util.document.User)1