step6_controller.js 11 KB

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