step6_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. isAddHostWizard: function(){
  35. return this.get('content.controllerName') === 'addHostController';
  36. }.property('content.controllerName'),
  37. isAllDataNodes: function () {
  38. return this.get('hosts').everyProperty('isDataNode', true);
  39. }.property('hosts.@each.isDataNode'),
  40. isAllTaskTrackers: function () {
  41. return this.get('hosts').everyProperty('isTaskTracker', true);
  42. }.property('hosts.@each.isTaskTracker'),
  43. isAllRegionServers: function () {
  44. return this.get('hosts').everyProperty('isRegionServer', true);
  45. }.property('hosts.@each.isRegionServer'),
  46. isAllClients: function () {
  47. return this.get('hosts').everyProperty('isClient', true);
  48. }.property('hosts.@each.isClient'),
  49. isNoDataNodes: function () {
  50. return this.get('hosts').everyProperty('isDataNode', false);
  51. }.property('hosts.@each.isDataNode'),
  52. isNoTaskTrackers: function () {
  53. return this.get('hosts').everyProperty('isTaskTracker', false);
  54. }.property('hosts.@each.isTaskTracker'),
  55. isNoRegionServers: function () {
  56. return this.get('hosts').everyProperty('isRegionServer', false);
  57. }.property('hosts.@each.isRegionServer'),
  58. isNoClients: function () {
  59. return this.get('hosts').everyProperty('isClient', false);
  60. }.property('hosts.@each.isClient'),
  61. /**
  62. * Return whether Hbase service was selected or not.
  63. * Calculate this information on <code>content.services</code> variable
  64. * @return Boolean
  65. */
  66. isHbSelected: function () {
  67. return this.get('content.services').findProperty('serviceName', 'HBASE').get('isSelected');
  68. }.property('content.services'),
  69. /**
  70. * Return whether MapReduce service was selected or not.
  71. * Calculate this information on <code>content.services</code> variable
  72. * @return Boolean
  73. */
  74. isMrSelected: function () {
  75. return this.get('content.services').findProperty('serviceName', 'MAPREDUCE').get('isSelected');
  76. }.property('content.services'),
  77. clearError: function () {
  78. var isError = false;
  79. var hosts = this.get('hosts');
  80. if (this.get('isNoDataNodes') === false &&
  81. (this.get('isNoTaskTrackers') === false || this.get('isMrSelected') === false) &&
  82. (this.get('isNoRegionServers') === false || this.get('isHbSelected') === false) &&
  83. this.get('isNoClients') === false) {
  84. this.set('errorMessage', '');
  85. }
  86. if(this.get('isAddHostWizard')){
  87. for(var i = 0; i < hosts.length; i++){
  88. isError = !(hosts[i].get('isDataNode') || hosts[i].get('isClient')
  89. || ( this.get('isMrSelected') && hosts[i].get('isTaskTracker'))
  90. || ( this.get('isHbSelected') && hosts[i].get('isRegionServer')));
  91. if (isError) {
  92. break;
  93. } else {
  94. this.set('errorMessage', '');
  95. }
  96. }
  97. }
  98. }.observes('isNoDataNodes', 'isNoTaskTrackers', 'isNoRegionServers', 'isNoClients'),
  99. /**
  100. * Check whether current host is currently selected as master
  101. * @param hostName
  102. * @return {Boolean}
  103. */
  104. hasMasterComponents: function (hostName) {
  105. return this.get('content.masterComponentHosts').someProperty('hostName', hostName);
  106. },
  107. selectAllDataNodes: function () {
  108. var forFilter = this.get('hosts').filterProperty('isDataNodeInstalled', false);
  109. forFilter.setEach('isDataNode', true);
  110. },
  111. selectAllTaskTrackers: function () {
  112. var forFilter = this.get('hosts').filterProperty('isTaskTrackerInstalled', false);
  113. forFilter.setEach('isTaskTracker', true);
  114. },
  115. selectAllRegionServers: function () {
  116. var forFilter = this.get('hosts').filterProperty('isRegionServerInstalled', false);
  117. forFilter.setEach('isRegionServer', true);
  118. },
  119. selectAllClients: function () {
  120. var forFilter = this.get('hosts').filterProperty('isClientInstalled', false);
  121. forFilter.setEach('isClient', true);
  122. },
  123. deselectAllDataNodes: function () {
  124. var forFilter = this.get('hosts').filterProperty('isDataNodeInstalled', false);
  125. forFilter.setEach('isDataNode', false);
  126. },
  127. deselectAllTaskTrackers: function () {
  128. var forFilter = this.get('hosts').filterProperty('isTaskTrackerInstalled', false);
  129. forFilter.setEach('isTaskTracker', false);
  130. },
  131. deselectAllRegionServers: function () {
  132. var forFilter = this.get('hosts').filterProperty('isRegionServerInstalled', false);
  133. forFilter.setEach('isRegionServer', false);
  134. },
  135. deselectAllClients: function () {
  136. var forFilter = this.get('hosts').filterProperty('isClientInstalled', false);
  137. forFilter.setEach('isClient', false);
  138. },
  139. clearStep: function () {
  140. this.set('hosts', []);
  141. this.clearError();
  142. },
  143. loadStep: function () {
  144. console.log("WizardStep6Controller: Loading step6: Assign Slaves");
  145. this.clearStep();
  146. this.renderSlaveHosts();
  147. if(this.get('content.missSlavesStep')){
  148. App.router.send('next');
  149. }
  150. },
  151. /**
  152. * Get active host names
  153. * @return {Array}
  154. */
  155. getHostNames: function () {
  156. var hostInfo = this.get('content.hosts');
  157. var hostNames = [];
  158. for (var index in hostInfo) {
  159. if (hostInfo[index].bootStatus === 'REGISTERED') {
  160. hostNames.push(hostInfo[index].name);
  161. }
  162. }
  163. return hostNames;
  164. },
  165. /**
  166. * Load all data needed for this module. Then it automatically renders in template
  167. * @return {Ember.Set}
  168. */
  169. renderSlaveHosts: function () {
  170. var hostsObj = Em.Set.create();
  171. var allHosts = this.getHostNames();
  172. // TODO - Hard coding should be removed.
  173. var maxNoofHostComponents = 11;
  174. var slaveComponents = this.get('content.slaveComponentHosts');
  175. allHosts.forEach(function (_hostName) {
  176. hostsObj.push(Em.Object.create({
  177. hostName: _hostName,
  178. isMaster: false,
  179. isDataNode: false,
  180. isTaskTracker: false,
  181. isRegionServer: false,
  182. isClient: false,
  183. isDataNodeInstalled: false,
  184. isTaskTrackerInstalled: false,
  185. isRegionServerInstalled: false,
  186. isClientInstalled: false
  187. }));
  188. });
  189. if (!slaveComponents) { // we are at this page for the first time
  190. if (allHosts.length > 3) { //multiple nodes scenario
  191. hostsObj.forEach(function (host) {
  192. host.isMaster = this.hasMasterComponents(host.hostName);
  193. host.isDataNode = host.isTaskTracker
  194. = host.isRegionServer = !host.isMaster;
  195. }, this);
  196. if (hostsObj.someProperty('isDataNode', true)) {
  197. hostsObj.findProperty('isDataNode', true).set('isClient', true);
  198. }
  199. } else {
  200. var masterObj = {
  201. host: null,
  202. masterComponents: maxNoofHostComponents
  203. };
  204. hostsObj.forEach(function (host) {
  205. host.isMaster = this.hasMasterComponents(host.hostName);
  206. var countMasterComp = this.getMasterComponentsForHost(host.hostName).length;
  207. if (countMasterComp <= masterObj.masterComponents) {
  208. masterObj.masterComponents = countMasterComp;
  209. masterObj.host = host;
  210. }
  211. }, this);
  212. masterObj.host.set('isClient', true);
  213. masterObj.host.set('isDataNode', true);
  214. masterObj.host.set('isTaskTracker', true);
  215. masterObj.host.set('isRegionServer', true);
  216. }
  217. } else {
  218. var dataNodes = slaveComponents.findProperty('componentName', 'DATANODE');
  219. dataNodes.hosts.forEach(function (_dataNode) {
  220. var dataNode = hostsObj.findProperty('hostName', _dataNode.hostName);
  221. if (dataNode) {
  222. dataNode.set('isDataNode', true);
  223. dataNode.set('isDataNodeInstalled', _dataNode.isInstalled);
  224. }
  225. });
  226. if (this.get('isMrSelected')) {
  227. var taskTrackers = slaveComponents.findProperty('componentName', 'TASKTRACKER');
  228. taskTrackers.hosts.forEach(function (_taskTracker) {
  229. var taskTracker = hostsObj.findProperty('hostName', _taskTracker.hostName);
  230. if (taskTracker) {
  231. taskTracker.set('isTaskTracker', true);
  232. taskTracker.set('isTaskTrackerInstalled', _taskTracker.isInstalled);
  233. }
  234. });
  235. }
  236. if (this.get('isHbSelected')) {
  237. var regionServers = slaveComponents.findProperty('componentName', 'HBASE_REGIONSERVER');
  238. regionServers.hosts.forEach(function (_regionServer) {
  239. var regionServer = hostsObj.findProperty('hostName', _regionServer.hostName);
  240. if (regionServer) {
  241. regionServer.set('isRegionServer', true);
  242. regionServer.set('isRegionServerInstalled', _regionServer.isInstalled);
  243. }
  244. });
  245. }
  246. var clients = slaveComponents.findProperty('componentName', 'CLIENT');
  247. clients.hosts.forEach(function (_client) {
  248. var client = hostsObj.findProperty('hostName', _client.hostName);
  249. if (client) {
  250. client.set('isClient', true);
  251. client.set('isClientInstalled', _client.isInstalled);
  252. }
  253. }, this);
  254. allHosts.forEach(function (_hostname) {
  255. var host = hostsObj.findProperty('hostName', _hostname);
  256. if (host) {
  257. host.set('isMaster', this.hasMasterComponents(_hostname));
  258. }
  259. }, this);
  260. }
  261. hostsObj.forEach(function (host) {
  262. this.get('hosts').pushObject(host);
  263. }, this);
  264. },
  265. /**
  266. * Return list of master components for specified <code>hostname</code>
  267. * @param hostName
  268. * @return {*}
  269. */
  270. getMasterComponentsForHost: function (hostName) {
  271. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  272. },
  273. /**
  274. * Validate form. Return do we have errors or not
  275. * @return {Boolean}
  276. */
  277. validate: function () {
  278. var isError = false;
  279. var hosts = this.get('hosts');
  280. if(this.get('isAddHostWizard')){
  281. for(var i = 0; i < hosts.length; i++){
  282. isError = !(hosts[i].get('isDataNode') || hosts[i].get('isClient')
  283. || ( this.get('isMrSelected') && hosts[i].get('isTaskTracker'))
  284. || ( this.get('isHbSelected') && hosts[i].get('isRegionServer')));
  285. if (isError) {
  286. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOneForHost'));
  287. break;
  288. }
  289. }
  290. } else {
  291. isError = this.get('isNoDataNodes') || this.get('isNoClients')
  292. || ( this.get('isMrSelected') && this.get('isNoTaskTrackers'))
  293. || ( this.get('isHbSelected') && this.get('isNoRegionServers'));
  294. if (isError) {
  295. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  296. }
  297. }
  298. return !isError;
  299. }
  300. });