cloudbox-server 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. data/.yardopts +3 -0
  2. data/README.md +17 -0
  3. data/bin/cb-cluster-allocate +5 -0
  4. data/bin/cb-cluster-create +5 -0
  5. data/bin/cb-cluster-delete +5 -0
  6. data/bin/cb-cluster-desallocate +5 -0
  7. data/bin/cb-cluster-info +5 -0
  8. data/bin/cb-cluster-ls +5 -0
  9. data/bin/cb-node-destroy +5 -0
  10. data/bin/cb-node-detach +6 -0
  11. data/bin/cb-node-info +5 -0
  12. data/bin/cb-node-install +5 -0
  13. data/bin/cb-node-ls +5 -0
  14. data/bin/cb-service-add +5 -0
  15. data/bin/cb-service-component-add +5 -0
  16. data/bin/cb-service-component-delete +5 -0
  17. data/bin/cb-service-component-detach +5 -0
  18. data/bin/cb-service-conf-apply +5 -0
  19. data/bin/cb-service-conf-create +5 -0
  20. data/bin/cb-service-conf-get +5 -0
  21. data/bin/cb-service-conf-ls +5 -0
  22. data/bin/cb-service-follow-request +5 -0
  23. data/bin/cb-service-info +5 -0
  24. data/bin/cb-service-install +5 -0
  25. data/bin/cb-service-ls +5 -0
  26. data/bin/cb-service-start +5 -0
  27. data/bin/cb-service-stop +5 -0
  28. data/lib/command.rb +61 -0
  29. data/lib/command/ambari_add_host.rb +19 -0
  30. data/lib/command/ambari_cluster_command.rb +26 -0
  31. data/lib/command/ambari_cluster_component_command.rb +26 -0
  32. data/lib/command/ambari_cluster_component_host_command.rb +26 -0
  33. data/lib/command/ambari_cluster_create.rb +19 -0
  34. data/lib/command/ambari_cluster_host_command.rb +27 -0
  35. data/lib/command/ambari_cluster_list.rb +20 -0
  36. data/lib/command/ambari_cluster_service_command.rb +26 -0
  37. data/lib/command/ambari_cluster_service_host_command.rb +26 -0
  38. data/lib/command/ambari_command.rb +21 -0
  39. data/lib/command/ambari_create_cluster_configuration.rb +39 -0
  40. data/lib/command/ambari_get_cluster_configuration.rb +29 -0
  41. data/lib/command/ambari_host_list.rb +19 -0
  42. data/lib/command/ambari_install_cluster.rb +19 -0
  43. data/lib/command/ambari_install_component.rb +19 -0
  44. data/lib/command/ambari_install_host.rb +19 -0
  45. data/lib/command/ambari_install_host_component.rb +19 -0
  46. data/lib/command/ambari_install_host_components.rb +19 -0
  47. data/lib/command/ambari_install_service_components.rb +19 -0
  48. data/lib/command/ambari_service_add.rb +27 -0
  49. data/lib/command/ambari_service_component_add.rb +21 -0
  50. data/lib/command/ambari_service_component_delete.rb +21 -0
  51. data/lib/command/ambari_service_component_detach.rb +21 -0
  52. data/lib/command/ambari_service_component_info.rb +29 -0
  53. data/lib/command/ambari_service_conf_apply.rb +31 -0
  54. data/lib/command/ambari_service_conf_ls.rb +30 -0
  55. data/lib/command/ambari_service_delete.rb +21 -0
  56. data/lib/command/ambari_service_info.rb +20 -0
  57. data/lib/command/ambari_service_list.rb +21 -0
  58. data/lib/command/ambari_start_cluster.rb +19 -0
  59. data/lib/command/ambari_start_component.rb +19 -0
  60. data/lib/command/ambari_start_host.rb +19 -0
  61. data/lib/command/ambari_start_host_component.rb +19 -0
  62. data/lib/command/ambari_start_host_components.rb +19 -0
  63. data/lib/command/ambari_start_service_components.rb +19 -0
  64. data/lib/command/ambari_stop_cluster.rb +19 -0
  65. data/lib/command/ambari_stop_component.rb +19 -0
  66. data/lib/command/ambari_stop_host.rb +19 -0
  67. data/lib/command/ambari_stop_host_component.rb +19 -0
  68. data/lib/command/ambari_stop_host_components.rb +19 -0
  69. data/lib/command/ambari_stop_service_components.rb +19 -0
  70. data/lib/command/basic_command.rb +44 -0
  71. data/lib/command/cluster_create.rb +50 -0
  72. data/lib/command/cluster_delete.rb +30 -0
  73. data/lib/command/cluster_info.rb +30 -0
  74. data/lib/command/cluster_ls.rb +30 -0
  75. data/lib/command/crowbar_cluster_allocate.rb +42 -0
  76. data/lib/command/crowbar_command.rb +30 -0
  77. data/lib/command/crowbar_get_barclamps_list.rb +30 -0
  78. data/lib/command/crowbar_node_command.rb +21 -0
  79. data/lib/command/crowbar_node_list.rb +40 -0
  80. data/lib/command/crowbar_vcluster_command.rb +20 -0
  81. data/lib/command/filter.rb +15 -0
  82. data/lib/command/node_destroy.rb +58 -0
  83. data/lib/command/node_detach.rb +44 -0
  84. data/lib/command/node_info.rb +27 -0
  85. data/lib/command/node_install.rb +46 -0
  86. data/lib/command/node_reinstall.rb +44 -0
  87. data/lib/command/state_filter.rb +16 -0
  88. data/lib/common.rb +11 -0
  89. data/lib/common/cb-lib-node-erase-hard-disk.sh +29 -0
  90. data/lib/common/cloudbox_exceptions.rb +631 -0
  91. data/lib/common/cloudbox_logger.rb +81 -0
  92. data/lib/common/cloudbox_logger_mock.rb +43 -0
  93. data/lib/common/color.rb +267 -0
  94. data/lib/common/config_properties.rb +2027 -0
  95. data/lib/common/services_description.rb +192 -0
  96. data/lib/exec.rb +35 -0
  97. data/lib/exec/check_parameter.rb +208 -0
  98. data/lib/exec/cluster_allocate.rb +163 -0
  99. data/lib/exec/cluster_create.rb +99 -0
  100. data/lib/exec/cluster_delete.rb +38 -0
  101. data/lib/exec/cluster_desallocate.rb +37 -0
  102. data/lib/exec/cluster_info.rb +177 -0
  103. data/lib/exec/cluster_ls.rb +150 -0
  104. data/lib/exec/command_option.rb +222 -0
  105. data/lib/exec/executable_command.rb +194 -0
  106. data/lib/exec/node_destroy.rb +101 -0
  107. data/lib/exec/node_detach.rb +98 -0
  108. data/lib/exec/node_info.rb +280 -0
  109. data/lib/exec/node_install.rb +234 -0
  110. data/lib/exec/node_ls.rb +160 -0
  111. data/lib/exec/service_add.rb +224 -0
  112. data/lib/exec/service_component_add.rb +39 -0
  113. data/lib/exec/service_component_delete.rb +37 -0
  114. data/lib/exec/service_component_detach.rb +37 -0
  115. data/lib/exec/service_conf_apply.rb +57 -0
  116. data/lib/exec/service_conf_create.rb +80 -0
  117. data/lib/exec/service_conf_get.rb +165 -0
  118. data/lib/exec/service_conf_ls.rb +103 -0
  119. data/lib/exec/service_follow_request.rb +49 -0
  120. data/lib/exec/service_info.rb +346 -0
  121. data/lib/exec/service_install.rb +87 -0
  122. data/lib/exec/service_ls.rb +124 -0
  123. data/lib/exec/service_start.rb +110 -0
  124. data/lib/exec/service_stop.rb +112 -0
  125. data/lib/receiver.rb +14 -0
  126. data/lib/receiver/ambari_receiver.rb +812 -0
  127. data/lib/receiver/ambari_rest_api_connector.rb +599 -0
  128. data/lib/receiver/basic_receiver.rb +28 -0
  129. data/lib/receiver/connector.rb +28 -0
  130. data/lib/receiver/crowbar_receiver.rb +588 -0
  131. data/lib/receiver/crowbar_rest_api_connector.rb +518 -0
  132. data/lib/receiver/crowbar_shell_api.rb +643 -0
  133. data/lib/receiver/rest_api_connector.rb +275 -0
  134. data/resources/ambari-configurations/HBASE/default_hbase-site +33 -0
  135. data/resources/ambari-configurations/HDFS/default_hdfs-site +49 -0
  136. data/resources/ambari-configurations/HIVE/default_hive-site +33 -0
  137. data/resources/ambari-configurations/MAPREDUCE/default_mapred-site +72 -0
  138. data/resources/ambari-configurations/OOZIE/default_oozie-site +28 -0
  139. data/resources/ambari-configurations/WEBHCAT/default_webhcat-site +18 -0
  140. data/resources/ambari-configurations/ZOOKEEPER/default_zookeeper-site +8 -0
  141. data/resources/ambari-configurations/default_core-site +22 -0
  142. data/resources/ambari-configurations/default_global +141 -0
  143. data/resources/cloudbox-server.conf +10 -0
  144. data/spec/common/services_description.rb +130 -0
  145. data/spec/exec/check_parameter.rb +152 -0
  146. data/spec/exec/command_option_spec.rb +97 -0
  147. metadata +328 -0
@@ -0,0 +1,346 @@
1
+ # This file is part of cloudbox-server project
2
+ # @author tnoguer (INGENSI)
3
+
4
+ require 'exec/executable_command'
5
+ require 'exec/check_parameter'
6
+ require 'command/ambari_service_info'
7
+ require 'command/ambari_service_list'
8
+ require 'common/cloudbox_exceptions'
9
+ require 'common/color'
10
+
11
+ include Exec::CheckParameter
12
+
13
+ module Exec
14
+ # Allows the user to show pieces of cluster's services information.
15
+ # @author tnoguer
16
+ # @todo Refactor class helper and all the fuss around it
17
+ class ServiceInfo < ExecutableCommand
18
+
19
+ protected
20
+ # service attributes to ignore
21
+ attr_accessor :ignore_service_attributes
22
+ # service component attributes to ignore
23
+ attr_accessor :ignore_attr_service_component
24
+ # host component attributes to ignore
25
+ attr_accessor :ignore_attr_host_component
26
+
27
+ public
28
+ def initialize(argv, stdin, stdout, stderr, command_name)
29
+ super(argv, stdin, stdout, stderr, command_name)
30
+ @ignore_service_attributes = []
31
+ @ignore_attr_service_component = %w{ cluster_name service_name }
32
+ @ignore_attr_host_component = %w{ cluster_name component_name }
33
+ end
34
+
35
+ private
36
+ # Parse and check the parameters of the function.
37
+ # @author tnoguer
38
+ def set_options
39
+ @logger.info("setting options")
40
+ @options.add_option("C", "cluster", "The cluster name.", true, true, method(:check_cluster_name))
41
+ @options.add_option("s", "service", "Limit the request to this service.", false, true, method(:check_hadoop_service_name))
42
+ @options.add_option("H", "host", "Limit the request to this host.", false, true, method(:check_ambari_host_name))
43
+ @options.add_option("c", "component", "Limit the request to this component type.", false, true, method(:check_hadoop_component_name))
44
+ end
45
+
46
+ public
47
+ # The execution of the command.
48
+ # @author tnoguer
49
+ def exec
50
+ Color::print_log("NONE", "getting service list...", @stdout)
51
+ confs = Command::AmbariServiceConfLs.new(@values["cluster"]).exec()
52
+ Color::echo_ok(@stdout)
53
+ @stdout.print "\nCLUSTER #{@values["cluster"]}\n"
54
+ @stdout.print "desired configs: \n"
55
+ confs.each do |conf|
56
+ if conf["active"]
57
+ @stdout.print(" " + " " + conf["type"] + " " + conf["tag"]+ "\n")
58
+ end
59
+ end
60
+ if @values["service"].nil?
61
+ msg = info_all_services()
62
+ else
63
+ msg = info_service()
64
+ end
65
+ @stdout.print msg
66
+ end
67
+
68
+ private
69
+ # Shows the informations for all the services.
70
+ # @return The information to print.
71
+ def info_all_services
72
+ @logger.begin_execution("infoService")
73
+
74
+ # Getting service list
75
+ data = Command::AmbariServiceList.new(@values["cluster"]).exec()
76
+
77
+ output = ""
78
+
79
+ # Call infoservice for each service
80
+ data["items"].each do |service|
81
+ service_name = service["ServiceInfo"]["service_name"].to_s
82
+ output += "\n======== #{service_name} ========\n"
83
+ output += info_service(@values["cluster"], service_name, @values["host"], @values["component"])
84
+ end
85
+
86
+ @logger.end_execution()
87
+ return output
88
+ end
89
+
90
+ private
91
+ # Shows the information for specific services.
92
+ # @param cluster_name The name of the cluster.
93
+ # @param service_name The name of the service.
94
+ # @param host_name The name of the host.
95
+ # @param component_name The name of the component.
96
+ # @param prefix The prefix to show before the services.
97
+ # @param prefix_char The prefix character to show before the services.
98
+ # @return The information to print.
99
+ def info_service(cluster_name = @values["cluster"], service_name = @values["service"], host_name = @values["host"], component_name = @values["component"], prefix = " ", prefix_char = " ")
100
+ @logger.begin_execution("infoService")
101
+ begin
102
+ output = color_white("Service #{service_name} on cluster #{cluster_name}", 1) + " :\n"
103
+ output += "Display only host '#{host_name}'\n" if !host_name.nil?
104
+ output += "Display only component '#{component_name}'\n" if !component_name.nil?
105
+
106
+ data = Command::AmbariServiceInfo.new(cluster_name, service_name).exec()
107
+
108
+ data["components"] = data["components"].sort { |x, y| x["href"] <=> y["href"] }
109
+ @logger.debug(data)
110
+ output += format_info_service(data, host_name, component_name, prefix + prefix_char, prefix_char)
111
+ rescue => e
112
+ raise e
113
+ end
114
+
115
+ @logger.info("output info service: #{output}")
116
+ @logger.end_execution()
117
+ return output
118
+ end
119
+
120
+ private
121
+ # Indicates if a status is incorrect.
122
+ # @param data The data containing the status to check.
123
+ # @return True if the status is incorrect, false otherwise.
124
+ def is_bad_status(data)
125
+ bad = false
126
+ if !data["HostRoles"].nil? && !data["HostRoles"]["desired_state"].nil? && !data["HostRoles"]["state"].nil?
127
+ desired_state = data["HostRoles"]["desired_state"]
128
+ state = data["HostRoles"]["state"]
129
+ if desired_state != state && !Helper.is_transitional_status?(state)
130
+ bad = true
131
+ end
132
+ end
133
+ return bad
134
+ end
135
+
136
+ private
137
+ def format_info_service(data, host_name, component_name, prefix = "\t", prefix_char = "\t")
138
+ raise(StandardError, "Malformed return request") if data["ServiceInfo"].nil?
139
+ output = ""
140
+ data["ServiceInfo"] = data["ServiceInfo"].sort
141
+
142
+ data["ServiceInfo"].each do |info_name, info_value|
143
+ unless @ignore_service_attributes.include?(info_name.to_s)
144
+ if info_name.to_s != "state" && info_name.to_s != "desired_state"
145
+ output += prefix + info_name.to_s + ": "
146
+ end
147
+ case info_name.to_s
148
+ when "desired_configs", "actual_configs", "configs"
149
+ output += format_configs(info_value, prefix + prefix_char)
150
+ else
151
+ output += info_value.to_s + "\n"
152
+ end
153
+ end
154
+ end
155
+
156
+ if data["components"].nil?
157
+ output += "No component in this cluster."
158
+ else
159
+ output += "Components: \n" if component_name.nil?
160
+ output += "Components (only #{component_name}): \n" if !component_name.nil?
161
+ data["components"] = data["components"].sort { |x, y| x["href"] <=> y["href"] }
162
+ data["components"].each do |component|
163
+ if component_name.nil? || component["ServiceComponentInfo"]["component_name"] == component_name
164
+ output += format_component(component, host_name, prefix + prefix_char, prefix_char)
165
+ end
166
+ end
167
+ end
168
+ return output
169
+ end
170
+
171
+ private
172
+ def format_component(data, host_name, prefix = "\t", prefix_char = "\t")
173
+ raise(StandardError, "Malformed return request") if data["ServiceComponentInfo"].nil?
174
+
175
+ infos = ""
176
+ title = ""
177
+ host_comp = ""
178
+ data["ServiceComponentInfo"] = data["ServiceComponentInfo"].sort
179
+
180
+ data["ServiceComponentInfo"].each do |info_name, info_value|
181
+ unless @ignore_attr_service_component.include?(info_name.to_s)
182
+ case info_name.to_s
183
+ when "state", "desired_state"
184
+ # infos += prefix + info_name.to_s + ": " + format_state(info_value.to_s) + "\n"
185
+ when "component_name"
186
+ title = prefix + color_white("Component " + info_value.to_s, 1) + ":\n"
187
+ when "desired_configs", "actual_configs", "configs"
188
+ #infos += prefix + info_name.to_s + ": " + format_configs(info_value, prefix + prefix_char)
189
+ else
190
+ infos += prefix + info_name.to_s + ": " + info_value.to_s + "\n"
191
+ end
192
+ end
193
+ end
194
+
195
+ if !data["host_components"].nil? && data["host_components"].length > 0
196
+ data["host_components"] = data["host_components"].sort { |x, y| x["href"] <=> y["href"] }
197
+ data["host_components"].each do |host_component|
198
+ if host_name.nil? || host_component["HostRoles"]["host_name"] == host_name
199
+ host_comp += format_host_component(host_component, prefix + prefix_char, prefix_char)
200
+ end
201
+ end
202
+ else
203
+ host_comp = prefix + "Hosts: none\n"
204
+ end
205
+ return title + infos + host_comp
206
+ end
207
+
208
+ private
209
+ def format_host_component(data, prefix = "\t", prefix_char = "\t")
210
+ raise(StandardError, "Malformed return request") if data["HostRoles"].nil?
211
+
212
+ title = ""
213
+ output = ""
214
+ output += color_yellow(prefix + "/!\\ WARNING STATUS\n") if is_bad_status(data)
215
+ data["HostRoles"] = data["HostRoles"].sort
216
+
217
+ data["HostRoles"].each do |info_name, info_value|
218
+ unless @ignore_attr_host_component.include?(info_name.to_s)
219
+ case info_name.to_s
220
+ when "host_name"
221
+ title = prefix + color_white("Host: " + info_value.to_s, 1) + "\n"
222
+ when "state", "desired_state"
223
+ output += prefix + info_name.to_s + ": " + format_state(info_value.to_s) + "\n"
224
+ when "config", "desired_config", "actual_configs"
225
+ output += prefix + info_name + format_configs(info_value, prefix + prefix_char)
226
+ else
227
+ output += prefix + info_name.to_s + ": " + info_value.to_s + "\n"
228
+ end
229
+ end
230
+ end
231
+ return title + output
232
+ end
233
+
234
+ end
235
+
236
+ private
237
+ # @todo do something
238
+ class Helper
239
+
240
+ @@adoop_services_description = {
241
+ "HDFS" => {
242
+ "MASTER" => %w{NAMENODE SECONDARY_NAMENODE},
243
+ "SLAVE" => %w{DATANODE},
244
+ "MAPREDUCE" => {
245
+ "MASTER" => %w{JOBTRACKER},
246
+ "SLAVE" => %w{TASKTRACKER}},
247
+ "HIVE" => {
248
+ "MASTER" => %w{HIVE_SERVER},
249
+ "SLAVE" => []},
250
+ "HBASE" => {
251
+ "MASTER" => %w{HBASE_MASTER},
252
+ "SLAVE" => %w{HBASE_REGIONSERVER}},
253
+ "ZOOKEEPER" => {
254
+ "MASTER" => %w{ZOOKEEPER_SERVER},
255
+ "SLAVE" => []},
256
+ "OOZIE" => {
257
+ "MASTER" => %w{OOZIE_SERVER},
258
+ "SLAVE" => []},
259
+ "NAGIOS" => {
260
+ "MASTER" => %w{NAGIOS_SERVER},
261
+ "SLAVE" => []},
262
+ "GANGLIA" => {
263
+ "MASTER" => %w{GANGLIA_SERVER},
264
+ "SLAVE" => []}
265
+ }
266
+ }
267
+
268
+ @@component_status = %w{INSTALLED STARTED MANTENANCE INIT}
269
+ @@component_transitional_status = %w{INSTALLING STARTING STOPPING}
270
+
271
+ def self.is_master_component?(component_name)
272
+ is_master = false
273
+ @@adoop_services_description.each_value do |type|
274
+ if type["MASTER"].include?(component_name)
275
+ is_master = true
276
+ break
277
+ end
278
+ end
279
+ return is_master
280
+ end
281
+
282
+ # Get the components of a service.
283
+ # @param service_name The name of the service.
284
+ # @return The list of components.
285
+ def self.get_service_components(service_name)
286
+ return @@adoop_services_description[service_name]
287
+ end
288
+
289
+ # @todo refactorise with same function in ambari receiver...
290
+ def self.get_service_by_component_name(component_name)
291
+ @@adoop_services_description.each do |service_name, types|
292
+ types.each_value do |component_names|
293
+ return service_name if component_names.include?(component_name)
294
+ end
295
+ end
296
+ return nil
297
+ end
298
+
299
+ # @todo refactorise with same function in ambari receiver...
300
+ def self.get_all_component_name()
301
+ all_components = []
302
+ @@adoop_services_description.each_value do |types|
303
+ types.each_value do |component_names|
304
+ all_components = all_components.concat(component_names)
305
+ end
306
+ end
307
+ return all_components
308
+ end
309
+
310
+ # @todo refactorise with same function in ambari receiver...
311
+ def self.get_readable_components()
312
+ all_components = ""
313
+ @@adoop_services_description.each_value do |types|
314
+ types.each_value do |component_names|
315
+ component_names.each do |cn|
316
+ all_components += " "+cn+"\n"
317
+ end
318
+ end
319
+ end
320
+ return all_components
321
+ end
322
+
323
+ # @todo refactorise with same kind of function in ambari receiver...
324
+ def self.is_transitional_status?(state)
325
+ return @@component_transitional_status.include?(state)
326
+ end
327
+
328
+ # @todo refactorise with same kind of function in ambari receiver...
329
+ def self.get_readable_service_desc(prefix = "\t")
330
+ output = "SERVICE_NAME (COMPONENT_LIST)\n"
331
+ @@adoop_services_description.each do |service_name, component_type|
332
+ output += prefix + service_name.to_s + "("
333
+ first = true
334
+ list = component_type['MASTER']
335
+ list.concat(component_type['SLAVE'])
336
+ list.each do |component_name|
337
+ output += ", " unless first
338
+ output += component_name.to_s
339
+ first = false
340
+ end
341
+ output += ")\n"
342
+ end
343
+ return output
344
+ end
345
+ end
346
+ end
@@ -0,0 +1,87 @@
1
+ # This file is part of cloudbox-service project
2
+ # @author tmarmin (INGENSI)
3
+
4
+ require 'exec/executable_command'
5
+ require 'exec/check_parameter'
6
+
7
+ require 'command/ambari_install_component'
8
+ require 'command/ambari_install_host'
9
+ require 'command/ambari_install_host_component'
10
+ require 'command/ambari_install_service_components'
11
+ require 'command/ambari_install_host_component'
12
+ require 'command/ambari_install_cluster'
13
+
14
+ include Exec::CheckParameter
15
+
16
+ module Exec
17
+ # Allows the user to install services.
18
+ # @author tnoguer
19
+ class ServiceInstall < ExecutableCommand
20
+
21
+ private
22
+ # Parse and check the parameters of the function.
23
+ # @author tmarmin
24
+ def set_options
25
+ @logger.info("setting options")
26
+ @options.add_option("C", "cluster", "The virtual cluster name.", true, true, method(:check_cluster_name))
27
+ @options.add_option("s", "service", "Limit request to this service.", false, true, method(:check_hadoop_service_name))
28
+ @options.add_option("H", "host", "Limit request to this host.", false, true, method(:check_ambari_host_name))
29
+ @options.add_option("c", "component", "Limit request to this component type.", false, true, method(:check_hadoop_component_name))
30
+ @options.add_option("f", "follow", "Follow completion of the request.", false)
31
+ end
32
+
33
+ private
34
+ # Execution of the command
35
+ def exec
36
+ msg = "Unknown combination of attributes... (should never happend)"
37
+ cmd = nil
38
+
39
+ if (!@values["host"].nil? && !@values["component"].nil?) || (!@values["service"].nil? && !@values["host"].nil? && !@values["component"].nil?)
40
+ # 3
41
+ # one component on one host
42
+ msg = "Install components #{@values["component"]} on host #{@values["host"]} (@cluster #{@values["cluster"]})."
43
+ cmd = Command::AmbariInstallHostComponent.new(@values["cluster"], @values["component"], @values["host"])
44
+
45
+ elsif !@values["component"].nil? || (!@values["service"].nil? && !@values["component"].nil?)
46
+ # 1
47
+ # one component on all hosts
48
+ msg = "Install all components (@cluster #{@values["cluster"]})."
49
+ cmd = Command::AmbariInstallComponent.new(@values["cluster"], @values["component"])
50
+
51
+ elsif !@values["service"].nil? && !@values["host"].nil?
52
+ # 5
53
+ # all component on one host for one service
54
+ # @todo it is the same case than number 3
55
+ msg = "Install components #{@values["component"]} of service #{@values["service"]} on host #{@values["host"]} (@cluster #{@values["cluster"]})."
56
+ cmd = Command::AmbariInstallHostComponents.new(@values["cluster"], @values["service"], @values["host"])
57
+
58
+ elsif !@values["host"].nil?
59
+ # 2
60
+ # all component on one host
61
+ msg = "Install all components on host #{@values["host"]} (@cluster #{@values["cluster"]})."
62
+ cmd = Command::AmbariInstallHost.new(@values["cluster"], @values["host"])
63
+
64
+ elsif !@values["service"].nil?
65
+ # 4
66
+ # all component on all hosts for one service
67
+ msg = "Install all components #{@values["component"]} of service #{@values["service"]} on all hosts (@cluster #{@values["cluster"]})."
68
+ cmd = Command::AmbariInstallServiceComponents.new(@values["cluster"], @values["service"])
69
+
70
+ elsif @values["service"].nil? && @values["host"].nil? && @values["component"].nil?
71
+ # 6
72
+ # all component on all host for all service
73
+ msg = "Install all components of all services on all hosts (@cluster #{@values["cluster"]})."
74
+ cmd = Command::AmbariInstallCluster.new(@values["cluster"])
75
+
76
+ else
77
+ raise StandardError(msg)
78
+ end
79
+
80
+ Color::print_log("NONE", msg, @stdout)
81
+ cmd.exec()
82
+ Color::echo_ok(@stdout)
83
+
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,124 @@
1
+ # This file is part of cloudbox-server project
2
+ # @author tnoguer (INGENSI)
3
+
4
+ require 'exec/executable_command'
5
+ require 'exec/check_parameter'
6
+ require 'command/ambari_cluster_list'
7
+ require 'common/cloudbox_exceptions'
8
+ require 'common/color'
9
+
10
+ include Exec::CheckParameter
11
+
12
+ # Allows the user to list the services along with some piece of information.
13
+ # @author tnoguer
14
+ module Exec
15
+ # Allows the user to list the services.
16
+ # @author tnoguer
17
+ class ServiceLs < ExecutableCommand
18
+
19
+ private
20
+ # Parse and check the parameters of the function.
21
+ # @author tmarmin
22
+ def set_options
23
+ @logger.info("setting options")
24
+ @options.add_option("C", "cluster", "The cluster name where to list services.", true, true, method(:check_cluster_name))
25
+ @options.add_option("a", "all", "List the services of all clusters.", false)
26
+ end
27
+
28
+ public
29
+ # The execution of the command.
30
+ # @author tnoguer
31
+ def exec
32
+ @logger.begin_main_step("service list getting")
33
+ Color::print_log("NONE", "getting service list...")
34
+ begin
35
+ if @values["all"]
36
+ msg=list_all_clusters_services()
37
+ else
38
+ msg=list_services()
39
+ end
40
+ Color::echo_ok
41
+ @stdout.puts(msg)
42
+ rescue => e
43
+ Color::echo_fail(@stdout)
44
+ raise e
45
+ end
46
+ @logger.end_main_step("service list getting")
47
+ end
48
+
49
+ private
50
+ #list all th service of all the cluster
51
+ def list_all_clusters_services
52
+ cmd = Command::AmbariClusterList.new()
53
+ data = cmd.exec()
54
+ output = ""
55
+ unless data["items"].nil?
56
+ data["items"] = data["items"].sort { |x, y| x["href"] <=> y["href"] }
57
+ data["items"].each do |cluster|
58
+ output += "Cluster " + cluster["Clusters"]["cluster_name"] + "\n"
59
+ output += list_services(cluster["Clusters"]["cluster_name"], "\t") + "\n"
60
+ end
61
+ end
62
+ return output
63
+ end
64
+
65
+ private
66
+ # list the service for one cluster
67
+ # @param cluster_name Name of the cluster
68
+ def list_services(cluster_name = @values["cluster"], prefix = '')
69
+ @logger.begin_main_step("listServices")
70
+ begin
71
+ output = prefix + "Services available on cluster #{cluster_name}:"
72
+ command = Command::AmbariServiceList.new(cluster_name)
73
+ data = command.exec()
74
+
75
+ return prefix + "No service" if data["items"].nil? || data["items"].length == 0
76
+
77
+ data["services"] = data["items"].sort { |x, y| x["href"] <=> y["href"] }
78
+ output += "\n"
79
+ data["services"].each do |service|
80
+ output += format_service(service, prefix + "\t")
81
+ end
82
+ rescue => e
83
+ raise e
84
+ end
85
+
86
+ @logger.debug("service list output: #{output}")
87
+ @logger.end_main_step("listServices")
88
+
89
+ return output
90
+ end
91
+
92
+ private
93
+ def format_service(service, prefix = '')
94
+ raise(StandardError, "Malformed return request") if service["ServiceInfo"].nil? || service["ServiceInfo"]["service_name"].nil?
95
+ output = prefix + service["ServiceInfo"]["service_name"] + "\n"
96
+ unless service["components"].nil?
97
+ service["components"] = service["components"].sort { |x, y| x["href"] <=> y["href"] }
98
+ service["components"].each do |component|
99
+ output+= "\t" + prefix + component["ServiceComponentInfo"]["component_name"] + "\n"
100
+ unless component["host_components"].nil?
101
+ component["host_components"] = component["host_components"].sort { |x, y| x["href"] <=> y["href"] }
102
+ component["host_components"].each do |host|
103
+ output += "\t\t" + prefix + host["HostRoles"]["host_name"] + "\n"
104
+ end
105
+ end
106
+ end
107
+ end
108
+ return output
109
+ end
110
+
111
+ private
112
+ # Inherited CommandOption used only by ServiceLs.
113
+ class CustomCommandOption < CommandOption
114
+
115
+ protected
116
+ # This method overrides the default behaviour.
117
+ # @raise [Common::MissingParameter] Never raise exception for the moment :)
118
+ def check_mandatory
119
+ raise Common::MissingParameter.new("-C", get_help()) if !@values["help"] && !@values["all"] && @values["cluster"].nil?
120
+ end
121
+ end
122
+
123
+ end
124
+ end