step6_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. if (this.isServiceSelected('HDFS')) {
  180. headers.pushObject(Ember.Object.create({
  181. name: 'DATANODE',
  182. label: self.getComponentDisplayName('DATANODE')
  183. }));
  184. }
  185. if (this.isServiceSelected('MAPREDUCE')) {
  186. headers.pushObject(Em.Object.create({
  187. name: 'TASKTRACKER',
  188. label: self.getComponentDisplayName('TASKTRACKER')
  189. }));
  190. }
  191. if (this.isServiceSelected('YARN')) {
  192. headers.pushObject(Em.Object.create({
  193. name: 'NODEMANAGER',
  194. label: self.getComponentDisplayName('NODEMANAGER')
  195. }));
  196. }
  197. if (this.isServiceSelected('HBASE')) {
  198. headers.pushObject(Em.Object.create({
  199. name: 'HBASE_REGIONSERVER',
  200. label: self.getComponentDisplayName('HBASE_REGIONSERVER')
  201. }));
  202. }
  203. headers.pushObject(Ember.Object.create({
  204. name: 'CLIENT',
  205. label: self.getComponentDisplayName('CLIENT')
  206. }));
  207. }
  208. headers.forEach(function (header) {
  209. header.setProperties({ allChecked: false, noChecked: true });
  210. });
  211. this.get('headers').pushObjects(headers);
  212. this.render();
  213. if (this.get('isMasters')) {
  214. if (this.get('content.skipMasterStep')) {
  215. App.router.send('next');
  216. }
  217. }
  218. else {
  219. if (this.get('content.skipSlavesStep')) {
  220. App.router.send('next');
  221. }
  222. }
  223. },
  224. /**
  225. * Get active host names
  226. * @return {Array}
  227. */
  228. getHostNames: function () {
  229. var hostInfo = this.get('content.hosts');
  230. var hostNames = [];
  231. for (var index in hostInfo) {
  232. if (hostInfo[index].bootStatus === 'REGISTERED') {
  233. hostNames.push(hostInfo[index].name);
  234. }
  235. }
  236. return hostNames;
  237. },
  238. /**
  239. * Load all data needed for this module. Then it automatically renders in template
  240. */
  241. render: function () {
  242. var hostsObj = Em.Set.create();
  243. var allHosts = this.getHostNames();
  244. var self = this;
  245. allHosts.forEach(function (_hostName) {
  246. var obj = Em.Object.create({
  247. hostName: _hostName,
  248. isMaster: false,
  249. checkboxes: []
  250. });
  251. self.get('headers').forEach(function (header) {
  252. obj.checkboxes.pushObject(Em.Object.create({
  253. title: header.label,
  254. checked: false,
  255. isInstalled: false
  256. }));
  257. });
  258. hostsObj.push(obj);
  259. });
  260. if (this.get('isMasters')) {
  261. hostsObj = this.renderMasters(hostsObj);
  262. }
  263. else {
  264. hostsObj = this.renderSlaves(hostsObj);
  265. }
  266. hostsObj.forEach(function (host) {
  267. this.get('hosts').pushObject(host);
  268. }, this);
  269. this.get('headers').forEach(function (header) {
  270. self.checkCallback(header.get('label'));
  271. });
  272. },
  273. /**
  274. *
  275. * @param hostsObj
  276. * @return {*}
  277. */
  278. renderSlaves: function (hostsObj) {
  279. var self = this;
  280. var allHosts = this.getHostNames();
  281. var headers = this.get('headers');
  282. var slaveComponents = this.get('content.slaveComponentHosts');
  283. if (!slaveComponents) { // we are at this page for the first time
  284. var client_is_set = false;
  285. hostsObj.forEach(function (host) {
  286. host.isMaster = self.hasMasterComponents(host.hostName);
  287. var checkboxes = host.get('checkboxes');
  288. checkboxes.setEach('checked', !host.isMaster);
  289. checkboxes.setEach('isInstalled', false);
  290. checkboxes.findProperty('title', headers.findProperty('name', 'CLIENT').get('label')).set('checked', false);
  291. // First not Master should have Client (only first!)
  292. if (!client_is_set) {
  293. if (self.isServiceSelected("HDFS")) {
  294. var checkboxDatanode = checkboxes.findProperty('title', headers.findProperty('name', 'DATANODE').get('label'));
  295. if (checkboxDatanode && checkboxDatanode.get('checked')) {
  296. checkboxes.findProperty('title', headers.findProperty('name', 'CLIENT').get('label')).set('checked', true);
  297. client_is_set = true;
  298. }
  299. }
  300. }
  301. });
  302. if (this.get('isInstallerWizard') && hostsObj.everyProperty('isMaster', true)) {
  303. var lastHost = hostsObj[hostsObj.length - 1];
  304. lastHost.get('checkboxes').setEach('checked', true);
  305. }
  306. }
  307. else {
  308. this.get('headers').forEach(function (header) {
  309. var nodes = slaveComponents.findProperty('componentName', header.get('name'));
  310. if (nodes) {
  311. nodes.hosts.forEach(function (_node) {
  312. var node = hostsObj.findProperty('hostName', _node.hostName);
  313. if (node) {
  314. node.get('checkboxes').findProperty('title', header.get('label')).set('checked', true);
  315. node.get('checkboxes').findProperty('title', header.get('label')).set('isInstalled', _node.isInstalled);
  316. }
  317. });
  318. }
  319. });
  320. allHosts.forEach(function (_hostname) {
  321. var host = hostsObj.findProperty('hostName', _hostname);
  322. if (host) {
  323. host.set('isMaster', this.hasMasterComponents(_hostname));
  324. }
  325. }, this);
  326. }
  327. return hostsObj;
  328. },
  329. /**
  330. *
  331. * @param hostsObj
  332. * @return {*}
  333. */
  334. renderMasters: function (hostsObj) {
  335. var self = this;
  336. var masterComponentHosts = this.get('content.masterComponentHosts');
  337. console.warn('masterComponentHosts', masterComponentHosts);
  338. if (masterComponentHosts) {
  339. masterComponentHosts.forEach(function (item) {
  340. var host = hostsObj.findProperty('hostName', item.hostName);
  341. if (host) {
  342. var checkbox = host.get('checkboxes').findProperty('title', item.display_name);
  343. if (checkbox) {
  344. checkbox.set('checked', true);
  345. }
  346. }
  347. });
  348. }
  349. return hostsObj;
  350. },
  351. /**
  352. * Return list of master components for specified <code>hostname</code>
  353. * @param hostName
  354. * @return {*}
  355. */
  356. getMasterComponentsForHost: function (hostName) {
  357. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  358. },
  359. /**
  360. * Validate form. Return do we have errors or not
  361. * @return {Boolean}
  362. */
  363. validate: function () {
  364. if (this.get('isAddHostWizard')) {
  365. return this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForHost'));
  366. }
  367. else if (this.get('isInstallerWizard')) {
  368. //this.validateEachComponent() ? this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForHost') ? return true : return false : return false;
  369. return this.validateEachComponent() && this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForSlaveHost'));
  370. }
  371. },
  372. /**
  373. * Validate all components for each host. Return do we have errors or not
  374. * @return {Boolean}
  375. */
  376. validateEachHost: function (errorMsg) {
  377. var isError = false;
  378. var hosts = this.get('hosts');
  379. var headers = this.get('headers');
  380. for (var i = 0; i < hosts.length; i++) {
  381. if (this.get('isInstallerWizard') && this.get('content.masterComponentHosts').someProperty('hostName', hosts[i].hostName)) {
  382. continue;
  383. }
  384. var checkboxes = hosts[i].get('checkboxes');
  385. isError = false;
  386. headers.forEach(function (header) {
  387. isError |= checkboxes.findProperty('title', header.get('label')).checked;
  388. });
  389. isError = !isError;
  390. if (isError) {
  391. this.set('errorMessage', errorMsg);
  392. break;
  393. }
  394. }
  395. return !isError;
  396. },
  397. /**
  398. * Validate a component for all hosts. Return do we have errors or not
  399. * @return {Boolean}
  400. */
  401. validateEachComponent: function () {
  402. var isError = false;
  403. var hosts = this.get('hosts');
  404. var headers = this.get('headers');
  405. headers.forEach(function (header) {
  406. var all_false = true;
  407. hosts.forEach(function (host) {
  408. var checkboxes = host.get('checkboxes');
  409. all_false = all_false && !checkboxes.findProperty('title', header.get('label')).checked;
  410. });
  411. isError = isError || all_false;
  412. });
  413. if (isError) {
  414. this.set('errorMessage', Em.I18n.t('installer.step6.error.mustSelectOne'));
  415. }
  416. return !isError;
  417. }
  418. })
  419. ;