step6_controller.js 12 KB

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