step6_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. },
  131. /**
  132. * Get active host names
  133. * @return {Array}
  134. */
  135. getHostNames: function () {
  136. var hostInfo = this.get('content.hostsInfo');
  137. var hostNames = [];
  138. for (var index in hostInfo) {
  139. if (hostInfo[index].bootStatus === 'success' || true) //TODO: remove true after integration with bootstrap
  140. hostNames.push(hostInfo[index].name);
  141. }
  142. return hostNames;
  143. },
  144. /**
  145. * Load all data needed for this module. Then it automatically renders in template
  146. * @return {Ember.Set}
  147. */
  148. renderSlaveHosts: function () {
  149. var hostsObj = Em.Set.create();
  150. var allHosts = this.getHostNames();
  151. var maxNoofHostComponents = 9;
  152. var slaveComponents = this.get('content.slaveComponentHosts');
  153. allHosts.forEach(function (_hostName) {
  154. hostsObj.push(Em.Object.create({
  155. hostName: _hostName,
  156. isMaster: false,
  157. isDataNode: false,
  158. isTaskTracker: false,
  159. isRegionServer: false,
  160. isClient: false,
  161. isDataNodeInstalled: false,
  162. isTaskTrackerInstalled: false,
  163. isRegionServerInstalled: false,
  164. isClientInstalled: false
  165. }));
  166. });
  167. if (!slaveComponents) { // we are at this page for the first time
  168. if (allHosts.length > 3) { //multiple nodes scenario
  169. hostsObj.forEach(function (host) {
  170. host.isMaster = this.hasMasterComponents(host.hostName);
  171. host.isDataNode = host.isTaskTracker
  172. = host.isRegionServer = !host.isMaster;
  173. }, this);
  174. if (hostsObj.someProperty('isDataNode', true)) {
  175. hostsObj.findProperty('isDataNode', true).set('isClient', true);
  176. }
  177. } else {
  178. var masterObj = {
  179. host: null,
  180. masterComponents: maxNoofHostComponents
  181. };
  182. hostsObj.forEach(function (host) {
  183. host.isMaster = this.hasMasterComponents(host.hostName);
  184. var countMasterComp = this.getMasterComponentsForHost(host.hostName).length;
  185. if (countMasterComp <= masterObj.masterComponents) {
  186. masterObj.masterComponents = countMasterComp;
  187. masterObj.host = host;
  188. }
  189. }, this);
  190. masterObj.host.set('isClient', true);
  191. masterObj.host.set('isDataNode', true);
  192. masterObj.host.set('isTaskTracker', true);
  193. masterObj.host.set('isRegionServer', true);
  194. }
  195. } else {
  196. var dataNodes = slaveComponents.findProperty('componentName', 'DATANODE');
  197. dataNodes.hosts.forEach(function (_dataNode) {
  198. var dataNode = hostsObj.findProperty('hostName', _dataNode.hostName);
  199. if (dataNode) {
  200. dataNode.set('isDataNode', true);
  201. dataNode.set('isDataNodeInstalled', _dataNode.isInstalled);
  202. }
  203. });
  204. if (this.get('isMrSelected')) {
  205. var taskTrackers = slaveComponents.findProperty('componentName', 'TASKTRACKER');
  206. taskTrackers.hosts.forEach(function (_taskTracker) {
  207. var taskTracker = hostsObj.findProperty('hostName', _taskTracker.hostName);
  208. if (taskTracker) {
  209. taskTracker.set('isTaskTracker', true);
  210. taskTracker.set('isTaskTrackerInstalled', _taskTracker.isInstalled);
  211. }
  212. });
  213. }
  214. if (this.get('isHbSelected')) {
  215. var regionServers = slaveComponents.findProperty('componentName', 'HBASE_REGIONSERVER');
  216. regionServers.hosts.forEach(function (_regionServer) {
  217. var regionServer = hostsObj.findProperty('hostName', _regionServer.hostName);
  218. if (regionServer) {
  219. regionServer.set('isRegionServer', true);
  220. regionServer.set('isRegionServerInstalled', _regionServer.isInstalled);
  221. }
  222. });
  223. }
  224. var clients = slaveComponents.findProperty('componentName', 'CLIENT');
  225. clients.hosts.forEach(function (_client) {
  226. var client = hostsObj.findProperty('hostName', _client.hostName);
  227. if (client) {
  228. client.set('isClient', true);
  229. client.set('isClientInstalled', _client.isInstalled);
  230. }
  231. }, this);
  232. allHosts.forEach(function (_hostname) {
  233. var host = hostsObj.findProperty('hostName', _hostname);
  234. if (host) {
  235. host.set('isMaster', this.hasMasterComponents(_hostname));
  236. }
  237. }, this);
  238. }
  239. hostsObj.forEach(function (host) {
  240. this.get('hosts').pushObject(host);
  241. }, this);
  242. },
  243. /**
  244. * Return list of master components for specified <code>hostname</code>
  245. * @param hostName
  246. * @return {*}
  247. */
  248. getMasterComponentsForHost: function (hostName) {
  249. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  250. },
  251. /**
  252. * Validate form. Return do we have errors or not
  253. * @return {Boolean}
  254. */
  255. validate: function () {
  256. var isError = this.get('isNoDataNodes') || this.get('isNoClients')
  257. || ( this.get('isMrSelected') && this.get('isNoTaskTrackers'))
  258. || ( this.get('isHbSelected') && this.get('isNoRegionServers'));
  259. if (isError) {
  260. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  261. }
  262. return !isError;
  263. }
  264. });