step6_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. var maxNoofHostComponents = 11;
  173. var slaveComponents = this.get('content.slaveComponentHosts');
  174. allHosts.forEach(function (_hostName) {
  175. hostsObj.push(Em.Object.create({
  176. hostName: _hostName,
  177. isMaster: false,
  178. isDataNode: false,
  179. isTaskTracker: false,
  180. isRegionServer: false,
  181. isClient: false,
  182. isDataNodeInstalled: false,
  183. isTaskTrackerInstalled: false,
  184. isRegionServerInstalled: false,
  185. isClientInstalled: false
  186. }));
  187. });
  188. if (!slaveComponents) { // we are at this page for the first time
  189. if (allHosts.length > 3) { //multiple nodes scenario
  190. hostsObj.forEach(function (host) {
  191. host.isMaster = this.hasMasterComponents(host.hostName);
  192. host.isDataNode = host.isTaskTracker
  193. = host.isRegionServer = !host.isMaster;
  194. }, this);
  195. if (hostsObj.someProperty('isDataNode', true)) {
  196. hostsObj.findProperty('isDataNode', true).set('isClient', true);
  197. }
  198. } else {
  199. var masterObj = {
  200. host: null,
  201. masterComponents: maxNoofHostComponents
  202. };
  203. hostsObj.forEach(function (host) {
  204. host.isMaster = this.hasMasterComponents(host.hostName);
  205. var countMasterComp = this.getMasterComponentsForHost(host.hostName).length;
  206. if (countMasterComp <= masterObj.masterComponents) {
  207. masterObj.masterComponents = countMasterComp;
  208. masterObj.host = host;
  209. }
  210. }, this);
  211. masterObj.host.set('isClient', true);
  212. masterObj.host.set('isDataNode', true);
  213. masterObj.host.set('isTaskTracker', true);
  214. masterObj.host.set('isRegionServer', true);
  215. }
  216. } else {
  217. var dataNodes = slaveComponents.findProperty('componentName', 'DATANODE');
  218. dataNodes.hosts.forEach(function (_dataNode) {
  219. var dataNode = hostsObj.findProperty('hostName', _dataNode.hostName);
  220. if (dataNode) {
  221. dataNode.set('isDataNode', true);
  222. dataNode.set('isDataNodeInstalled', _dataNode.isInstalled);
  223. }
  224. });
  225. if (this.get('isMrSelected')) {
  226. var taskTrackers = slaveComponents.findProperty('componentName', 'TASKTRACKER');
  227. taskTrackers.hosts.forEach(function (_taskTracker) {
  228. var taskTracker = hostsObj.findProperty('hostName', _taskTracker.hostName);
  229. if (taskTracker) {
  230. taskTracker.set('isTaskTracker', true);
  231. taskTracker.set('isTaskTrackerInstalled', _taskTracker.isInstalled);
  232. }
  233. });
  234. }
  235. if (this.get('isHbSelected')) {
  236. var regionServers = slaveComponents.findProperty('componentName', 'HBASE_REGIONSERVER');
  237. regionServers.hosts.forEach(function (_regionServer) {
  238. var regionServer = hostsObj.findProperty('hostName', _regionServer.hostName);
  239. if (regionServer) {
  240. regionServer.set('isRegionServer', true);
  241. regionServer.set('isRegionServerInstalled', _regionServer.isInstalled);
  242. }
  243. });
  244. }
  245. var clients = slaveComponents.findProperty('componentName', 'CLIENT');
  246. clients.hosts.forEach(function (_client) {
  247. var client = hostsObj.findProperty('hostName', _client.hostName);
  248. if (client) {
  249. client.set('isClient', true);
  250. client.set('isClientInstalled', _client.isInstalled);
  251. }
  252. }, this);
  253. allHosts.forEach(function (_hostname) {
  254. var host = hostsObj.findProperty('hostName', _hostname);
  255. if (host) {
  256. host.set('isMaster', this.hasMasterComponents(_hostname));
  257. }
  258. }, this);
  259. }
  260. hostsObj.forEach(function (host) {
  261. this.get('hosts').pushObject(host);
  262. }, this);
  263. },
  264. /**
  265. * Return list of master components for specified <code>hostname</code>
  266. * @param hostName
  267. * @return {*}
  268. */
  269. getMasterComponentsForHost: function (hostName) {
  270. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  271. },
  272. /**
  273. * Validate form. Return do we have errors or not
  274. * @return {Boolean}
  275. */
  276. validate: function () {
  277. var isError = false;
  278. var hosts = this.get('hosts');
  279. if(this.get('isAddHostWizard')){
  280. for(var i = 0; i < hosts.length; i++){
  281. isError = !(hosts[i].get('isDataNode') || hosts[i].get('isClient')
  282. || ( this.get('isMrSelected') && hosts[i].get('isTaskTracker'))
  283. || ( this.get('isHbSelected') && hosts[i].get('isRegionServer')));
  284. if (isError) {
  285. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOneForHost'));
  286. break;
  287. }
  288. }
  289. } else {
  290. isError = this.get('isNoDataNodes') || this.get('isNoClients')
  291. || ( this.get('isMrSelected') && this.get('isNoTaskTrackers'))
  292. || ( this.get('isHbSelected') && this.get('isNoRegionServers'));
  293. if (isError) {
  294. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  295. }
  296. }
  297. return !isError;
  298. }
  299. });