step6_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. isInstallerWizard: function () {
  45. return this.get('content.controllerName') === 'installerController';
  46. }.property('content.controllerName'),
  47. clearError: function () {
  48. var self = this;
  49. var isError = false;
  50. var err = true;
  51. var hosts = this.get('hosts');
  52. var headers = this.get('headers');
  53. headers.forEach(function (header) {
  54. var all_false = true;
  55. hosts.forEach(function (host) {
  56. var checkboxes = host.get('checkboxes');
  57. all_false &= !checkboxes.findProperty('title', header.get('label')).checked;
  58. });
  59. err &= all_false;
  60. });
  61. if (!err) {
  62. this.set('errorMessage', '');
  63. }
  64. if (this.get('isAddHostWizard')) {
  65. if (this.get('isMasters')) {
  66. this.set('errorMessage', '');
  67. }
  68. else {
  69. hosts.forEach(function (host) {
  70. isError = false;
  71. headers.forEach(function (header) {
  72. isError |= host.get('checkboxes').findProperty('title', header.get('label')).checked;
  73. });
  74. isError = !isError;
  75. if (isError) {
  76. return;
  77. }
  78. else {
  79. self.set('errorMessage', '');
  80. }
  81. });
  82. }
  83. }
  84. },
  85. /**
  86. * Check whether current host is currently selected as master
  87. * @param hostName
  88. * @return {Boolean}
  89. */
  90. hasMasterComponents: function (hostName) {
  91. return this.get('content.masterComponentHosts').someProperty('hostName', hostName);
  92. },
  93. clearStep: function () {
  94. this.set('hosts', []);
  95. this.set('headers', []);
  96. this.clearError();
  97. },
  98. /**
  99. * Enable some service for all hosts
  100. * @param event
  101. */
  102. selectAllNodes: function (event) {
  103. this.setAllNodes(event.context.label, true);
  104. },
  105. /**
  106. * Disable some services for all hosts
  107. * @param event
  108. */
  109. deselectAllNodes: function (event) {
  110. this.setAllNodes(event.context.label, false);
  111. },
  112. /**
  113. * Enable/disable some service for all hosts
  114. * @param {String} label - service name
  115. * @param {Boolean} checked - true - enable, false - disable
  116. */
  117. setAllNodes: function (label, checked) {
  118. this.get('hosts').forEach(function (host) {
  119. host.get('checkboxes').forEach(function (checkbox) {
  120. if (checkbox.get('title') === label) {
  121. checkbox.set('checked', checked);
  122. }
  123. });
  124. });
  125. },
  126. /**
  127. * Return whether service was selected or not
  128. * @param name serviceName
  129. * @return {*}
  130. */
  131. isServiceSelected: function (name) {
  132. return this.get('content.services').findProperty('serviceName', name) &&
  133. this.get('content.services').findProperty('serviceName', name).get('isSelected');
  134. },
  135. /**
  136. * Checkbox check callback
  137. * @param {String} title
  138. */
  139. checkCallback: function (title) {
  140. var header = this.get('headers').findProperty('label', title);
  141. var hosts = this.get('hosts');
  142. var allTrue = true;
  143. var allFalse = true;
  144. hosts.forEach(function (host) {
  145. host.get('checkboxes').forEach(function (cb) {
  146. if (cb.get('title') === title) {
  147. allTrue &= cb.get('checked');
  148. allFalse &= !cb.get('checked');
  149. }
  150. });
  151. });
  152. header.set('allChecked', allTrue);
  153. header.set('noChecked', allFalse);
  154. this.clearError();
  155. },
  156. getComponentDisplayName: function (componentName) {
  157. return this.get('components').findProperty('component_name', componentName).display_name
  158. },
  159. loadStep: function () {
  160. var self = this;
  161. console.log("WizardStep6Controller: Loading step6: Assign Slaves");
  162. this.clearStep();
  163. var headers = [];
  164. if (this.get('isMasters')) {
  165. if (this.isServiceSelected('HBASE') && App.supports.multipleHBaseMasters) {
  166. headers.pushObject(Em.Object.create({
  167. name: 'HBASE_MASTER',
  168. label: self.getComponentDisplayName('HBASE_MASTER')
  169. }));
  170. }
  171. if (this.isServiceSelected('ZOOKEEPER')) {
  172. headers.pushObject(Em.Object.create({
  173. name: 'ZOOKEEPER_SERVER',
  174. label: self.getComponentDisplayName('ZOOKEEPER_SERVER')
  175. }));
  176. }
  177. }
  178. else {
  179. headers.pushObject(Ember.Object.create({
  180. name: 'DATANODE',
  181. label: self.getComponentDisplayName('DATANODE')
  182. }));
  183. if (this.isServiceSelected('MAPREDUCE')) {
  184. headers.pushObject(Em.Object.create({
  185. name: 'TASKTRACKER',
  186. label: self.getComponentDisplayName('TASKTRACKER')
  187. }));
  188. }
  189. if (this.isServiceSelected('YARN')) {
  190. headers.pushObject(Em.Object.create({
  191. name: 'NODEMANAGER',
  192. label: self.getComponentDisplayName('NODEMANAGER')
  193. }));
  194. }
  195. if (this.isServiceSelected('HBASE')) {
  196. headers.pushObject(Em.Object.create({
  197. name: 'HBASE_REGIONSERVER',
  198. label: self.getComponentDisplayName('HBASE_REGIONSERVER')
  199. }));
  200. }
  201. headers.pushObject(Ember.Object.create({
  202. name: 'CLIENT',
  203. label: self.getComponentDisplayName('CLIENT')
  204. }));
  205. }
  206. headers.forEach(function (header) {
  207. header.setProperties({ allChecked: false, noChecked: true });
  208. });
  209. this.get('headers').pushObjects(headers);
  210. this.render();
  211. if (this.get('isMasters')) {
  212. if (this.get('content.skipMasterStep')) {
  213. App.router.send('next');
  214. }
  215. }
  216. else {
  217. if (this.get('content.skipSlavesStep')) {
  218. App.router.send('next');
  219. }
  220. }
  221. },
  222. /**
  223. * Get active host names
  224. * @return {Array}
  225. */
  226. getHostNames: function () {
  227. var hostInfo = this.get('content.hosts');
  228. var hostNames = [];
  229. for (var index in hostInfo) {
  230. if (hostInfo[index].bootStatus === 'REGISTERED') {
  231. hostNames.push(hostInfo[index].name);
  232. }
  233. }
  234. return hostNames;
  235. },
  236. /**
  237. * Load all data needed for this module. Then it automatically renders in template
  238. */
  239. render: function () {
  240. var hostsObj = Em.Set.create();
  241. var allHosts = this.getHostNames();
  242. var self = this;
  243. allHosts.forEach(function (_hostName) {
  244. var obj = Em.Object.create({
  245. hostName: _hostName,
  246. isMaster: false,
  247. checkboxes: []
  248. });
  249. self.get('headers').forEach(function (header) {
  250. obj.checkboxes.pushObject(Em.Object.create({
  251. title: header.label,
  252. checked: false,
  253. isInstalled: false
  254. }));
  255. });
  256. hostsObj.push(obj);
  257. });
  258. if (this.get('isMasters')) {
  259. hostsObj = this.renderMasters(hostsObj);
  260. }
  261. else {
  262. hostsObj = this.renderSlaves(hostsObj);
  263. }
  264. hostsObj.forEach(function (host) {
  265. this.get('hosts').pushObject(host);
  266. }, this);
  267. this.get('headers').forEach(function (header) {
  268. self.checkCallback(header.get('label'));
  269. });
  270. },
  271. /**
  272. *
  273. * @param hostsObj
  274. * @return {*}
  275. */
  276. renderSlaves: function (hostsObj) {
  277. var self = this;
  278. var allHosts = this.getHostNames();
  279. var headers = this.get('headers');
  280. var slaveComponents = this.get('content.slaveComponentHosts');
  281. if (!slaveComponents) { // we are at this page for the first time
  282. var client_is_set = false;
  283. hostsObj.forEach(function (host) {
  284. host.isMaster = self.hasMasterComponents(host.hostName);
  285. var checkboxes = host.get('checkboxes');
  286. checkboxes.setEach('checked', !host.isMaster);
  287. checkboxes.setEach('isInstalled', false);
  288. checkboxes.findProperty('title', headers.findProperty('name', 'CLIENT').get('label')).set('checked', false);
  289. // First not Master should have Client (only first!)
  290. if (!client_is_set) {
  291. var checkboxDatanode = checkboxes.findProperty('title', headers.findProperty('name', 'DATANODE').get('label'));
  292. if (checkboxDatanode && checkboxDatanode.get('checked')) {
  293. checkboxes.findProperty('title', headers.findProperty('name', 'CLIENT').get('label')).set('checked', true);
  294. client_is_set = true;
  295. }
  296. }
  297. });
  298. if (this.get('isInstallerWizard') && hostsObj.everyProperty('isMaster', true)) {
  299. var lastHost = hostsObj[hostsObj.length - 1];
  300. lastHost.get('checkboxes').setEach('checked', true);
  301. }
  302. }
  303. else {
  304. this.get('headers').forEach(function (header) {
  305. var nodes = slaveComponents.findProperty('componentName', header.get('name'));
  306. if (nodes) {
  307. nodes.hosts.forEach(function (_node) {
  308. var node = hostsObj.findProperty('hostName', _node.hostName);
  309. if (node) {
  310. node.get('checkboxes').findProperty('title', header.get('label')).set('checked', true);
  311. node.get('checkboxes').findProperty('title', header.get('label')).set('isInstalled', _node.isInstalled);
  312. }
  313. });
  314. }
  315. });
  316. allHosts.forEach(function (_hostname) {
  317. var host = hostsObj.findProperty('hostName', _hostname);
  318. if (host) {
  319. host.set('isMaster', this.hasMasterComponents(_hostname));
  320. }
  321. }, this);
  322. }
  323. return hostsObj;
  324. },
  325. /**
  326. *
  327. * @param hostsObj
  328. * @return {*}
  329. */
  330. renderMasters: function (hostsObj) {
  331. var self = this;
  332. var masterComponentHosts = this.get('content.masterComponentHosts');
  333. console.warn('masterComponentHosts', masterComponentHosts);
  334. if (masterComponentHosts) {
  335. masterComponentHosts.forEach(function (item) {
  336. var host = hostsObj.findProperty('hostName', item.hostName);
  337. if (host) {
  338. var checkbox = host.get('checkboxes').findProperty('title', item.display_name);
  339. if (checkbox) {
  340. checkbox.set('checked', true);
  341. }
  342. }
  343. });
  344. }
  345. return hostsObj;
  346. },
  347. /**
  348. * Return list of master components for specified <code>hostname</code>
  349. * @param hostName
  350. * @return {*}
  351. */
  352. getMasterComponentsForHost: function (hostName) {
  353. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  354. },
  355. /**
  356. * Validate form. Return do we have errors or not
  357. * @return {Boolean}
  358. */
  359. validate: function () {
  360. if (this.get('isAddHostWizard')) {
  361. return this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForHost'));
  362. }
  363. else if (this.get('isInstallerWizard')) {
  364. //this.validateEachComponent() ? this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForHost') ? return true : return false : return false;
  365. return this.validateEachComponent() && this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForSlaveHost'));
  366. }
  367. },
  368. /**
  369. * Validate all components for each host. Return do we have errors or not
  370. * @return {Boolean}
  371. */
  372. validateEachHost: function (errorMsg) {
  373. var isError = false;
  374. var hosts = this.get('hosts');
  375. var headers = this.get('headers');
  376. for (var i = 0; i < hosts.length; i++) {
  377. if (this.get('isInstallerWizard') && this.get('content.masterComponentHosts').someProperty('hostName', hosts[i].hostName)) {
  378. continue;
  379. }
  380. var checkboxes = hosts[i].get('checkboxes');
  381. isError = false;
  382. headers.forEach(function (header) {
  383. isError |= checkboxes.findProperty('title', header.get('label')).checked;
  384. });
  385. isError = !isError;
  386. if (isError) {
  387. this.set('errorMessage', errorMsg);
  388. break;
  389. }
  390. }
  391. return !isError;
  392. },
  393. /**
  394. * Validate a component for all hosts. Return do we have errors or not
  395. * @return {Boolean}
  396. */
  397. validateEachComponent: function () {
  398. var isError = false;
  399. var hosts = this.get('hosts');
  400. var headers = this.get('headers');
  401. headers.forEach(function (header) {
  402. var all_false = true;
  403. hosts.forEach(function (host) {
  404. var checkboxes = host.get('checkboxes');
  405. all_false = all_false && !checkboxes.findProperty('title', header.get('label')).checked;
  406. });
  407. isError = isError || all_false;
  408. });
  409. if (isError) {
  410. this.set('errorMessage', Em.I18n.t('installer.step6.error.mustSelectOne'));
  411. }
  412. return !isError;
  413. }
  414. })
  415. ;