step6_controller.js 15 KB

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