step6_controller.js 15 KB

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