| 1 | # |
|---|
| 2 | # This is a script example, which shows how to install and run an application on a set |
|---|
| 3 | # of nodes |
|---|
| 4 | # |
|---|
| 5 | # The scenario of this experiment involves one set of nodes: 'worker'. We will install |
|---|
| 6 | # the application "do_some_work.sh" in the directory "/usr/bin/" of all the nodes within |
|---|
| 7 | # that set. We will then execute this application on all the nodes. |
|---|
| 8 | # |
|---|
| 9 | # The application to install must be contained into a TAR archive on the local |
|---|
| 10 | # machine/console where this experiment script is being executed. |
|---|
| 11 | # |
|---|
| 12 | # It is the duty of this application to decide/implement what to do with its output (e.g. |
|---|
| 13 | # send then to STDOUT, or into a text file, or to the OML Collection framework as explained |
|---|
| 14 | # in other tutorials). |
|---|
| 15 | # |
|---|
| 16 | # In this example we: |
|---|
| 17 | # 1) Define a new Application, which will be a wrapper around the "do_some_work.sh" application |
|---|
| 18 | # 2) Define a set of nodes which contains 1 node: [1,1] that will run the application |
|---|
| 19 | # 3) Run the application |
|---|
| 20 | # |
|---|
| 21 | |
|---|
| 22 | # 1) |
|---|
| 23 | # Define a new application |
|---|
| 24 | # The following declaration defines a new application which as a URI 'myAppWrapper' |
|---|
| 25 | # and the name 'someWorkToDo' |
|---|
| 26 | # |
|---|
| 27 | # To use this Application definition in multiple experiment scripts, place it |
|---|
| 28 | # into a separate stand-alone file with the name 'myAppWrapper.rb' in the same |
|---|
| 29 | # directory as the experiment scripts that would use it. These experiment scripts |
|---|
| 30 | # will then NOT require this step 1) declaration. |
|---|
| 31 | # |
|---|
| 32 | defApplication('myAppWrapper', 'someWorkToDo') {|app| |
|---|
| 33 | app.shortDescription = "This is a simple wrapper application around my application" |
|---|
| 34 | |
|---|
| 35 | # We tell the experiment script where is the TAR archive which contains the application |
|---|
| 36 | # that we would like to install. |
|---|
| 37 | # The path that we give here is a local path to the TAR archive on the local machine/console |
|---|
| 38 | # on which we are running this experiment script. |
|---|
| 39 | # This TAR archive will be extracted at the ROOT "/" of the filesystem of each node. Therefore, |
|---|
| 40 | # you must layout the directory structure in your TAR archive in the exact way you would like |
|---|
| 41 | # its content to be placed within each node's filesystem. |
|---|
| 42 | # For example, here our TAR archive contains the following directory layout (using: 'tar -tf'): |
|---|
| 43 | # usr/ |
|---|
| 44 | # usr/bin/ |
|---|
| 45 | # usr/bin/do_some_work.sh |
|---|
| 46 | # |
|---|
| 47 | app.binaryRepository = "/home/myUsername/myArchive.tar" |
|---|
| 48 | |
|---|
| 49 | # Here we tell the node where it can find the installed application |
|---|
| 50 | app.path = "/usr/bin/do_some_work.sh" |
|---|
| 51 | |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | # 2) |
|---|
| 55 | # Define a set of node that would use the above application |
|---|
| 56 | # |
|---|
| 57 | defGroup('worker', [1,1]) {|node| |
|---|
| 58 | |
|---|
| 59 | # Add the 'myAppWrapper' application to the node(s) in this set |
|---|
| 60 | node.addApplication('myAppWrapper', 'someWorkToDo', nil, nil) |
|---|
| 61 | |
|---|
| 62 | # Note: the signature of addApplication() is |
|---|
| 63 | # |
|---|
| 64 | # addApplication(app, vName, bindings, env) |
|---|
| 65 | # |
|---|
| 66 | # 'app' - The application URI or instance |
|---|
| 67 | # 'vName' - Virtual name given to this app |
|---|
| 68 | # 'paramBindings' - Parameter bindings for this application |
|---|
| 69 | # 'env' - Environment to set before starting application |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | # 3) |
|---|
| 73 | # When all the nodes are UP, execute the application on them |
|---|
| 74 | # |
|---|
| 75 | whenAllUp() {|node| |
|---|
| 76 | |
|---|
| 77 | # Wait 10 sec to make sure that the applications are all |
|---|
| 78 | # installed |
|---|
| 79 | wait 5 |
|---|
| 80 | |
|---|
| 81 | # Start all the applications |
|---|
| 82 | allGroups.startApplications |
|---|
| 83 | |
|---|
| 84 | # Wait 10 sec that will be the application duration time |
|---|
| 85 | wait 10 |
|---|
| 86 | |
|---|
| 87 | # Stop the experiment |
|---|
| 88 | Experiment.done |
|---|
| 89 | } |
|---|