step6_controller.js 12 KB

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