step6_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var db = require('utils/db');
  20. /**
  21. * By Step 6, we have the following information stored in App.db and set on this
  22. * controller by the router:
  23. *
  24. * hosts: App.db.hosts (list of all hosts the user selected in Step 3)
  25. * selectedServiceNames: App.db.selectedServiceNames (the services that the user selected in Step 4)
  26. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  27. *
  28. * Step 6 will set the following information in App.db:
  29. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  30. *
  31. */
  32. App.WizardStep6Controller = Em.Controller.extend({
  33. hosts: [],
  34. headers: [],
  35. /**
  36. * true - assign ZK, HB
  37. * false - slaves and clients
  38. */
  39. isMasters: false,
  40. components:require('data/service_components'),
  41. isAddHostWizard: function(){
  42. return this.get('content.controllerName') === 'addHostController';
  43. }.property('content.controllerName'),
  44. clearError: function () {
  45. var self = this;
  46. var isError = false;
  47. var err = true;
  48. var hosts = this.get('hosts');
  49. var headers = this.get('headers');
  50. headers.forEach(function(header) {
  51. var all_false = true;
  52. hosts.forEach(function(host) {
  53. var checkboxes = host.get('checkboxes');
  54. all_false &= !checkboxes.findProperty('title', header.get('label')).checked;
  55. });
  56. err &= all_false;
  57. });
  58. if (!err) {
  59. this.set('errorMessage', '');
  60. }
  61. if(this.get('isAddHostWizard')) {
  62. if (this.get('isMasters')) {
  63. this.set('errorMessage', '');
  64. }
  65. else {
  66. hosts.forEach(function(host) {
  67. isError = false;
  68. headers.forEach(function(header) {
  69. isError |= host.get('checkboxes').findProperty('title', header.get('label')).checked;
  70. });
  71. isError = !isError;
  72. if (isError) {
  73. return;
  74. }
  75. else {
  76. self.set('errorMessage', '');
  77. }
  78. });
  79. }
  80. }
  81. },
  82. /**
  83. * Check whether current host is currently selected as master
  84. * @param hostName
  85. * @return {Boolean}
  86. */
  87. hasMasterComponents: function (hostName) {
  88. return this.get('content.masterComponentHosts').someProperty('hostName', hostName);
  89. },
  90. clearStep: function () {
  91. this.set('hosts', []);
  92. this.set('headers', []);
  93. this.clearError();
  94. },
  95. /**
  96. * Enable some service for all hosts
  97. * @param event
  98. */
  99. selectAllNodes: function(event) {
  100. this.setAllNodes(event.context.label, true);
  101. },
  102. /**
  103. * Disable some services for all hosts
  104. * @param event
  105. */
  106. deselectAllNodes: function(event) {
  107. this.setAllNodes(event.context.label, false);
  108. },
  109. /**
  110. * Enable/disable some service for all hosts
  111. * @param {String} label - service name
  112. * @param {Boolean} checked - true - enable, false - disable
  113. */
  114. setAllNodes: function(label, checked) {
  115. this.get('hosts').forEach(function(host) {
  116. host.get('checkboxes').forEach(function(checkbox) {
  117. if (checkbox.get('title') === label) {
  118. checkbox.set('checked', checked);
  119. }
  120. });
  121. });
  122. },
  123. /**
  124. * Return whether service was selected or not
  125. * @param name serviceName
  126. * @return {*}
  127. */
  128. isServiceSelected: function(name) {
  129. return this.get('content.services').findProperty('serviceName', name).get('isSelected');
  130. },
  131. /**
  132. * Checkbox check callback
  133. * @param {String} title
  134. */
  135. checkCallback: function(title) {
  136. var header = this.get('headers').findProperty('label', title);
  137. var hosts = this.get('hosts');
  138. var allTrue = true;
  139. var allFalse = true;
  140. hosts.forEach(function(host) {
  141. host.get('checkboxes').forEach(function(cb) {
  142. if (cb.get('title') === title) {
  143. allTrue &= cb.get('checked');
  144. allFalse &= !cb.get('checked');
  145. }
  146. });
  147. });
  148. header.set('allChecked', allTrue);
  149. header.set('noChecked', allFalse);
  150. this.clearError();
  151. },
  152. getComponentDisplayName: function(componentName) {
  153. return this.get('components').findProperty('component_name', componentName).display_name
  154. },
  155. loadStep: function () {
  156. var self = this;
  157. console.log("WizardStep6Controller: Loading step6: Assign Slaves");
  158. this.clearStep();
  159. var headers = [];
  160. if (this.get('isMasters')) {
  161. if (this.isServiceSelected('HBASE')) {
  162. headers.pushObject(Em.Object.create({
  163. name: 'HBASE_MASTER',
  164. label: self.getComponentDisplayName('HBASE_MASTER')
  165. }));
  166. }
  167. if (this.isServiceSelected('ZOOKEEPER')) {
  168. headers.pushObject(Em.Object.create({
  169. name:'ZOOKEEPER_SERVER',
  170. label: self.getComponentDisplayName('ZOOKEEPER_SERVER')
  171. }));
  172. }
  173. }
  174. else {
  175. headers.pushObject(Ember.Object.create({
  176. name: 'DATANODE',
  177. label: self.getComponentDisplayName('DATANODE')
  178. }));
  179. if (this.isServiceSelected('MAPREDUCE')) {
  180. headers.pushObject(Em.Object.create({
  181. name:'TASKTRACKER',
  182. label: self.getComponentDisplayName('TASKTRACKER')
  183. }));
  184. }
  185. if (this.isServiceSelected('HBASE')) {
  186. headers.pushObject(Em.Object.create({
  187. name:'HBASE_REGIONSERVER',
  188. label: self.getComponentDisplayName('HBASE_REGIONSERVER')
  189. }));
  190. }
  191. headers.pushObject(Ember.Object.create({
  192. name: 'CLIENT',
  193. label: self.getComponentDisplayName('CLIENT')
  194. }));
  195. }
  196. headers.forEach(function(header) {
  197. header.setProperties({ allChecked: false, noChecked: true });
  198. });
  199. this.get('headers').pushObjects(headers);
  200. this.render();
  201. if (this.get('isMasters')) {
  202. if(this.get('content.missMasterStep')) {
  203. App.router.send('next');
  204. }
  205. }
  206. else {
  207. if(this.get('content.missSlavesStep')) {
  208. App.router.send('next');
  209. }
  210. }
  211. },
  212. /**
  213. * Get active host names
  214. * @return {Array}
  215. */
  216. getHostNames: function () {
  217. var hostInfo = this.get('content.hosts');
  218. var hostNames = [];
  219. for (var index in hostInfo) {
  220. if (hostInfo[index].bootStatus === 'REGISTERED') {
  221. hostNames.push(hostInfo[index].name);
  222. }
  223. }
  224. return hostNames;
  225. },
  226. /**
  227. * Load all data needed for this module. Then it automatically renders in template
  228. * @return {Ember.Set}
  229. */
  230. render: function () {
  231. var hostsObj = Em.Set.create();
  232. var allHosts = this.getHostNames();
  233. var self = this;
  234. allHosts.forEach(function (_hostName) {
  235. var obj = Em.Object.create({
  236. hostName: _hostName,
  237. isMaster: false,
  238. checkboxes: []
  239. });
  240. self.get('headers').forEach(function(header) {
  241. obj.checkboxes.pushObject(Em.Object.create({
  242. title: header.label,
  243. checked: false,
  244. installed: false
  245. }));
  246. });
  247. hostsObj.push(obj);
  248. });
  249. if (this.get('isMasters')) {
  250. hostsObj = this.renderMasters(hostsObj);
  251. }
  252. else {
  253. hostsObj = this.renderSlaves(hostsObj);
  254. }
  255. hostsObj.forEach(function (host) {
  256. this.get('hosts').pushObject(host);
  257. }, this);
  258. this.get('headers').forEach(function(header) {
  259. self.checkCallback(header.get('label'));
  260. });
  261. },
  262. /**
  263. *
  264. * @param hostsObj
  265. * @return {*}
  266. */
  267. renderSlaves: function(hostsObj) {
  268. var allHosts = this.getHostNames();
  269. var slaveComponents = this.get('content.slaveComponentHosts');
  270. if (!slaveComponents) { // we are at this page for the first time
  271. hostsObj.forEach(function(host) {
  272. host.isMaster = this.hasMasterComponents(host.hostName);
  273. }, this);
  274. }
  275. else {
  276. this.get('headers').forEach(function(header) {
  277. var nodes = slaveComponents.findProperty('componentName', header.get('name'));
  278. if (nodes) {
  279. nodes.hosts.forEach(function (_node) {
  280. var node = hostsObj.findProperty('hostName', _node.hostName);
  281. if (node) {
  282. node.get('checkboxes').findProperty('title', header.get('label')).set('checked', true);
  283. node.get('checkboxes').findProperty('title', header.get('label')).set('installed', _node.isInstalled);
  284. }
  285. });
  286. }
  287. });
  288. allHosts.forEach(function (_hostname) {
  289. var host = hostsObj.findProperty('hostName', _hostname);
  290. if (host) {
  291. host.set('isMaster', this.hasMasterComponents(_hostname));
  292. }
  293. }, this);
  294. }
  295. return hostsObj;
  296. },
  297. /**
  298. *
  299. * @param hostsObj
  300. * @return {*}
  301. */
  302. renderMasters: function(hostsObj) {
  303. var self = this;
  304. var masterComponentHosts = this.get('content.masterComponentHosts');
  305. console.warn('masterComponentHosts', masterComponentHosts);
  306. if (masterComponentHosts) {
  307. masterComponentHosts.forEach(function(item) {
  308. var host = hostsObj.findProperty('hostName', item.hostName);
  309. if (host) {
  310. host.get('checkboxes').findProperty('title', item.display_name).set('checked', true);
  311. }
  312. });
  313. }
  314. return hostsObj;
  315. },
  316. /**
  317. * Return list of master components for specified <code>hostname</code>
  318. * @param hostName
  319. * @return {*}
  320. */
  321. getMasterComponentsForHost: function (hostName) {
  322. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  323. },
  324. /**
  325. * Validate form. Return do we have errors or not
  326. * @return {Boolean}
  327. */
  328. validate: function () {
  329. var isError = false;
  330. var hosts = this.get('hosts');
  331. var headers = this.get('headers');
  332. if(this.get('isAddHostWizard')) {
  333. for(var i = 0; i < hosts.length; i++) {
  334. var checkboxes = hosts[i].get('checkboxes');
  335. isError = false;
  336. headers.forEach(function(header) {
  337. isError |= checkboxes.findProperty('title', header.get('label')).checked;
  338. });
  339. isError = !isError;
  340. if (isError) {
  341. this.set('errorMessage', Em.I18n.t('installer.step6.error.mustSelectOneForHost'));
  342. break;
  343. }
  344. }
  345. }
  346. else {
  347. headers.forEach(function(header) {
  348. var all_false = true;
  349. hosts.forEach(function(host) {
  350. var checkboxes = host.get('checkboxes');
  351. all_false = all_false && !checkboxes.findProperty('title', header.get('label')).checked;
  352. });
  353. isError = isError || all_false;
  354. });
  355. if (isError) {
  356. this.set('errorMessage', Em.I18n.t('installer.step6.error.mustSelectOne'));
  357. }
  358. }
  359. return !isError;
  360. }
  361. });