step6_controller.js 14 KB

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