auser-poolparty 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/History.txt +22 -0
  2. data/License.txt +20 -0
  3. data/README.txt +52 -0
  4. data/Rakefile +4 -109
  5. data/bin/cloud +31 -0
  6. data/bin/cloud-add-keypair +23 -0
  7. data/bin/cloud-configure +35 -0
  8. data/bin/cloud-contract +27 -0
  9. data/bin/cloud-expand +27 -0
  10. data/bin/cloud-list +32 -0
  11. data/bin/cloud-maintain +36 -0
  12. data/bin/cloud-provision +30 -0
  13. data/bin/cloud-reconfigure +24 -0
  14. data/bin/cloud-ssh +18 -0
  15. data/bin/cloud-start +29 -0
  16. data/bin/pool +23 -75
  17. data/bin/pool-console +12 -0
  18. data/bin/pool-describe +9 -0
  19. data/bin/pool-list +28 -0
  20. data/bin/pool-provision +34 -0
  21. data/bin/pool-spec +17 -0
  22. data/bin/pool-start +32 -0
  23. data/examples/basic.rb +20 -0
  24. data/examples/plugin_without_plugin_directory.rb +13 -0
  25. data/examples/poolparty.rb +12 -0
  26. data/examples/with_apache_plugin.rb +22 -0
  27. data/generators/poolspec/USAGE +5 -0
  28. data/generators/poolspec/poolspec_generator.rb +65 -0
  29. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  30. data/lib/erlang/eb_server.erl +27 -0
  31. data/lib/poolparty.rb +40 -116
  32. data/lib/poolparty/base_packages/haproxy.rb +41 -0
  33. data/lib/poolparty/base_packages/heartbeat.rb +43 -0
  34. data/lib/poolparty/base_packages/poolparty.rb +18 -0
  35. data/lib/poolparty/base_packages/ruby.rb +27 -0
  36. data/lib/poolparty/core/array.rb +24 -0
  37. data/lib/{core → poolparty/core}/exception.rb +0 -0
  38. data/lib/{core → poolparty/core}/float.rb +0 -0
  39. data/lib/poolparty/core/hash.rb +29 -0
  40. data/lib/poolparty/core/kernel.rb +34 -0
  41. data/lib/{core → poolparty/core}/module.rb +18 -0
  42. data/lib/poolparty/core/my_open_struct.rb +18 -0
  43. data/lib/poolparty/core/object.rb +54 -0
  44. data/lib/poolparty/core/proc.rb +2 -0
  45. data/lib/poolparty/core/string.rb +72 -0
  46. data/lib/poolparty/core/symbol.rb +8 -0
  47. data/lib/{core → poolparty/core}/time.rb +15 -0
  48. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  49. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  50. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  51. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  52. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  53. data/lib/poolparty/helpers/binary.rb +30 -0
  54. data/lib/poolparty/helpers/console.rb +30 -0
  55. data/lib/poolparty/helpers/display.rb +25 -0
  56. data/lib/poolparty/helpers/optioner.rb +61 -0
  57. data/lib/poolparty/helpers/provisioner_base.rb +226 -0
  58. data/lib/poolparty/helpers/provisioners/master.rb +120 -0
  59. data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
  60. data/lib/poolparty/modules/cloud_resourcer.rb +72 -0
  61. data/lib/poolparty/modules/configurable.rb +34 -0
  62. data/lib/poolparty/modules/definable_resource.rb +59 -0
  63. data/lib/poolparty/modules/file_writer.rb +55 -0
  64. data/lib/poolparty/modules/method_missing_sugar.rb +17 -0
  65. data/lib/poolparty/modules/output.rb +13 -0
  66. data/lib/poolparty/modules/pretty_printer.rb +38 -0
  67. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
  68. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  69. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  70. data/lib/poolparty/net/remote.rb +35 -0
  71. data/lib/poolparty/net/remote_bases/ec2.rb +145 -0
  72. data/lib/poolparty/net/remote_instance.rb +68 -0
  73. data/lib/poolparty/net/remoter.rb +209 -0
  74. data/lib/poolparty/net/remoter_base.rb +117 -0
  75. data/lib/poolparty/plugins/gem_package.rb +39 -0
  76. data/lib/poolparty/plugins/line.rb +76 -0
  77. data/lib/poolparty/plugins/svn.rb +48 -0
  78. data/lib/poolparty/pool/base.rb +74 -0
  79. data/lib/poolparty/pool/cloud.rb +132 -0
  80. data/lib/poolparty/pool/custom_resource.rb +61 -0
  81. data/lib/poolparty/pool/loggable.rb +29 -0
  82. data/lib/poolparty/pool/plugin.rb +42 -0
  83. data/lib/poolparty/pool/plugin_model.rb +48 -0
  84. data/lib/poolparty/pool/pool.rb +55 -0
  85. data/lib/poolparty/pool/resource.rb +235 -0
  86. data/lib/poolparty/pool/resources/class_package.rb +60 -0
  87. data/lib/poolparty/pool/resources/cron.rb +14 -0
  88. data/lib/poolparty/pool/resources/directory.rb +23 -0
  89. data/lib/poolparty/pool/resources/exec.rb +26 -0
  90. data/lib/poolparty/pool/resources/file.rb +23 -0
  91. data/lib/poolparty/pool/resources/gem.rb +14 -0
  92. data/lib/poolparty/pool/resources/host.rb +14 -0
  93. data/lib/poolparty/pool/resources/package.rb +14 -0
  94. data/lib/poolparty/pool/resources/remote_file.rb +20 -0
  95. data/lib/poolparty/pool/resources/service.rb +21 -0
  96. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  97. data/lib/poolparty/pool/resources/variable.rb +27 -0
  98. data/lib/poolparty/pool/script.rb +21 -0
  99. data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
  100. data/lib/poolparty/templates/cib.xml +1 -0
  101. data/lib/poolparty/templates/fileserver.conf +4 -0
  102. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
  103. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  104. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  105. data/lib/poolparty/templates/puppet.conf +13 -0
  106. data/lib/poolparty/version.rb +9 -0
  107. data/lib/poolpartycl.rb +3 -0
  108. data/script/destroy +14 -0
  109. data/script/generate +14 -0
  110. data/script/txt2html +82 -0
  111. data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
  112. data/tasks/deployment.rake +34 -0
  113. data/tasks/development.rake +78 -0
  114. data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
  115. data/tasks/environment.rake +7 -0
  116. data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
  117. data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
  118. data/tasks/spec.rake +17 -0
  119. data/tasks/website.rake +17 -0
  120. metadata +154 -249
  121. data/CHANGELOG +0 -23
  122. data/LICENSE +0 -22
  123. data/README +0 -139
  124. data/assets/clouds.png +0 -0
  125. data/bin/instance +0 -68
  126. data/bin/poolnotify +0 -34
  127. data/config/cloud_master_takeover +0 -17
  128. data/config/create_proxy_ami.sh +0 -582
  129. data/config/installers/ubuntu_install.sh +0 -77
  130. data/config/monit.conf +0 -9
  131. data/config/monit/haproxy.monit.conf +0 -8
  132. data/config/monit/nginx.monit.conf +0 -0
  133. data/config/nginx.conf +0 -24
  134. data/config/reconfigure_instances_script.sh +0 -37
  135. data/config/sample-config.yml +0 -23
  136. data/config/scp_instances_script.sh +0 -12
  137. data/lib/core/array.rb +0 -16
  138. data/lib/core/hash.rb +0 -11
  139. data/lib/core/kernel.rb +0 -12
  140. data/lib/core/object.rb +0 -21
  141. data/lib/core/proc.rb +0 -15
  142. data/lib/helpers/plugin_spec_helper.rb +0 -58
  143. data/lib/modules/callback.rb +0 -133
  144. data/lib/modules/ec2_wrapper.rb +0 -108
  145. data/lib/modules/file_writer.rb +0 -38
  146. data/lib/modules/sprinkle_overrides.rb +0 -27
  147. data/lib/modules/vlad_override.rb +0 -83
  148. data/lib/poolparty/application.rb +0 -199
  149. data/lib/poolparty/init.rb +0 -6
  150. data/lib/poolparty/master.rb +0 -492
  151. data/lib/poolparty/monitors.rb +0 -11
  152. data/lib/poolparty/monitors/cpu.rb +0 -23
  153. data/lib/poolparty/monitors/memory.rb +0 -33
  154. data/lib/poolparty/monitors/web.rb +0 -29
  155. data/lib/poolparty/optioner.rb +0 -20
  156. data/lib/poolparty/plugin.rb +0 -78
  157. data/lib/poolparty/provider.rb +0 -104
  158. data/lib/poolparty/provider/essential.rb +0 -6
  159. data/lib/poolparty/provider/git.rb +0 -8
  160. data/lib/poolparty/provider/haproxy.rb +0 -9
  161. data/lib/poolparty/provider/heartbeat.rb +0 -6
  162. data/lib/poolparty/provider/rsync.rb +0 -8
  163. data/lib/poolparty/provider/ruby.rb +0 -65
  164. data/lib/poolparty/provider/s3fuse.rb +0 -22
  165. data/lib/poolparty/remote_instance.rb +0 -250
  166. data/lib/poolparty/remoter.rb +0 -171
  167. data/lib/poolparty/remoting.rb +0 -137
  168. data/lib/poolparty/scheduler.rb +0 -93
  169. data/lib/poolparty/tasks.rb +0 -47
  170. data/lib/poolparty/tasks/development.rake +0 -78
  171. data/lib/poolparty/tasks/plugins.rake +0 -30
  172. data/lib/poolparty/thread_pool.rb +0 -94
  173. data/lib/s3/s3_object_store_folders.rb +0 -44
  174. data/poolparty.gemspec +0 -71
  175. data/spec/files/describe_response +0 -37
  176. data/spec/files/multi_describe_response +0 -69
  177. data/spec/files/remote_desc_response +0 -37
  178. data/spec/helpers/ec2_mock.rb +0 -57
  179. data/spec/lib/core/core_spec.rb +0 -26
  180. data/spec/lib/core/kernel_spec.rb +0 -24
  181. data/spec/lib/core/string_spec.rb +0 -28
  182. data/spec/lib/modules/callback_spec.rb +0 -213
  183. data/spec/lib/modules/file_writer_spec.rb +0 -74
  184. data/spec/lib/poolparty/application_spec.rb +0 -135
  185. data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
  186. data/spec/lib/poolparty/master_spec.rb +0 -479
  187. data/spec/lib/poolparty/optioner_spec.rb +0 -34
  188. data/spec/lib/poolparty/plugin_spec.rb +0 -115
  189. data/spec/lib/poolparty/poolparty_spec.rb +0 -60
  190. data/spec/lib/poolparty/provider_spec.rb +0 -74
  191. data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
  192. data/spec/lib/poolparty/remoter_spec.rb +0 -72
  193. data/spec/lib/poolparty/remoting_spec.rb +0 -148
  194. data/spec/lib/poolparty/scheduler_spec.rb +0 -70
  195. data/spec/monitors/cpu_monitor_spec.rb +0 -39
  196. data/spec/monitors/memory_spec.rb +0 -51
  197. data/spec/monitors/misc_monitor_spec.rb +0 -51
  198. data/spec/monitors/web_spec.rb +0 -40
  199. data/spec/spec_helper.rb +0 -53
@@ -1,6 +0,0 @@
1
- =begin rdoc
2
- Load the files in order
3
- =end
4
- %w(optioner application thread_pool scheduler provider remoter remoting remote_instance master monitors tasks plugin).each do |f|
5
- require File.join(File.dirname(__FILE__), f)
6
- end
@@ -1,492 +0,0 @@
1
- =begin rdoc
2
- The basic master for PoolParty
3
- =end
4
- module PoolParty
5
- class Master < Remoting
6
- include Aska
7
- include Callbacks
8
- # ############################
9
- include Remoter
10
- # ############################
11
- include FileWriter
12
-
13
- def initialize
14
- super
15
-
16
- self.class.send :rules, :contract_when, Application.options.contract_when unless are_rules?(:contract_when)
17
- self.class.send :rules, :expand_when, Application.options.expand_when unless are_rules?(:expand_when)
18
- end
19
- # Start the cloud
20
- def start_cloud!
21
- start!
22
- end
23
- alias_method :start_cloud, :start_cloud!
24
- # Start the cloud, which launches the minimum_instances
25
- def start!
26
- message "Launching minimum_instances"
27
- launch_minimum_instances
28
- message "Waiting for master to boot up"
29
-
30
- wait_for_all_instances_to_boot
31
-
32
- setup_cloud
33
- end
34
- def setup_cloud
35
- install_cloud
36
- configure_cloud
37
- end
38
- alias_method :start, :start!
39
- def wait_for_all_instances_to_boot
40
- reset!
41
- while !number_of_pending_instances.zero?
42
- wait "2.seconds" unless Application.test?
43
- waited = true
44
- reset!
45
- end
46
- unless Application.test? || waited.nil?
47
- message "Give some time for the instance ssh to start up"
48
- wait "15.seconds"
49
- end
50
- end
51
- def wait_for_all_instances_to_terminate
52
- reset!
53
- while !list_of_terminating_instances.size.zero?
54
- wait "2.seconds" unless Application.test?
55
- waited = true
56
- reset!
57
- end
58
- unless Application.test? || waited.nil?
59
- message "Give some time for the instance ssh to start up"
60
- wait "15.seconds"
61
- end
62
- reset!
63
- end
64
- # Configure the master because the master will take care of the rest after that
65
- def configure_cloud
66
- message "Configuring master"
67
- build_and_send_config_files_in_temp_directory
68
- remote_configure_instances
69
-
70
- nodes.each do |node|
71
- node.configure
72
- end
73
- end
74
- before :install_cloud, :add_ssh_key
75
- after :configure_cloud, :remove_ssh_key
76
- def add_ssh_key(i)
77
- Kernel.system("ssh-add #{Application.keypair_path} >/dev/null 2>/dev/null")
78
- end
79
- def remove_ssh_key(i)
80
- Kernel.system("ssh-add -d #{Application.keypair_name} >/dev/null 2>/dev/null")
81
- end
82
- def install_cloud(bool=false)
83
- if Application.install_on_load? || bool
84
- # Just in case, add the new ubuntu apt-sources as well as updating and fixing the
85
- # update packages.
86
- update_apt_string =<<-EOE
87
- touch /etc/apt/sources.list
88
- echo 'deb http://mirrors.kernel.org/ubuntu hardy main universe' >> /etc/apt/sources.list
89
- apt-get update --fix-missing
90
- EOE
91
-
92
- ssh(update_apt_string)
93
-
94
- Provider.install_poolparty
95
-
96
- # For plugins
97
- nodes.each do |node|
98
- node.install
99
- end
100
-
101
- end
102
- end
103
- def cloud_ips
104
- @ips ||= nodes.collect {|a| a.ip }
105
- end
106
- # Launch the minimum number of instances.
107
- def launch_minimum_instances
108
- request_launch_new_instances(Application.minimum_instances - number_of_pending_and_running_instances)
109
- nodes
110
- end
111
- # Start monitoring the cloud with the threaded loop
112
- def start_monitor!
113
- begin
114
- trap("INT") do
115
- on_exit
116
- exit
117
- end
118
- # Daemonize only if we are not in the test environment
119
- run_thread_loop(:daemonize => !Application.test?) do
120
- add_task {PoolParty.message "Checking cloud"}
121
- add_task {launch_minimum_instances}
122
- add_task {reconfigure_cloud_when_necessary}
123
- add_task {scale_cloud!}
124
- add_task {check_stats}
125
- end
126
- rescue Exception => e
127
- Process.kill("HUP", Process.pid)
128
- end
129
- end
130
- alias_method :start_monitor, :start_monitor!
131
- def user_tasks
132
- end
133
- # Sole purpose to check the stats, mainly in a plugin
134
- def check_stats
135
- str = registered_monitors.collect {|m| "#{m}"}
136
- PoolParty.message "Monitors: #{str.join(", ")}"
137
- end
138
- # Add an instance if the cloud needs one ore terminate one if necessary
139
- def scale_cloud!
140
- add_instance_if_load_is_high
141
- terminate_instance_if_load_is_low
142
- end
143
- alias_method :scale_cloud, :scale_cloud!
144
- # Tough method:
145
- # We need to make sure that all the instances have the required software installed
146
- # This is a basic check against the local store of the instances that have the
147
- # stack installed.
148
- def reconfigure_cloud_when_necessary
149
- PoolParty.message "#{number_of_unconfigured_nodes} unconfigured nodes"
150
- configure_cloud if number_of_unconfigured_nodes > 0
151
- end
152
- def number_of_unconfigured_nodes
153
- # TODO: Find a better way to tell if the nodes are configured.
154
- nodes.reject {|a| a.stack_installed? }.size
155
- end
156
- def grow_by(num=1)
157
- request_launch_new_instances(num)
158
-
159
- wait_for_all_instances_to_boot
160
-
161
- reset!
162
- configure_cloud
163
- end
164
- def shrink_by(num=1)
165
- num.times do |i|
166
- # Get the last node that is not the master
167
- node = nodes.reject {|a| a.master? }[-1]
168
- res = request_termination_of_instance(node.instance_id) if node
169
- PoolParty.message "#{res ? "Could" : "Could not"} shutdown instance"
170
- end
171
- wait_for_all_instances_to_terminate
172
- configure_cloud
173
- end
174
- def make_base_tmp_dir(c)
175
- `mkdir #{base_tmp_dir}` unless File.directory?(base_tmp_dir)
176
- end
177
- before :build_and_send_config_files_in_temp_directory, :make_base_tmp_dir
178
- def build_and_send_config_files_in_temp_directory
179
- require 'ftools'
180
- if File.directory?(Application.plugin_dir)
181
- Kernel.system("tar -czf #{base_tmp_dir}/plugins.tar.gz #{File.basename(Application.plugin_dir)}")
182
- end
183
-
184
- if Master.requires_heartbeat?
185
- build_and_copy_heartbeat_authkeys_file
186
- File.copy(get_config_file_for("cloud_master_takeover"), "#{base_tmp_dir}/cloud_master_takeover")
187
- File.copy(get_config_file_for("heartbeat.conf"), "#{base_tmp_dir}/ha.cf")
188
- end
189
-
190
- File.copy(Application.config_file, "#{base_tmp_dir}/config.yml") if Application.config_file && File.exists?(Application.config_file)
191
- File.copy(Application.keypair_path, "#{base_tmp_dir}/keypair") if File.exists?(Application.keypair_path)
192
-
193
- copy_pem_files_to_tmp_dir
194
-
195
- copy_config_files_in_directory_to_tmp_dir("config/resource.d")
196
- # copy_config_files_in_directory_to_tmp_dir("config/monit.d")
197
-
198
- build_haproxy_file
199
- Master.build_user_global_files
200
-
201
- build_nodes_list
202
-
203
- Master.with_nodes do |node|
204
- build_hosts_file_for(node)
205
- build_reconfigure_instances_script_for(node)
206
- Master.build_user_node_files_for(node)
207
-
208
- if Master.requires_heartbeat?
209
- build_heartbeat_config_file_for(node)
210
- build_heartbeat_resources_file_for(node)
211
- end
212
- end
213
- end
214
- def copy_pem_files_to_tmp_dir
215
- %w(EC2_CERT EC2_PRIVATE_KEY).each do |key|
216
- begin
217
- file = `echo $#{key}`.strip
218
- File.copy(file, "#{base_tmp_dir}/#{File.basename(file)}")
219
- rescue Exception => e
220
- end
221
- end
222
- end
223
- def cleanup_tmp_directory(c)
224
- Dir["#{base_tmp_dir}/*"].each {|f| FileUtils.rm_rf f} if File.directory?("tmp/")
225
- end
226
- before :build_and_send_config_files_in_temp_directory, :cleanup_tmp_directory
227
- # Send the files to the nodes
228
- def send_config_files_to_nodes(c)
229
- run_array_of_tasks(rsync_tasks("#{base_tmp_dir}/*", "#{remote_base_tmp_dir}"))
230
- end
231
- after :build_and_send_config_files_in_temp_directory, :send_config_files_to_nodes
232
- def remote_configure_instances
233
- arr = []
234
- Master.with_nodes do |node|
235
- script_file = "#{remote_base_tmp_dir}/#{node.name}-configuration"
236
- str=<<-EOC
237
- chmod +x #{script_file}
238
- /bin/sh #{script_file}
239
- EOC
240
- arr << "#{self.class.ssh_string} #{node.ip} '#{str.strip.runnable}'"
241
- end
242
- run_array_of_tasks(arr)
243
- end
244
- # Add an instance if the load is high
245
- def add_instance_if_load_is_high
246
- if expand?
247
- PoolParty.message "Cloud needs expansion"
248
- grow_by(1)
249
- end
250
- end
251
- alias_method :add_instance, :add_instance_if_load_is_high
252
- # Teardown an instance if the load is pretty low
253
- def terminate_instance_if_load_is_low
254
- if contract?
255
- PoolParty.message "Cloud to shrink"
256
- shrink_by(1)
257
- end
258
- end
259
- alias_method :terminate_instance, :terminate_instance_if_load_is_low
260
- # FOR MONITORING
261
- def contract?
262
- valid_rules?(:contract_when)
263
- end
264
- def expand?
265
- valid_rules?(:expand_when)
266
- end
267
- # Restart the running instances services with monit on all the nodes
268
- def restart_running_instances_services
269
- nodes.each do |node|
270
- node.restart_with_monit
271
- end
272
- end
273
- # Build the basic haproxy config file from the config file in the config directory and return a tempfile
274
- def build_haproxy_file
275
- write_to_file_for("haproxy") do
276
- servers=<<-EOS
277
- #{nodes.collect {|node| node.haproxy_entry}.join("\n")}
278
- EOS
279
- open(Application.haproxy_config_file).read.strip ^ {:servers => servers, :host_port => Application.host_port}
280
- end
281
- end
282
- # Build host file for a specific node
283
- def build_hosts_file_for(n)
284
- write_to_file_for("hosts", n) do
285
- "#{nodes.collect {|node| node.ip == n.ip ? node.local_hosts_entry : node.hosts_entry}.join("\n")}"
286
- end
287
- end
288
- def build_nodes_list
289
- write_to_file_for(RemoteInstance.node_list_name) do
290
- "#{cloud_ips.join("\n")}"
291
- end
292
- end
293
- # Build the basic auth file for the heartbeat
294
- def build_and_copy_heartbeat_authkeys_file
295
- write_to_file_for("authkeys") do
296
- open(Application.heartbeat_authkeys_config_file).read
297
- end
298
- end
299
- # Build heartbeat config file
300
- def build_heartbeat_config_file_for(node)
301
- write_to_file_for("heartbeat", node) do
302
- servers = "#{node.node_entry}\n#{get_next_node(node).node_entry}" rescue ""
303
- open(Application.heartbeat_config_file).read.strip ^ {:nodes => servers}
304
- end
305
- end
306
- def build_heartbeat_resources_file_for(node)
307
- write_to_file_for("haresources", node) do
308
- "#{node.haproxy_resources_entry}\n#{get_next_node(node).haproxy_resources_entry}" rescue ""
309
- end
310
- end
311
- # Build basic configuration script for the node
312
- def build_reconfigure_instances_script_for(node)
313
- write_to_file_for("configuration", node) do
314
- open(Application.sh_reconfigure_instances_script).read.strip ^ node.configure_tasks( !PoolParty.verbose? )
315
- end
316
- end
317
-
318
- # Try the user's directory before the master directory
319
- def get_config_file_for(name)
320
- if File.exists?("#{user_dir}/config/#{name}")
321
- "#{user_dir}/config/#{name}"
322
- else
323
- "#{root_dir}/config/#{name}"
324
- end
325
- end
326
- # Copy all the files in the directory to the dest
327
- def copy_config_files_in_directory_to_tmp_dir(dir)
328
- dest_dir = "#{base_tmp_dir}/#{File.basename(dir)}"
329
- FileUtils.mkdir_p dest_dir
330
-
331
- if File.directory?("#{user_dir}/#{dir}")
332
- Dir["#{user_dir}/#{dir}/*"].each do |file|
333
- File.copy(file, dest_dir)
334
- end
335
- else
336
- Dir["#{root_dir}/#{dir}/*"].each do |file|
337
- File.copy(file, dest_dir)
338
- end
339
- end
340
- end
341
- # Return a list of the nodes and cache them
342
- def nodes
343
- @nodes ||= list_of_nonterminated_instances.collect_with_index do |inst, i|
344
- RemoteInstance.new(inst.merge({:number => i}))
345
- end
346
- end
347
- # Return a list of the nodes for each keypair and cache them
348
- def cloud_nodes
349
- @cloud_nodes ||= begin
350
- nodes_list = []
351
- cloud_keypairs.each {|keypair|
352
- list_of_nonterminated_instances(list_of_instances(keypair)).collect_with_index { |inst, i|
353
- nodes_list << RemoteInstance.new(inst.merge({:number => i}))
354
- }
355
- }
356
- nodes_list
357
- end
358
- end
359
- # Get the node at the specific index from the cached nodes
360
- def get_node(i=0)
361
- nodes.select {|a| a.number == i.to_i}.first
362
- end
363
- # Get the next node in sequence, so we can configure heartbeat to monitor the next node
364
- def get_next_node(node)
365
- i = node.number + 1
366
- i = 0 if i >= nodes.size
367
- get_node(i)
368
- end
369
- # On exit command
370
- def on_exit
371
- end
372
- # List the clouds
373
- def list
374
- if number_of_pending_and_running_instances > 0
375
- out = "-- CLOUD (#{number_of_pending_and_running_instances})--\n"
376
- out << nodes.collect {|node| node.description }.join("\n")
377
- else
378
- out = "Cloud is not running"
379
- end
380
- out
381
- end
382
- def clouds_list
383
- if number_of_all_pending_and_running_instances > 0
384
- out = "-- ALL CLOUDS (#{number_of_all_pending_and_running_instances})--\n"
385
- keypair = nil
386
- out << cloud_nodes.collect {|node|
387
- str = ""
388
- if keypair != node.keypair
389
- keypair = node.keypair;
390
- str = "key pair: #{keypair} (#{number_of_pending_and_running_instances(keypair)})\n"
391
- end
392
- str += "\t"+node.description if !node.description.nil?
393
- }.join("\n")
394
- else
395
- out = "Clouds are not running"
396
- end
397
- out
398
- end
399
- # Reset and clear the caches
400
- def reset!
401
- @cached_descriptions = nil
402
- @nodes = nil
403
- @cloud_nodes = nil
404
- end
405
-
406
- class << self
407
- include PoolParty
408
- include FileWriter
409
-
410
- def with_nodes(&block)
411
- new.nodes.each &block
412
- end
413
-
414
- def collect_nodes(&block)
415
- new.nodes.collect &block
416
- end
417
-
418
- def requires_heartbeat?
419
- new.nodes.size > 1
420
- end
421
- def is_master_responding?
422
- `ping -c1 -t5 #{get_master.ip}`
423
- end
424
- def get_master
425
- new.nodes[0]
426
- end
427
- def cloud_ips
428
- new.cloud_ips
429
- end
430
- def get_next_node(node)
431
- new.get_next_node(node)
432
- end
433
- def set_hosts(c, remotetask=nil)
434
- unless remotetask.nil?
435
- rt = remotetask
436
- end
437
-
438
- ssh_location = `which ssh`.gsub(/\n/, '')
439
- rsync_location = `which rsync`.gsub(/\n/, '')
440
- rt.set :user, Application.username
441
- # rt.set :domain, "#{Application.user}@#{ip}"
442
- rt.set :application, Application.app_name
443
- rt.set :ssh_flags, "-i #{Application.keypair_path} -o StrictHostKeyChecking=no"
444
- rt.set :rsync_flags , ['-azP', '--delete', "-e '#{ssh_location} -l #{Application.username} -i #{Application.keypair_path} -o StrictHostKeyChecking=no'"]
445
-
446
- master = get_master
447
- rt.set :domain, "#{master.ip}" if master
448
- Master.with_nodes { |node|
449
- rt.host "#{Application.username}@#{node.ip}",:app if node.status =~ /running/
450
- }
451
- end
452
-
453
- def ssh_configure_string_for(node)
454
- cmd=<<-EOC
455
- #{node.update_plugin_string(node)}
456
- pool maintain -c ~/.config -l #{PoolParty.plugin_dir}
457
- hostname -v #{node.name}
458
- /usr/bin/s3fs #{Application.shared_bucket} -o accessKeyId=#{Application.access_key} -o secretAccessKey=#{Application.secret_access_key} -o nonempty /data
459
- EOC
460
- end
461
- def build_haproxy_file
462
- servers=<<-EOS
463
- #{collect_nodes {|node| node.haproxy_entry}.join("\n")}
464
- EOS
465
- open(Application.haproxy_config_file).read.strip ^ {:servers => servers, :host_port => Application.host_port}
466
- end
467
-
468
- # Placeholders
469
- def build_user_global_files
470
- global_user_files.each do |arr|
471
- write_to_file_for(arr[0]) &arr[1]
472
- end
473
- end
474
- def build_user_node_files_for(node)
475
- user_node_files.each do |arr|
476
- write_to_file_for(arr[0], node) do
477
- arr[1].call(node)
478
- end
479
- end
480
- end
481
- def define_global_user_file(name, &block)
482
- global_user_files << [name, block]
483
- end
484
- def global_user_files;@global_user_files ||= [];end
485
- def define_node_user_file(name, &block)
486
- user_node_files << [name, block]
487
- end
488
- def user_node_files;@user_node_files ||= [];end
489
- end
490
-
491
- end
492
- end