Back to DevDoc

Work with the OpenMole console

The scope of this page is to document the use of the UI console provided by OpenMole to build interactive shell Mole.

Get the OpenMOLE console

You can either download the last built packaged version here or built it from the sources.

Launching

Run the launching depending on your platform:

  • Windows platform: run.bat
  • Bourne compatible shell (GNU/Linux and Mac OS X): run.sh

If all is OK, you'll have a nice interactive console. If not, please fill a bug report!

Console Usage

The console interprets Groovy language statements. The Groovy language is derivated from Java with additional features. The PLEAC documentation is a good ressource for working with Groovy.

Master password

When you start the console for the first time, a password will be asked to you for storing all data that need to be encrypted. Then, this password will be asked each time you restart the console. You can reset your password by deleting the file ~/.openmole/.preferences.

Environment

Variables available:

  • plugin (javadoc): provides a tool for loading dynamically plugins into the platform. The console is provided with a set of plugins that you can load with the command:
    plugin.loadDir('openmole-plugins')
    
  • builder (javadoc)

TODO: list variables available

Commands

  • To know all the console command you have to type

help or \h

The result of this command is displayed :

For information about Groovy, visit:
    http://groovy.codehaus.org 

Available commands:
  help      (\h ) Display this help message
  ?         (\? ) Alias to: help
  exit      (\x ) Exit the shell
  quit      (\q ) Alias to: exit
  import    (\i ) Import a class into the namespace
  display   (\d ) Display the current buffer
  clear     (\c ) Clear the buffer
  show      (\S ) Show variables, classes or imports
  inspect   (\n ) Inspect a variable or the last result with the GUI object browser
  purge     (\p ) Purge variables, classes, imports or preferences
  edit      (\e ) Edit the current buffer
  load      (\l ) Load a file or URL into the buffer
  .         (\. ) Alias to: load
  save      (\s ) Save the current buffer to a file
  record    (\r ) Record the current session to a file
  history   (\H ) Display, manage and recall edit-line history
  alias     (\a ) Create an alias
  set       (\= ) Set (or list) preferences
  register  (\rc) Registers a new command with the shell

For help on a specific command type:
    help command 

This console is based on the groovy shell

Samples

Here are some example scripts than can be launched with the load command. Copy the content of an example in a file and run in the console the command:

load path/to/your/script.groovy

Hello World

A minimalistic example:

import org.openmole.plugin.task.groovy.*
import org.openmole.core.implementation.mole.*
import org.openmole.core.implementation.capsule.*

helloTask = new GroovyTask("Sample groovy task")
helloTask.setCode("println 'Hello world!'")


new MoleExecution(new Mole(new TaskCapsule(helloTask))).start()

Hello World with a variable

Here, we introduce a variable that is passed from a first task to the second:

import org.openmole.plugin.task.groovy.GroovyTask

// Declare the variable
textVariable = builder.buildPrototype("text", String.class)

// First task produces the variable
assignTask = new GroovyTask("Assign task")
assignTask.setCode("text = 'Hello world!'")
assignTask.addOutput(textVariable)

// Second task consumes the variable
helloTask = new GroovyTask("Sample groovy task")
helloTask.setCode("println text")
helloTask.addInput(textVariable)

// Build the transition and run
builder.buildMoleExecution(assignTask, helloTask).start()

File handling with variable

This samble demonstrates how files are managed in transitions between tasks. A file is written by a task, and read by a second one. What is magic, is if you switch the execution of one of the tasks on a remote computer, the file will automatically transfered from the first task to the second one.

import org.openmole.plugin.task.groovy.GroovyTask

helloFile = builder.buildPrototype("helloFile", File.class)
generateTask = new GroovyTask("Generate file")
generateTask.setCode("helloFile = workspace.newTmpFile();\nhelloFile.write('Hello from groovy');\n")
generateTask.addOutput(helloFile)

displayTask = new GroovyTask("Display file")
displayTask.setCode("println helloFile.text")
displayTask.addInput(helloFile)

builder.buildMoleExecution(generateTask,displayTask).start()

Hello World exploration with a complete plan

Here, we introduce a variable that is passed from a first task to the second:

import org.openmole.core.implementation.data.*
import org.openmole.core.implementation.transition.*
import org.openmole.core.implementation.mole.*
import org.openmole.core.implementation.task.*
import org.openmole.core.implementation.capsule.*
import org.openmole.core.implementation.plan.*
import org.openmole.plugin.plan.complete.*
import org.openmole.plugin.task.groovy.*
import org.openmole.plugin.domain.interval.*
import static org.openmole.core.model.data.DataModeMask.*

// Declare the variable
i = new Prototype("i", Integer)

// Define the exploration task
plan = new CompletePlan(new Factor(i, new RangeInteger("0", "10")))

explorationTask = new ExplorationTask("exploration", plan)

// Second task consumes the variable
helloTask = new GroovyTask("Sample groovy task")
helloTask.setCode("println 'hello number ' + i")
helloTask.addInput(i)

explorationTaskCaps = new ExplorationTaskCapsule(explorationTask)
helloTaskCaps = new TaskCapsule(helloTask)

new ExplorationTransition(explorationTaskCaps, helloTaskCaps)

// Build the transition and run
new MoleExecution(new Mole(explorationTaskCaps)).start()

or by using the builder:

import org.openmole.plugin.domain.interval.RangeInteger
import org.openmole.plugin.plan.complete.CompletePlan
import org.openmole.plugin.task.groovy.GroovyTask

i = builder.buildPrototype("i", Integer.class)

// Define the exploration task
plan = new CompletePlan(builder.exploration.buildFactor(i, new RangeInteger("0","10","1")))

explorationTask = builder.exploration.buildExplorationTask("exploration",plan)
                                      
// Second task consumes the variable
helloTask = new GroovyTask("Sample groovy task")
helloTask.setCode("println 'hello number ' + i")
helloTask.addInput(i)

// build the worflow
explorationCapsule = builder.exploration.buildExplorationTaskCapsule(explorationTask)
helloCapsule = builder.exploration.buildExplorationTransition(explorationCapsule, helloTask)
// run
builder.buildMoleExecution(explorationCapsule).start()

Data structures generation (Outdated)

This sample demonstrates how you can generate your own datastructure for managing complex objects through a workflow.

import org.openmole.core.implementation.data.*

import org.openmole.core.implementation.transition.*
import org.openmole.core.implementation.mole.*
import org.openmole.core.methods.task.*
import org.openmole.plugin.task.groovy.*

superNode = new ComplexNode("SuperNode");
superNode.add(new PrototypeNode(new Prototype("attribute", Integer.class)));

inStruct = new ComplexNode("In", superNode);
inStruct.add(new PrototypeNode(new Prototype("a", Integer.class)));
outStruct = new ComplexNode("Out");
outStruct.add(new PrototypeNode(new Prototype("b", Integer.class)));

inClass = structure.generateClass(inStruct);
outClass = structure.generateClass(outStruct);
structGenTask = new ModelStructuresGenerationTask("structGen", inClass, outClass);

assignTask = new GroovyTask("assign");
assignTask.setCode("input.attribute = 3;");
assignTask.addInput(ModelStructuresGenerationTask.InputData);
assignTask.addInput(ModelStructuresGenerationTask.OutputData);
assignTask.addOutput(ModelStructuresGenerationTask.InputData);

displayTask = new GroovyTask("display");
displayTask.setCode("println input.attribute;");
displayTask.addInput(ModelStructuresGenerationTask.InputData);

new MoleExecution(new Mole(TransitionFactory.buildChain(structGenTask, assignTask, displayTask).getFirstCapsule())).start()

Go on the grid

First you have to init the OpenMOLE configuration, run in the console

import org.openmole.plugin.environment.glite.*
init GliteEnvironment

A simple example that runs a first task on the grid and then a second one on your local computer:

import org.openmole.core.implementation.mole.*
import org.openmole.plugin.environment.glite.*
import org.openmole.plugin.task.groovy.GroovyTask
import org.openmole.core.implementation.transition.*

// Declare the variable   
textVariable = builder.buildPrototype("text", String.class)

// First task produces the variable
assignTask = new GroovyTask("Assign task") 
assignTask.setCode("text = 'Hello world!'")
assignTask.addOutput(textVariable)

// Second task consumes the variable
helloTask = new GroovyTask("Sample groovy task")
helloTask.setCode("println text")
helloTask.addInput(textVariable) 

// Build and Run
assignCaps = builder.buildTaskCapsule(assignTask)
new Transition(assignCaps, builder.buildTaskCapsule(helloTask))

// Grid env
env = new GliteEnvironment("vo.iscpif.fr", "voms://grid12.lal.in2p3.fr:20013/O=GRID-FR/C=FR/O=CNRS/OU=LAL/CN=grid12.lal.in2p3.fr", "ldap://topbdii.grif.fr:2170")
strat = builder.buildFixedEnvironmentSelection() 
strat.setEnvironment(assignCaps,env)

// Run
ex = new MoleExecution(builder.buildMole(assignCaps),strat)
ex.start()

Then, you can use the ex (javadoc) variable for monitoring the execution:

> print ex
Ready: 1711
Running: 1
Achieved: 0
Completed: 0
Failed: 0
Transition Performed: 0
Canceled: 0

Creating a scripted Mole example

The example is describe there

logo cemagref

logo iscpif

logo lifegrid

logo region auvergne

logo patres project