Search in sources :

Example 1 with SimulationTaskRepresentation

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

the class VCellApiClient method getSimTasks.

public SimulationTaskRepresentation[] getSimTasks(SimTasksQuerySpec simTasksQuerySpec) throws IOException {
    HttpGet httpget = new HttpGet("https://" + httpHost.getHostName() + ":" + httpHost.getPort() + "/simtask?" + simTasksQuerySpec.getQueryString());
    if (lg.isInfoEnabled()) {
        lg.info("Executing request to retrieve simulation tasks " + httpget.getRequestLine());
    }
    String responseBody = httpclient.execute(httpget, new VCellStringResponseHandler("getSimTasks()", httpget), httpClientContext);
    String simTasksJson = responseBody;
    if (lg.isInfoEnabled()) {
        lg.info("returned: " + toStringTruncated(simTasksJson));
    }
    Gson gson = new Gson();
    SimulationTaskRepresentation[] simTaskReps = gson.fromJson(simTasksJson, SimulationTaskRepresentation[].class);
    return simTaskReps;
}
Also used : SimulationTaskRepresentation(org.vcell.api.common.SimulationTaskRepresentation) HttpGet(org.apache.http.client.methods.HttpGet) Gson(com.google.gson.Gson)

Example 2 with SimulationTaskRepresentation

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

the class VCellApiClient method startSimulation.

public SimulationTaskRepresentation[] startSimulation(String bmId, String simKey) throws IOException {
    HttpPost httppost = new HttpPost("https://" + httpHost.getHostName() + ":" + httpHost.getPort() + "/biomodel/" + bmId + "/simulation/" + simKey + "/startSimulation");
    if (lg.isInfoEnabled()) {
        lg.info("Executing request to retrieve simulation " + httppost.getRequestLine());
    }
    String responseBody = httpclient.execute(httppost, new VCellStringResponseHandler("startSimulation()", httppost), httpClientContext);
    String simTaskReps = responseBody;
    if (lg.isInfoEnabled()) {
        lg.info("returned: " + toStringTruncated(simTaskReps));
    }
    if (responseBody.equals("simulation start failed")) {
        throw new RuntimeException("simulation start failed for SimID=" + simKey + " within BioModelKey=" + bmId);
    } else {
        Gson gson = new Gson();
        SimulationTaskRepresentation[] simulationTaskRepresentations = gson.fromJson(simTaskReps, SimulationTaskRepresentation[].class);
        return simulationTaskRepresentations;
    }
}
Also used : SimulationTaskRepresentation(org.vcell.api.common.SimulationTaskRepresentation) HttpPost(org.apache.http.client.methods.HttpPost) Gson(com.google.gson.Gson)

Example 3 with SimulationTaskRepresentation

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

the class VCellApiClient method stopSimulation.

public SimulationTaskRepresentation[] stopSimulation(String bmId, String simKey) throws IOException {
    HttpPost httppost = new HttpPost("https://" + httpHost.getHostName() + ":" + httpHost.getPort() + "/biomodel/" + bmId + "/simulation/" + simKey + "/stopSimulation");
    if (lg.isInfoEnabled()) {
        lg.info("Executing request to retrieve simulation " + httppost.getRequestLine());
    }
    String responseBody = httpclient.execute(httppost, new VCellStringResponseHandler("stopSimulation()", httppost), httpClientContext);
    String simTaskReps = responseBody;
    if (lg.isInfoEnabled()) {
        lg.info("returned: " + toStringTruncated(simTaskReps));
    }
    Gson gson = new Gson();
    SimulationTaskRepresentation[] simulationTaskRepresentations = gson.fromJson(simTaskReps, SimulationTaskRepresentation[].class);
    return simulationTaskRepresentations;
}
Also used : SimulationTaskRepresentation(org.vcell.api.common.SimulationTaskRepresentation) HttpPost(org.apache.http.client.methods.HttpPost) Gson(com.google.gson.Gson)

Example 4 with SimulationTaskRepresentation

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

the class VCSchedulerPanel method refreshCount.

private void refreshCount() throws IOException {
    if (vcellApiClient != null) {
        StringBuffer buffer = new StringBuffer();
        SimTasksQuerySpec simTasksQuerySpec = new SimTasksQuerySpec();
        simTasksQuerySpec.waiting = "on";
        simTasksQuerySpec.queued = "on";
        simTasksQuerySpec.dispatched = "on";
        simTasksQuerySpec.running = "on";
        simTasksQuerySpec.completed = "off";
        simTasksQuerySpec.failed = "off";
        simTasksQuerySpec.stopped = "off";
        simTasksQuerySpec.maxRows = "1000";
        SimulationTaskRepresentation[] simTaskReps = vcellApiClient.getSimTasks(simTasksQuerySpec);
        int numWaiting = 0;
        int numQueued = 0;
        int numDispatched = 0;
        int numRunning = 0;
        for (SimulationTaskRepresentation simTaskRep : simTaskReps) {
            buffer.append(toString(simTaskRep));
            if (simTaskRep.getStatus().equals("waiting")) {
                numWaiting++;
            } else if (simTaskRep.getStatus().equals("queued")) {
                numQueued++;
            } else if (simTaskRep.getStatus().equals("dispatched")) {
                numDispatched++;
            } else if (simTaskRep.getStatus().equals("running")) {
                numRunning++;
            }
        }
        this.lblWaitingValue.setText("" + numWaiting);
        this.lblQueuedValue.setText("" + numQueued);
        this.lblDispatchedValue.setText("" + numDispatched);
        this.lblRunningValue.setText("" + numRunning);
        setText(buffer.toString());
    } else {
        setText("vcellApiClient is null");
    }
}
Also used : SimulationTaskRepresentation(org.vcell.api.common.SimulationTaskRepresentation) SimTasksQuerySpec(org.vcell.api.client.query.SimTasksQuerySpec)

Example 5 with SimulationTaskRepresentation

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

the class VCellApiClientTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    VCellApiClient vcellApiClient = null;
    try {
        if (args.length != 4 && args.length != 5) {
            System.out.println("usage: VCellApiClient host port userid password [clientID]");
            System.exit(1);
        }
        String host = args[0];
        int port = Integer.parseInt(args[1]);
        String username = args[2];
        String password = args[3];
        boolean bIgnoreCertProblems = true;
        boolean bIgnoreHostMismatch = true;
        vcellApiClient = new VCellApiClient(host, port, bIgnoreCertProblems, bIgnoreHostMismatch);
        vcellApiClient.authenticate(username, password, false);
        // test /biomodel[? query string]
        BiomodelRepresentation[] biomodelReps = vcellApiClient.getBioModels(new BioModelsQuerySpec());
        for (BiomodelRepresentation biomodelRep : biomodelReps) {
            System.out.println("biomodel : " + biomodelRep.getBmKey() + " : " + biomodelRep.getName());
            for (ApplicationRepresentation appRep : biomodelRep.getApplications()) {
                System.out.println("   app : " + appRep.getName());
            }
            for (SimulationRepresentation simRep : biomodelRep.getSimulations()) {
                System.out.println("   sim : " + simRep.getName());
            }
        }
        boolean bFirstSimulationToStartStop = true;
        if (biomodelReps.length > 0) {
            // test /biomodel/[bmkey]
            System.out.println(" ... re-fetching first biomodel owned by me ...");
            BioModelsQuerySpec bioModelsQuerySpec = new BioModelsQuerySpec();
            bioModelsQuerySpec.owner = username;
            BiomodelRepresentation firstBiomodelRep = vcellApiClient.getBioModels(bioModelsQuerySpec)[0];
            System.out.println("biomodel : " + firstBiomodelRep.getBmKey() + " : " + firstBiomodelRep.getName());
            for (ApplicationRepresentation appRep : firstBiomodelRep.getApplications()) {
                System.out.println("   appRep : " + appRep.getName());
            }
            for (SimulationRepresentation simRep : firstBiomodelRep.getSimulations()) {
                System.out.println("   simRep (returned with BioModelRep) : " + simRep.getKey() + " : " + simRep.getName());
                // test /biomodel/[bmkey]/simulation/simkey
                SimulationRepresentation simulation = vcellApiClient.getSimulation(firstBiomodelRep.getBmKey(), simRep.getKey());
                System.out.println("   simRep (retrieved separately) : " + simulation.getKey() + " : " + simulation.getName());
                if (bFirstSimulationToStartStop) {
                    bFirstSimulationToStartStop = false;
                    // test /biomodel/[bmkey]/simulation/[simkey]/startSimulation
                    SimTasksQuerySpec simTasksQuerySpec = new SimTasksQuerySpec();
                    simTasksQuerySpec.simId = simRep.getKey();
                    SimulationTaskRepresentation[] beforeStartSimTasks = vcellApiClient.getSimTasks(simTasksQuerySpec);
                    System.out.println("SENDING START SIMULATION");
                    SimulationTaskRepresentation[] justAfterStartSimTasks = vcellApiClient.startSimulation(firstBiomodelRep.getBmKey(), simRep.getKey());
                    System.out.println("SENT START SIMULATION");
                    System.out.println("WAITING 5 seconds");
                    try {
                        Thread.sleep(5000);
                    } catch (Exception e) {
                    }
                    SimulationTaskRepresentation[] longAfterStartSimTasks = vcellApiClient.getSimTasks(simTasksQuerySpec);
                    System.out.println("SENDING STOP SIMULATION");
                    SimulationTaskRepresentation[] justAfterStopSimTasks = vcellApiClient.stopSimulation(firstBiomodelRep.getBmKey(), simRep.getKey());
                    System.out.println("SENT STOP SIMULATION");
                    System.out.println("WAITING 5 seconds");
                    try {
                        Thread.sleep(5000);
                    } catch (Exception e) {
                    }
                    SimulationTaskRepresentation[] longAfterStopSimTasks = vcellApiClient.getSimTasks(simTasksQuerySpec);
                    System.out.println("\n\nsimulation status:");
                    for (SimulationTaskRepresentation simTaskRep : beforeStartSimTasks) {
                        System.out.println("    BEFORE START Job = " + simTaskRep.getJobIndex() + ", Task = " + simTaskRep.getTaskId() + ", Status = " + simTaskRep.getStatus());
                    }
                    for (SimulationTaskRepresentation simTaskRep : justAfterStartSimTasks) {
                        System.out.println("    JUST AFTER START Job = " + simTaskRep.getJobIndex() + ", Task = " + simTaskRep.getTaskId() + ", Status = " + simTaskRep.getStatus());
                    }
                    for (SimulationTaskRepresentation simTaskRep : longAfterStartSimTasks) {
                        System.out.println("    LONG AFTER START Job = " + simTaskRep.getJobIndex() + ", Task = " + simTaskRep.getTaskId() + ", Status = " + simTaskRep.getStatus());
                    }
                    for (SimulationTaskRepresentation simTaskRep : justAfterStopSimTasks) {
                        System.out.println("    JUST AFTER STOP Job = " + simTaskRep.getJobIndex() + ", Task = " + simTaskRep.getTaskId() + ", Status = " + simTaskRep.getStatus());
                    }
                    for (SimulationTaskRepresentation simTaskRep : longAfterStopSimTasks) {
                        System.out.println("    LONG AFTER STOP Job = " + simTaskRep.getJobIndex() + ", Task = " + simTaskRep.getTaskId() + ", Status = " + simTaskRep.getStatus());
                    }
                    System.out.println("\n\n");
                }
                System.out.println("\n");
            }
        }
        // test /simtask
        SimulationTaskRepresentation[] simTaskReps = vcellApiClient.getSimTasks(new SimTasksQuerySpec());
        for (SimulationTaskRepresentation simTaskRep : simTaskReps) {
            System.out.println("simTask : " + simTaskRep.getSimKey() + " : " + simTaskRep.getSimName());
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    } finally {
        if (vcellApiClient != null) {
            try {
                vcellApiClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : BiomodelRepresentation(org.vcell.api.common.BiomodelRepresentation) IOException(java.io.IOException) VCellApiClient(org.vcell.api.client.VCellApiClient) IOException(java.io.IOException) SimulationRepresentation(org.vcell.api.common.SimulationRepresentation) SimulationTaskRepresentation(org.vcell.api.common.SimulationTaskRepresentation) SimTasksQuerySpec(org.vcell.api.client.query.SimTasksQuerySpec) ApplicationRepresentation(org.vcell.api.common.ApplicationRepresentation) BioModelsQuerySpec(org.vcell.api.client.query.BioModelsQuerySpec)

Aggregations

SimulationTaskRepresentation (org.vcell.api.common.SimulationTaskRepresentation)5 Gson (com.google.gson.Gson)3 HttpPost (org.apache.http.client.methods.HttpPost)2 SimTasksQuerySpec (org.vcell.api.client.query.SimTasksQuerySpec)2 IOException (java.io.IOException)1 HttpGet (org.apache.http.client.methods.HttpGet)1 VCellApiClient (org.vcell.api.client.VCellApiClient)1 BioModelsQuerySpec (org.vcell.api.client.query.BioModelsQuerySpec)1 ApplicationRepresentation (org.vcell.api.common.ApplicationRepresentation)1 BiomodelRepresentation (org.vcell.api.common.BiomodelRepresentation)1 SimulationRepresentation (org.vcell.api.common.SimulationRepresentation)1