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,192 @@
1
+ # This file is part of cloudbox-service project
2
+ # @author tmarmin (INGENSI)
3
+
4
+ module Common
5
+
6
+ module ServicesDescription
7
+ private
8
+ # This variable gives informations about each service available in cloudbox.
9
+ # :MASTER : master components,
10
+ # :SLAVE : slave components,
11
+ # :CONFIG : nil if service doesn't require configuration, name of the config type else,
12
+ # :SLAVEONMASTER : slave components to install on master node by default.
13
+ # :DEPS : dependencies with other services.
14
+ @services_description = {
15
+ "HDFS" => {
16
+ :MASTER => %w{NAMENODE}, # Maybe add SECONDARY NAMENODE
17
+ :SLAVE => %w{DATANODE},
18
+ :CONFIG => "hdfs-site",
19
+ :SLAVEONMASTER => [],
20
+ :DEPS => []},
21
+ "MAPREDUCE" => {
22
+ :MASTER => %w{JOBTRACKER},
23
+ :SLAVE => %w{TASKTRACKER},
24
+ :CONFIG => "mapred-site",
25
+ :SLAVEONMASTER => [],
26
+ :DEPS => %w{HDFS}},
27
+ "HIVE" => {
28
+ :MASTER => %w{HIVE_SERVER},
29
+ :SLAVE => [],
30
+ :CONFIG => "hive-site",
31
+ :SLAVEONMASTER => [],
32
+ :DEPS => %w{MAPREDUCE}},
33
+ "HBASE" => {
34
+ :MASTER => %w{HBASE_MASTER},
35
+ :SLAVE => %w{HBASE_REGIONSERVER},
36
+ :CONFIG => "hbase-site",
37
+ :SLAVEONMASTER => [],
38
+ :DEPS => %w{HDFS ZOOKEEPER}},
39
+ "ZOOKEEPER" => {
40
+ :MASTER => %w{ZOOKEEPER_SERVER},
41
+ :SLAVE => [],
42
+ :CONFIG => "zookeeper-site",
43
+ :SLAVEONMASTER => [],
44
+ :DEPS => []},
45
+ "OOZIE" => {
46
+ :MASTER => %w{OOZIE_SERVER},
47
+ :SLAVE => [],
48
+ :CONFIG => "oozie-site",
49
+ :SLAVEONMASTER => [],
50
+ :DEPS => []},
51
+ "NAGIOS" => {
52
+ :MASTER => %w{NAGIOS_SERVER},
53
+ :SLAVE => [],
54
+ :CONFIG => nil,
55
+ :SLAVEONMASTER => [],
56
+ :DEPS => []},
57
+ "GANGLIA" => {
58
+ :MASTER => %w{GANGLIA_SERVER},
59
+ :SLAVE => %w{GANGLIA_MONITOR},
60
+ :CONFIG => nil,
61
+ :SLAVEONMASTER => %w{GANGLIA_MONITOR},
62
+ :DEPS => []}
63
+ }
64
+
65
+ public
66
+ def get_services_list
67
+ return @services_description.keys
68
+ end
69
+
70
+ public
71
+ def get_components_list
72
+ components = []
73
+ @services_description.each_value do |value|
74
+ components.concat(value[:MASTER])
75
+ components.concat(value[:SLAVE])
76
+ end
77
+
78
+ return components.uniq
79
+ end
80
+
81
+ public
82
+ def get_components(service_name)
83
+ components = []
84
+ unless @services_description[service_name].nil?
85
+ components = @services_description[service_name][:MASTER] + @services_description[service_name][:SLAVE]
86
+ end
87
+
88
+ return components
89
+ end
90
+
91
+ public
92
+ def get_config_name_service(service_name)
93
+ config_name = nil
94
+ unless @services_description[service_name].nil?
95
+ config_name = @services_description[service_name][:CONFIG]
96
+ end
97
+
98
+ return config_name
99
+ end
100
+
101
+ public
102
+ def get_master_nodes(service_name)
103
+ components = []
104
+ unless @services_description[service_name].nil?
105
+ components = @services_description[service_name][:MASTER]
106
+ end
107
+
108
+ return components
109
+ end
110
+
111
+ public
112
+ def get_slave_nodes(service_name)
113
+ components = []
114
+ unless @services_description[service_name].nil?
115
+ components = @services_description[service_name][:SLAVE]
116
+ end
117
+
118
+ return components
119
+ end
120
+
121
+ public
122
+ def get_slave_nodes_on_master(service_name)
123
+ components = []
124
+ unless @services_description[service_name].nil?
125
+ components = @services_description[service_name][:SLAVEONMASTER]
126
+ end
127
+
128
+ return components
129
+ end
130
+
131
+ public
132
+ def get_deps(service_name)
133
+ deps = []
134
+ unless @services_description[service_name].nil?
135
+ deps = @services_description[service_name][:DEPS]
136
+ deps.each do |deps_name|
137
+ deps.concat(get_deps(deps_name))
138
+ end
139
+ end
140
+
141
+ return deps.uniq
142
+ end
143
+
144
+ public
145
+ def get_depends_on(service_name)
146
+ depends = []
147
+
148
+ @services_description.each do |service, description|
149
+ [service, description]
150
+ if service != service_name && description[:DEPS].include?(service_name)
151
+ depends.push(service)
152
+ depends.concat(get_depends_on(service))
153
+ end
154
+ end
155
+
156
+ return depends.uniq
157
+ end
158
+
159
+ public
160
+ def get_master_components_deps(service_name)
161
+ deps = []
162
+ service_deps = get_deps(service_name)
163
+
164
+ service_deps.each do |service_dep|
165
+ deps.concat(get_master_nodes(service_dep))
166
+ end
167
+
168
+ return deps.uniq
169
+ end
170
+
171
+ def get_master_components_depends_on(service_name)
172
+ deps = []
173
+ service_deps = get_depends_on(service_name)
174
+
175
+ service_deps.each do |service_dep|
176
+ deps.concat(get_master_nodes(service_dep))
177
+ end
178
+
179
+ return deps.uniq
180
+ end
181
+
182
+ public
183
+ def get_service_name_by_comp_name(component_name)
184
+ @services_description.each do |service_name, values|
185
+ return service_name if (values[:MASTER].include?(component_name) || values[:SLAVE].include?(component_name))
186
+ end
187
+
188
+ return nil
189
+ end
190
+
191
+ end
192
+ end
@@ -0,0 +1,35 @@
1
+ # This file is part of cloudbox-service project
2
+ # @author tmarmin (INGENSI)
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'exec/executable_command'
7
+ require 'exec/command_option'
8
+
9
+ require 'exec/node_ls'
10
+ require 'exec/cluster_create'
11
+ require 'exec/cluster_ls'
12
+ require 'exec/cluster_delete'
13
+ require 'exec/cluster_allocate'
14
+ require 'exec/cluster_desallocate'
15
+ require 'exec/service_conf_create'
16
+ require 'exec/cluster_info'
17
+
18
+ require 'exec/node_destroy'
19
+ require 'exec/node_detach'
20
+ require 'exec/node_info'
21
+ require 'exec/node_install'
22
+ require 'exec/node_ls'
23
+ require 'exec/service_add'
24
+ require 'exec/service_conf_ls'
25
+ require 'exec/service_conf_apply'
26
+ require 'exec/service_component_add'
27
+ require 'exec/service_component_delete'
28
+ require 'exec/service_component_detach'
29
+ require 'exec/service_follow_request'
30
+ require 'exec/service_info'
31
+ require 'exec/service_install'
32
+ require 'exec/service_ls'
33
+ require 'exec/service_start'
34
+ require 'exec/service_stop'
35
+ require 'exec/service_conf_get'
@@ -0,0 +1,208 @@
1
+ # This file is part of cloudbox-server project
2
+ # @author tmarmin (INGENSI)
3
+
4
+ require 'rubygems'
5
+ require 'ipaddress'
6
+
7
+ require 'lib/common/services_description'
8
+
9
+ module Exec
10
+ #Module who gather all methods whoch check synthax of parameter
11
+ module CheckParameter
12
+
13
+ # Check cluster name format.
14
+ # It has to be a string of alphanumric down case char.
15
+ def check_cluster_name(str)
16
+ return match_regex(str, /^[a-z0-9]+$/, "The vcluser name #{str} is not valid. It should be an alphanumeric (down case) string.")
17
+ end
18
+
19
+ # Check type name format of the configuration about a ambari cluster.
20
+ # It has to be a string of alphanumric down case char.
21
+ def check_type_conf(str)
22
+ return match_regex(str, /^[a-z0-9]+$/, "The type name #{str} of the configuration is not valid. It should be an alphanumeric (down case) string.")
23
+ end
24
+
25
+ # Check tag name format of the configuration about a ambari cluster.
26
+ # It has to be a string of alphanumric down case char.
27
+ #def check_tag_conf(str)
28
+ # return match_regex(str, /^[a-z0-9]+$/, "The tag name #{str} of the configuration is not valid. It should be an alphanumeric (down case) string.")
29
+ #end
30
+
31
+ # Check crowbar node name format.
32
+ # It has to be a string of any characters.
33
+ def check_crowbar_node_name(str)
34
+ return match_regex(str, /^[A-Z0-9a-z\-]+$/, "The Node name #{str} is not valid.")
35
+ end
36
+
37
+ # Check raid name format.
38
+ # It has to be a string of alphanumric down case char.
39
+ def check_param_for_bios(str)
40
+ msg = ""
41
+ valid = true
42
+ if str.strip() != "Hadoop" && str.strip() != "HadoopInfra" && str.strip() != "Storage" && str.strip() != "Virtualization"
43
+ valid = false
44
+ msg = "The Bios name must be only \"Hadoop\", \"HadoopInfra\", \"Storage\" or \"Virtualization\""
45
+ return valid, msg
46
+ end
47
+ return valid, msg
48
+ end
49
+
50
+ # Check raid name format.
51
+ # It has to be a string of alphanumric down case char.
52
+ def check_param_for_raid(str)
53
+ msg = ""
54
+ valid = true
55
+ if str.strip() != "JBODOnly" && str.strip() != "Raid10"
56
+ valid = false
57
+ msg = "The Raid name must be only \"JBODOnly\" or \"Raid10\""
58
+ return valid, msg
59
+ end
60
+ return valid, msg
61
+ end
62
+
63
+ # Check vlan id format.
64
+ # It has to be a positive integer.
65
+ def check_vlan_id(str)
66
+ if str.to_i >= 10 && str.to_i <= 4096
67
+ return match_regex(str.to_s, /^[1-9][0-9]+$/, "ID Vlan '#{str}' is not a correct number.")
68
+ else
69
+ return false, "ID Vlan '#{str}' is not a correct number."
70
+ end
71
+ end
72
+
73
+ # Check ram size format.
74
+ # It has to be an integer followed by 'g' charatcter.
75
+ def check_ram_size(str)
76
+ return match_regex(str, /^[1-9]+[0-9]*g$/, "RAM value #{str} is not valid. It should be a positive integer followed by.")
77
+ end
78
+
79
+ # Check cpu weight format.
80
+ # It has to be a positive integer.
81
+ def check_cpu_weight(str)
82
+ return match_regex(str, /^[1-9]+[0-9]*$/, "CPU value '#{str}' is not valid. It should be a positive integer.")
83
+ end
84
+
85
+ # Check network address.
86
+ # Exemple of network format : 10.0.0.0/8
87
+ # Network adress must have 1 octet in order to have a CIDR equals to 8
88
+ # Network adress must have 2 octet in order to have a CIDR equals to 16
89
+ # Network adress must have 3 octet in order to have a CIDR equals to 24
90
+ def check_network_address(str)
91
+ msg = ""
92
+ valid = true
93
+ if str == nil
94
+ valid = false
95
+ msg = "Network adress and mask is missing"
96
+ return valid, msg
97
+ end
98
+ network = str.split("/").first
99
+ cidr = str.split("/").last
100
+
101
+ if network == nil
102
+ valid = false
103
+ msg = "Network adress is missing"
104
+ return valid, msg
105
+ end
106
+ if cidr == nil
107
+ valid = false
108
+ msg = "cidr mask is missing "
109
+ return valid, msg
110
+ end
111
+
112
+ if cidr != "24" && cidr != "16" && cidr != "8"
113
+ valid = false
114
+ msg = "cidr is only valid if equal 8 , 16 , 24 "
115
+ return valid, msg
116
+ end
117
+ unless IPAddress.valid?(network)
118
+ valid = false
119
+ msg = "Network adress is not valid "
120
+ return valid, msg
121
+ end
122
+ octet1 = network.split(".").first
123
+ octet2 = network.split(".").at(1)
124
+ octet3 = network.split(".").at(2)
125
+ octet4 = network.split(".").last
126
+ if cidr == "8"
127
+ if octet1 == "0" || octet2 != "0" || octet3 != "0" || octet4 !="0"
128
+ valid = false
129
+ msg = "Network adress is not valid "
130
+ return valid, msg
131
+ end
132
+ elsif cidr == "16"
133
+ if octet1 == "0" || octet3 != "0" || octet4 !="0"
134
+ valid = false
135
+ msg = "Network adress is not valid "
136
+ return valid, msg
137
+ end
138
+ elsif cidr == "24"
139
+ if octet1 == "0" || octet4 != "0"
140
+ valid = false
141
+ msg = "Network adress is not valid "
142
+ return valid, msg
143
+ end
144
+ end
145
+
146
+ return valid, msg
147
+ end
148
+
149
+ # Check hadoop service name.
150
+ # It has to be a known hadoop service.
151
+ def check_hadoop_service_name(str)
152
+ hadoop_services = Common::ServicesDescription.get_services_list
153
+ valid = true
154
+ msg = ""
155
+
156
+ unless hadoop_services.include?(str)
157
+ valid = false
158
+ msg = "Service name parameter has to be known Hadoop service."
159
+ end
160
+
161
+ return valid, msg
162
+ end
163
+
164
+ # Check hadoop component name.
165
+ # It has to be a known component name.
166
+ def check_hadoop_component_name(str)
167
+ hadoop_components = Common::ServicesDescription.get_components_list
168
+ valid = true
169
+ msg = ""
170
+
171
+ unless hadoop_components.include?(str)
172
+ valid = false
173
+ msg = "Component name parameter has to be known Hadoop component."
174
+ end
175
+
176
+ return valid, msg
177
+ end
178
+
179
+ # Check ambari host name
180
+ # @todo returns allways true for the moment.
181
+ def check_ambari_host_name(str)
182
+ return true, ""
183
+ end
184
+
185
+ # Check request id.
186
+ # It has to be an integer.
187
+ def check_request_id(str)
188
+ return match_regex(str, /^[0-9]*$/, "Request id has to be a positive integer.")
189
+ end
190
+
191
+ private
192
+ # Check if a string matches a regex
193
+ # @param str [String] The string to check.
194
+ # @param regexp [Rexexp] The regular expression.
195
+ # @param msg_if_nok [String] The message to return if str doesn't match with regex
196
+ # @return [Boolean, String] true,"" if msg matched with regex, false, msg_if_nok if doesn't.
197
+ def match_regex(str, regexp, msg_if_nok)
198
+ msg = ""
199
+ valid = true
200
+ regex=Regexp.new(regexp)
201
+ unless str.match(regex)
202
+ valid = false
203
+ msg = msg_if_nok
204
+ end
205
+ return valid, msg
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,163 @@
1
+ # This file is part of cloudbox-server project
2
+ # Author: mbr (INGENSI)
3
+ # Created: 22/08/13 11:08
4
+
5
+ # You are a good developer if you document this class
6
+
7
+ require 'exec/executable_command'
8
+ require 'exec/check_parameter'
9
+ require 'common/cloudbox_exceptions'
10
+ require 'command/crowbar_node_command'
11
+ require 'command/crowbar_node_list'
12
+ require 'command/crowbar_cluster_allocate'
13
+ require 'command/ambari_add_host'
14
+ require 'command/ambari_host_list'
15
+
16
+ include Exec::CheckParameter
17
+
18
+ module Exec
19
+ # Allows user to allocate node on a cluster
20
+ class ClusterAllocate < ExecutableCommand
21
+
22
+ public
23
+ # Default constructor of the class.
24
+ # @note Overrides default constructor by passing CustomCommandOption to super().
25
+ # @author mbretaud
26
+ def initialize(argv, stdin, stdout, stderr, command_name)
27
+ super(argv, stdin, stdout, stderr, command_name, CustomCommandOption)
28
+ end
29
+
30
+ private
31
+ # Parse and check the parameters of the function.
32
+ # @author tnoguer
33
+ def set_options
34
+ @options.add_option("a", "all", "All nodes which are ready.", false)
35
+ @options.add_option("C", "cluster_name", "The name of the vcluster .", true, true, method(:check_cluster_name))
36
+ @options.add_option("n", "list_nodes", "The list of nodes.", false, true, method(:check_crowbar_node_name))
37
+ end
38
+
39
+ def exec
40
+ @logger.info("Exec::ClusterAllocate Executing ClusterAllocate")
41
+ @logger.info("Exec::ClusterAllocate Allocate node on the vcluster '#{@values['cluster']}'...")
42
+ Color::print_log("NONE", "Allocate node on the vcluster '#{@values['cluster']}'...", @stdout)
43
+
44
+ output = ""
45
+
46
+ if @values['all']
47
+ ###### Allocate all nodes ######
48
+ @logger.info("executing CrowbarNodeList")
49
+ cmd = Command::CrowbarNodeList.new(@logger, "Ready")
50
+ list_nodes = cmd.exec
51
+
52
+ list_nodes_filter = Array.new
53
+ list_nodes.each { |node|
54
+ list_nodes_filter << node.split(" ").at(0).strip.to_s
55
+ }
56
+
57
+ cmd = Command::CrowbarClusterAllocate.new(@logger, @values['cluster_name'], true, list_nodes_filter)
58
+ output += cmd.exec()
59
+
60
+ Color::echo_ok(@stdout)
61
+ output.each{|out|
62
+ Color::print_log("NONE", "#{out}", @stdout)
63
+ Color::echo_ok(@stdout)
64
+ }
65
+ elsif @values['list_nodes'] != nil
66
+ ###### Allocate a list of nodes ######
67
+ cmd = Command::CrowbarNodeList.new(@logger, "Ready")
68
+ list_nodes_ready = cmd.exec()
69
+
70
+ list_nodes = Hash.new
71
+ @values['list_nodes'].split(" ").each{|node|
72
+ list_nodes[node] = node
73
+ }
74
+
75
+ list_nodes_filter = Array.new
76
+ list_nodes.each {|key, value|
77
+ node_exists = false
78
+ list_nodes_ready.each{|node|
79
+ if node == key
80
+ node_exists = true
81
+ end
82
+ }
83
+
84
+ if !node_exists
85
+ raise NodeNotExistsError.new("The node '#{key}' is not exists.")
86
+ end
87
+
88
+ list_nodes_filter << key.strip.to_s
89
+ }
90
+
91
+ cmd = Command::CrowbarClusterAllocate.new(@logger, @values['cluster_name'], false, list_nodes_filter)
92
+ output += cmd.exec()
93
+
94
+ Color::echo_ok(@stdout)
95
+ output.each{|out|
96
+ Color::print_log("NONE", "#{out}", @stdout)
97
+ Color::echo_ok(@stdout)
98
+ }
99
+ end
100
+
101
+ @logger.info("Exec::ClusterAllocate Allocate node on the ambari cluster '#{@values['cluster']}'...")
102
+ Color::print_log("NONE", "Allocate node on the vcluster '#{@values['cluster']}'...", @stdout)
103
+
104
+ output = ""
105
+
106
+ ###### Allocate nodes on the ambari cluster ######
107
+ cmd = Command::AmbariHostList.new(@values['cluster_name'])
108
+ list_hosts = cmd.exec()
109
+
110
+ list_nodes_filter.each do |node|
111
+ host_exists = false
112
+ attempts = 0
113
+ node = "#{@values['cluster_name']}-#{node.gsub(/\s+/, "").strip}"
114
+
115
+ list_hosts.each{|host|
116
+ if host.strip == node.strip
117
+ host_exists = true
118
+ end
119
+ }
120
+
121
+ if !host_exists
122
+ begin
123
+ cmd = Command::AmbariAddHost.new(@values['cluster_name'], node)
124
+ cmd.exec()
125
+ rescue => e
126
+ attempts += 1
127
+ sleep 5
128
+ retry unless attempts > 10
129
+ raise ClusterAllocateError.new("Allocate the host '#{node}' to the ambari cluster '#{@values['cluster_name']}'.")
130
+ end
131
+ output += "Add the host #{node} into the cluster #{@values['cluster_name']}.\n"
132
+ else
133
+ output += "The host #{node} into the cluster #{@values['cluster_name']} is already exists...\n"
134
+ end
135
+
136
+ Color::echo_ok(@stdout)
137
+ output.each{|out|
138
+ Color::print_log("NONE", "#{out}", @stdout)
139
+ Color::echo_ok(@stdout)
140
+ }
141
+ end
142
+ end
143
+
144
+ private
145
+ # Inherited CommandOption used only by ServiceLs.
146
+ class CustomCommandOption < CommandOption
147
+
148
+ # This method overrides the default banner generating method
149
+ def get_banner
150
+ return "Usage: #@command_name -C CLUSTER_NAME -a|-n NODE_NAME"
151
+ end
152
+
153
+ protected
154
+ # This method overrides the default behaviour.
155
+ # @raise [Common::MissingParameter] Never raise exception for the moment :)
156
+ def check_mandatory()
157
+ raise Common::MissingParameter.new("-C", get_help()) if !@values["help"] && @values["cluster_name"].nil?
158
+ raise Common::MissingParameter.new("-n or -a", get_help()) if !@values["help"] && @values["list_nodes"].nil? && !@values["all"] && !@values["cluster_name"].nil?
159
+ raise Common::InconsistentParameter.new("can not be used together.", get_help(), "-a", "-n") if !@values["help"] && @values["all"] && !@values["list_nodes"].nil?
160
+ end
161
+ end
162
+ end
163
+ end