Tutorial: Script for the Tut_app_2.rb experiment¶
Given below is the code for the tut_app_1.rb script:
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.appPackage = "/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')
61
62 # Note: the signature of addApplication() is
63 #
64 # addApplication(app)
65 #
66 # 'app' - The application URI or instance
67 }
68
69 # 3)
70 # When all the nodes are UP, execute the application on them
71 #
72 whenAllUp() {|node|
73
74 # Wait 10 sec to make sure that the applications are all
75 # installed
76 wait 5
77
78 # Start all the applications
79 allGroups.startApplications
80
81 # Wait 10 sec that will be the application duration time
82 wait 10
83
84 # Stop the experiment
85 Experiment.done
86 }