Home » Eclipse Projects » Spatiotemporal Epidemiological Modeler (STEM) » Web interface?
|
Re: Web interface? [message #522018 is a reply to message #521978] |
Fri, 19 March 2010 16:17 |
Matthew Davis Messages: 269 Registered: July 2009 |
Senior Member |
|
|
Hi Doug,
We have some internal work on a Web-based STEM interface, but it's not really in a condition for public release at this time. It's really more of a proof-of-concept/what we can do. Right now, it's just a collection of JSON-generating servlets with a Dojo interface and visualizer built with Google Maps. Simulation controls are mainly related to state (start, stop, etc). The underlying container is running Jetty as an Eclipse plug-in. See: http://www.eclipse.org/equinox/server/
As for the hooks to control STEM through an API, my recommendation is that you start by looking at the SimulationManager and Simulation classes in in the org.eclipse.stem.jobs plug-in.
To initialize and run a headless simulation, pulling from our Web code, here's a very simple set of steps. Obviously any real system will be more advanced, but this is a basic startup. Note that the project name and scenario name correspond to projects and scenarios you created using the STEM UI.
import org.eclipse.emf.common.util.URI;
import org.eclipse.stem.core.Utility;
import org.eclipse.stem.core.scenario.Scenario;
import org.eclipse.stem.jobs.simulation.SimulationManager;
import org.eclipse.stem.jobs.simulation.ISimulation;
import org.eclipse.stem.jobs.simulation.Simulation;
...
String projectName = "somestemproject";
String scenarioName = "somescenarioname.scenario";
// Get the internal URI to the Scenario resource file in the workspace
URI scenarioUri = URI.createURI("platform:/resource/"+ projectName +"/scenarios/"+ scenarioName);
// Load the scenario from file
Scenario scenario = (Scenario)Utility.getIdentifiable(scenarioUri);
// Get the simulation manager
SimulationManager mgr = SimulationManager.getManager();
// Create a runnable simulation from the given scenario
ISimulation sim = mgr.createSimulation(scenario);
// Run the simulation
mgr.runSimulation(sim);
|
|
| | |
Re: Web interface? [message #525562 is a reply to message #522018] |
Tue, 06 April 2010 21:41 |
Doug Messages: 30 Registered: March 2010 |
Member |
|
|
I am still having trouble with this... I have what are probably lots of very basic questions. I have very limited time available to try to learn Eclipse and STEM, so perhaps this just isn't going to work out right now.
To simplify, I dropped the web app part for now and just want to create a standalone, command line version of STEM where parameters can be passed to specify the scenario, for example. I started with the code from Matt above, but swapped the last 4 lines for:
// Create a runnable simulation from the given scenario and run it
mgr.createAndRunSimulation(scenario);
(the version above was causing errors, but I don't recall what off the top of my head)
I assume I want to develop my command line driver as a plug-in, then set up a product configuration to export it as a standalone Eclipse application (I still can't seem to get that working for STEM itself, per this thread).
I have scenarios created from the version of STEM I downloaded, but can't seem to load them. Where would I need to copy/import/??? my "US-Flu" project in order to load its "test.scenario"?
If I run as a Java application, my working directory = C:\Documents and Settings\drafalsk\workspace\headlessSTEM, and
scenarioUri.toString() = platform:/resource/US-Flu/scenarios/test.scenario
scenarioUri.toFileString() = null
The code
Scenario scenario = (Scenario)Utility.getIdentifiable(scenarioUri);
Then fails withQuote: |
The serialized instance of an Identifiable at "platform:/resource/USFlu/scenarios/test.scenario" was not found or was of the wrong format
|
|
|
|
Re: Web interface? [message #526140 is a reply to message #525562] |
Thu, 08 April 2010 20:40 |
Matthew Davis Messages: 269 Registered: July 2009 |
Senior Member |
|
|
Hi Doug,
I suspect the problem here is launching as Java application. STEM has strong dependencies on the Eclipse environment that you only get when launching as an Eclipse application. If you launch, even in Eclipse, as "Java Application", it stills runs in the barebones JVM. To launch with STEM, it has to run in a JVM with the Eclipse/OSGi environment loaded and the Eclipse Workbench launched.
You can still do this headless-ly, it just requires writing the correct boilerplate to run as an Eclipse application - notable a launcher class that implements IApplication and the correct entry in plugin.xml.
First, take a look at the org.eclipse.equinox.app.IApplication interface:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/reference/api/org/eclipse/equinox/app/IApp lication.html
At the very least, the class implementing this interface contains a method that can act like a standard main(String[] args) to the Eclipse platform. There's generally much more to this, but you can get started here and run code directly from start(...).
After creating that class, you have to register it in the underlying Platform so Eclipse/OSGi knows about it. Easiest way to do this is add an entry into your plugin's plugin.xml file with the application registration:
Again, a very simple example:
<extension
point="org.eclipse.core.runtime.applications"
id="MyApplicationLoader">
<application>
<run
class="org.example.path.to.MyApplicationLoader">
</run>
</application>
</extension>
Now you should be able to right click on your project and "Run as Eclipse Application", which will cause the loader to get invoked. You'll probably have to fix the run configurations and maybe the OSGi plug-in relationships, but it should allow you to get full access to STEM's API.
|
|
| | |
Re: Web interface? [message #528167 is a reply to message #526140] |
Mon, 19 April 2010 15:02 |
Doug Messages: 30 Registered: March 2010 |
Member |
|
|
I've been out on travel and didn't get to it right away, but this was very helpful, and I have been able to create my headless version.
I am still working out the details, but I can export my own executable. I still haven't figured out how to access my pre-existing STEM projects/scenarios yet. I'll outline my method, let me know if I am heading the wrong way.
1) Export my project as Eclipse Product. It creates eclipse and repository folders, and the executable in the eclipse folder is named per my project, headlessSTEM.exe.
2) I copied the workspace folder from my official STEM release to the eclipse folder of my headless version. (This is probably wrong, as there is probably more to importing pre-existing projects, but is what I tried so far.)
3) The code for my application is based off of the example noted above. For now I have a loop reading strings from the command line arguments expected to be scenario names. I just have the project name fixed, then I construct the URI with the scenario name.
The code does not seem to be able to locate the project/scenario. The scenario name passed was "DougScenario.scenario". This is in the "scenarios" folder in the "US-Flu" folder in workspace. The error is:
Quote: | !ENTRY org.eclipse.stem.core 4 0 2010-04-19 09:28:10.347
!MESSAGE The serialized instance of an Identifiable at "platform:/resource/US-Flu/scenarios/DougScenario.scenario" was not found or was of the wrong format
!STACK 0
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/US-Flu/scenarios/DougScenario.scenario' does not exist.
|
Relevant code trying to run the scenario:
String projectName = "US-Flu";
//String scenarioName = "DougScenario.scenario";
for (String scenarioName: args) {
// Get the internal URI to the Scenario resource file in the workspace
URI scenarioUri = URI.createURI("platform:/resource/"+ projectName +"/scenarios/"+ scenarioName);
System.out.println("Working Directory = " + System.getProperty("user.dir"));
System.out.println("Scenario URI = "+scenarioUri.toString()+" ==> "+scenarioUri.path()+" ==> "+scenarioUri.toFileString());
// Load the scenario from file
Scenario scenario = (Scenario)Utility.getIdentifiable(scenarioUri);
// Get the simulation manager
SimulationManager mgr = SimulationManager.getManager();
// Create/run simulation from the given scenario
mgr.createAndRunSimulation(scenario);
}
I'll play with it more this week, but welcome any comments (especially if there is something obviously wrong
|
|
|
Re: Web interface? [message #528795 is a reply to message #528167] |
Wed, 21 April 2010 19:01 |
Matthew Davis Messages: 269 Registered: July 2009 |
Senior Member |
|
|
Hi Doug,
First question is whether the US-Flu project and DougScenario scenario are visible in your official STEM instance's Project Explorer. You're right that you cannot just copy a folder into an Eclipse workspace and it show up, it must be done in a way that the workbench metadata is updated (either using the "Import" mechanism or by refreshing the workspace). If so, then you should be able to copy and paste the workspace as-is.
Second is to make sure your headless STEM instance is loading the correct workspace path. Normally it's ./workspace relative to the executable, but not always. You can override this by passing the -data parameter to headlessSTEM.exe with a path to your workspace. You might try specifying an absolute path just to make sure it's loading the correct workspace.
[Updated on: Wed, 21 April 2010 20:36] Report message to a moderator
|
|
|
Re: Web interface? [message #563244 is a reply to message #525562] |
Thu, 08 April 2010 20:40 |
Matthew Davis Messages: 269 Registered: July 2009 |
Senior Member |
|
|
Hi Doug,
I suspect the problem here is launching as Java application. STEM has strong dependencies on the Eclipse environment that you only get when launching as an Eclipse application. If you launch, even in Eclipse, as "Java Application", it stills runs in the barebones JVM. To launch with STEM, it has to run in a JVM with the Eclipse/OSGi environment loaded and the Eclipse Workbench launched.
You can still do this headless-ly, it just requires writing the correct boilerplate to run as an Eclipse application - notable a launcher class that implements IApplication and the correct entry in plugin.xml.
First, take a look at the org.eclipse.equinox.app.IApplication interface:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/reference/api/org/eclipse/equinox/app/IApp lication.html
At the very least, the class implementing this interface contains a method that can act like a standard main(String[] args) to the Eclipse platform. There's generally much more to this, but you can get started here and run code directly from start(...).
After creating that class, you have to register it in the underlying Platform so Eclipse/OSGi knows about it. Easiest way to do this is add an entry into your plugin's plugin.xml file with the application registration:
Again, a very simple example:
<extension
point="org.eclipse.core.runtime.applications"
id="MyApplicationLoader">
<application>
<run
class="org.example.path.to.MyApplicationLoader">
</run>
</application>
</extension>
Now you should be able to right click on your project and "Run as Eclipse Application", which will cause the loader to get invoked. You'll probably have to fix the run configurations and maybe the OSGi plug-in relationships, but it should allow you to get full access to STEM's API.
|
|
| | |
Re: Web interface? [message #563304 is a reply to message #526140] |
Mon, 19 April 2010 15:02 |
Doug Messages: 30 Registered: March 2010 |
Member |
|
|
I've been out on travel and didn't get to it right away, but this was very helpful, and I have been able to create my headless version.
I am still working out the details, but I can export my own executable. I still haven't figured out how to access my pre-existing STEM projects/scenarios yet. I'll outline my method, let me know if I am heading the wrong way.
1) Export my project as Eclipse Product. It creates eclipse and repository folders, and the executable in the eclipse folder is named per my project, headlessSTEM.exe.
2) I copied the workspace folder from my official STEM release to the eclipse folder of my headless version. (This is probably wrong, as there is probably more to importing pre-existing projects, but is what I tried so far.)
3) The code for my application is based off of the example noted above. For now I have a loop reading strings from the command line arguments expected to be scenario names. I just have the project name fixed, then I construct the URI with the scenario name.
The code does not seem to be able to locate the project/scenario. The scenario name passed was "DougScenario.scenario". This is in the "scenarios" folder in the "US-Flu" folder in workspace. The error is:
Quote:
> !ENTRY org.eclipse.stem.core 4 0 2010-04-19 09:28:10.347
> !MESSAGE The serialized instance of an Identifiable at "platform:/resource/US-Flu/scenarios/DougScenario.scenario" was not found or was of the wrong format
> !STACK 0
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/US-Flu/scenarios/DougScenario.scenario' does not exist.
Relevant code trying to run the scenario:
String projectName = "US-Flu";
//String scenarioName = "DougScenario.scenario";
for (String scenarioName: args) {
// Get the internal URI to the Scenario resource file in the workspace
URI scenarioUri = URI.createURI("platform:/resource/"+ projectName +"/scenarios/"+ scenarioName);
System.out.println("Working Directory = " + System.getProperty("user.dir"));
System.out.println("Scenario URI = "+scenarioUri.toString()+" ==> "+scenarioUri.path()+" ==> "+scenarioUri.toFileString());
// Load the scenario from file
Scenario scenario = (Scenario)Utility.getIdentifiable(scenarioUri);
// Get the simulation manager
SimulationManager mgr = SimulationManager.getManager();
// Create/run simulation from the given scenario
mgr.createAndRunSimulation(scenario);
}
I'll play with it more this week, but welcome any comments (especially if there is something obviously wrong ;)
|
|
|
Re: Web interface? [message #563360 is a reply to message #528167] |
Wed, 21 April 2010 19:01 |
Matthew Davis Messages: 269 Registered: July 2009 |
Senior Member |
|
|
Hi Doug,
First question is whether the US-Flu project and DougScenario scenario are visible in your official STEM instance's Project Explorer. You're right that you cannot just copy a folder into an Eclipse workspace and it show up, it must be done in a way that the workbench metadata is updated (either using the "Import" mechanism or by refreshing the workspace). If so, then you should be able to copy and paste the workspace as-is.
If so, make sure your headless STEM instance is loading the correct workspace path. Normally it's ./workspace relative to the executable, but not always. You can override this by passing the -data parameter to headlessSTEM.exe with a path to your workspace. You might try specifying an absolute path just to make sure it's loading the correct workspace.
|
|
|
Goto Forum:
Current Time: Wed Dec 11 13:08:55 GMT 2024
Powered by FUDForum. Page generated in 0.05936 seconds
|