step6_controller.js 15 KB

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