PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/omf/simple.rb

https://bitbucket.org/romoore/gnrs
Ruby | 182 lines | 131 code | 28 blank | 23 comment | 32 complexity | 6faf3d1b1575fc7dcabba4310f7580ca MD5 | raw file
  1. #!/bin/ruby
  2. #
  3. # Simple GNRS experiment that performs the tasks outlined in the project Wiki.
  4. # See <https://bitbucket.org/romoore/gnrs/wiki/Running%20an%20Experiment%20on%20Orbit>
  5. # for more details.
  6. #
  7. # Author: Robert Moore
  8. # Last Modified: Jan 4, 2013
  9. #
  10. # Runtime configuration of propertes can be effected like this:
  11. # omf exec simple.rb -- --prop1 value1 --prop2 value2
  12. # Import the experiment utilities
  13. eval(File.new('./utils.rb').read)
  14. # Main function, used so we can "return" from the experiment early when
  15. # errors are detected.
  16. def doMainExperiment(serversMap, clientsMap)
  17. info "## Configuring node network interfaces ##"
  18. success = prepareNodes(serversMap, clientsMap)
  19. if success == 0
  20. info "\tNetwork configuration complete."
  21. else
  22. error "\tUnable to configure networking. Exiting."
  23. return;
  24. end
  25. info "Servers:"
  26. serversMap.each_value { |node|
  27. info "\t#{node}"
  28. }
  29. info "Clients:"
  30. clientsMap.each_value { |node|
  31. info "\t#{node}"
  32. }
  33. if (property.disableDelay.to_s == "")
  34. info "## Preparing the delay modules ##"
  35. success = prepareDelayModule(serversMap, clientsMap, property.dataUrl, property.clickModule)
  36. if success == 0
  37. info "\tSuccessfully installed and configured delay module on all nodes."
  38. else
  39. error "\tUnable to configure delay module on one or more nodes. Exiting."
  40. return;
  41. end
  42. end
  43. info "## Installing configuration files ##"
  44. success = installConfigs(serversMap, clientsMap)
  45. if success == 0
  46. info "\tSuccessfully installed configuration files."
  47. else
  48. error "\tUnable to install configuration files."
  49. return;
  50. end
  51. wait property.microWait
  52. info "## Compressing configuration files ##"
  53. success = buildTarballs()
  54. if success == 0
  55. info "\tSuccessfully compressed configuration files."
  56. else
  57. error "\tUnable to compress configuration files."
  58. return;
  59. end
  60. wait property.microWait
  61. # WGET everything onto the nodes
  62. info "## Downloading to the nodes ##"
  63. success = getHostTarballs(serversMap,clientsMap)
  64. if success == 0
  65. info "\tSuccessfully downloaded configuration files."
  66. else
  67. error "\tUnable to download configuration files."
  68. return
  69. end
  70. wait property.miniWait
  71. # Install delay modules
  72. if (property.disableDelay.to_s == "")
  73. info "## Install the delay modules ##"
  74. success = installDelayModule(serversMap, clientsMap, property.dataUrl, property.clickModule)
  75. if success == 0
  76. info "\tSuccessfully installed and configured delay module on all nodes."
  77. else
  78. error "\tUnable to configure delay module on one or more nodes. Exiting."
  79. return;
  80. end
  81. end
  82. wait property.miniWait
  83. # Now update the permissions on the nodes
  84. info "Installing init scripts"
  85. installInit(serversMap)
  86. wait property.miniWait
  87. info "## Launching servers ##"
  88. success = launchServers(serversMap)
  89. if success == 0
  90. info "\tSuccessfully launched servers."
  91. else
  92. error "\tUnable to launch servers."
  93. return;
  94. end
  95. info "## Waiting 5 seconds for servers to start ##"
  96. wait property.miniWait
  97. info "## Loading GUIDs ##"
  98. success = loadGUIDs(clientsMap)
  99. if success == 0
  100. info "\tSuccessfully launched clients."
  101. else
  102. error "\tUnable to launch clients."
  103. GNRSUtils.stopServers(serversMap)
  104. return;
  105. end
  106. info "Waiting #{property.clientWait} for trace to execute."
  107. wait property.clientWait
  108. info "## Shutting down servers ##"
  109. success = stopServers(serversMap)
  110. if success == 0
  111. info "\tTerminated servers successfully."
  112. else
  113. error "\tUnable to terminate servers."
  114. return
  115. end
  116. info "Collecting statistsics from nodes."
  117. # clients
  118. success = collectClientStats(clientsMap, '')
  119. if success != 0
  120. error "\tUnable to collect client statistics."
  121. return
  122. end
  123. # servers
  124. success = collectServerStats(serversMap,'')
  125. if success != 0
  126. error "\tUnable to collect server statistics."
  127. return
  128. end
  129. # remove experimental files
  130. info "Removing experiment-related files from nodes."
  131. success = 0
  132. success = removeExperimentFiles(serversMap)
  133. success |= removeExperimentFiles(clientsMap)
  134. if success != 0
  135. error "\tUnable to remove files from one or more nodes. You should reimage the testbed."
  136. return
  137. end
  138. end # main
  139. # Load resources, get topology, define groups
  140. success, serversMap, clientsMap = doInitSetup
  141. # Only register callback if we were able to prepare the experiment.
  142. if success == 0
  143. info "Awaiting node readiness"
  144. # Called when all nodes are available for use.
  145. onEvent(:ALL_UP) do |event|
  146. if success
  147. info "GNRS: All nodes are up."
  148. doMainExperiment(serversMap, clientsMap)
  149. end
  150. Experiment.done
  151. end # onEvent
  152. else
  153. Experiment.done
  154. end