step6_controller.js 9.6 KB

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