step6_controller.js 15 KB

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