step6_controller.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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.InstallerStep6Controller = Em.Controller.extend({
  34. hosts: [],
  35. // TODO: hook up with user host selection
  36. rawHosts: [],
  37. selectedServiceNames: [],
  38. masterComponentHosts: require('data/mock/master_component_hosts'),
  39. showHbase: false,
  40. showTaskTracker: false,
  41. hasMasterComponents: function (hostname) {
  42. var hasMaster = false;
  43. var masterComponentHosts = db.getMasterComponentHosts();
  44. return masterComponentHosts.someProperty('hostName', hostname);
  45. },
  46. isAllDataNodes: function () {
  47. return this.get('hosts').everyProperty('isDataNode', true);
  48. }.property('hosts.@each.isDataNode'),
  49. isAllTaskTrackers: function () {
  50. return this.get('hosts').everyProperty('isTaskTracker', true);
  51. }.property('hosts.@each.isTaskTracker'),
  52. isAllRegionServers: function () {
  53. return this.get('hosts').everyProperty('isRegionServer', true);
  54. }.property('hosts.@each.isRegionServer'),
  55. isNoDataNodes: function () {
  56. return this.get('hosts').everyProperty('isDataNode', false);
  57. }.property('hosts.@each.isDataNode'),
  58. isNoTaskTrackers: function () {
  59. return this.get('hosts').everyProperty('isTaskTracker', false);
  60. }.property('hosts.@each.isTaskTracker'),
  61. isNoRegionServers: function () {
  62. return this.get('hosts').everyProperty('isRegionServer', false);
  63. }.property('hosts.@each.isRegionServer'),
  64. isHbaseSelected: function () {
  65. var services = db.getSelectedServiceNames();
  66. return this.get('selectedServiceNames').contains('HBASE');
  67. },
  68. isMrSelected: function () {
  69. return this.get('selectedServiceNames').contains('MAPREDUCE');
  70. }.property('selectedServiceNames'),
  71. clearError: function () {
  72. if (this.get('isNoDataNodes') === false && this.get('isNoTaskTrackers') === false && this.get('isNoRegionServers') === false) {
  73. this.set('errorMessage', '');
  74. }
  75. }.observes('isNoDataNodes', 'isNoTaskTrackers', 'isNoRegionServers'),
  76. selectAllDataNodes: function () {
  77. this.get('hosts').setEach('isDataNode', true);
  78. },
  79. selectAllTaskTrackers: function () {
  80. this.get('hosts').setEach('isTaskTracker', true);
  81. },
  82. selectAllRegionServers: function () {
  83. this.get('hosts').setEach('isRegionServer', true);
  84. },
  85. deselectAllDataNodes: function () {
  86. this.get('hosts').setEach('isDataNode', false);
  87. },
  88. deselectAllTaskTrackers: function () {
  89. this.get('hosts').setEach('isTaskTracker', false);
  90. },
  91. deselectAllRegionServers: function () {
  92. this.get('hosts').setEach('isRegionServer', false);
  93. },
  94. clearStep: function () {
  95. this.set('hosts', []);
  96. this.set('selectedServiceNames', []);
  97. this.clearError();
  98. },
  99. loadStep: function () {
  100. console.log("TRACE: Loading step6: Assign Slaves");
  101. this.clearStep();
  102. this.set('selectedServiceNames', db.getSelectedServiceNames());
  103. this.set('showHbase', this.isHbaseSelected());
  104. this.set('showTaskTracker', this.get('isMrSelected'));
  105. this.setSlaveHost(this.getSlaveHosts());
  106. },
  107. getHostNames: function () {
  108. var hostInfo = db.getHosts();
  109. var hostNames = [];
  110. for (var index in hostInfo) {
  111. if (hostInfo[index].bootStatus === 'success')
  112. hostNames.push(hostInfo[index].name);
  113. }
  114. return hostNames;
  115. },
  116. getSlaveHosts: function () {
  117. var hostObjs = new Ember.Set();
  118. var allHosts = this.getHostNames();
  119. var slaveHosts = App.db.getSlaveComponentHosts();
  120. if (slaveHosts === undefined || slaveHosts === null) {
  121. allHosts.forEach(function (_hostname) {
  122. var hostObj = {};
  123. hostObj.hostname = _hostname;
  124. hostObj.isDataNode = !this.hasMasterComponents(_hostname);
  125. hostObj.isTaskTracker = !this.hasMasterComponents(_hostname);
  126. hostObj.isRegionServer = !this.hasMasterComponents(_hostname);
  127. hostObjs.add(hostObj);
  128. }, this);
  129. return hostObjs;
  130. } else {
  131. allHosts.forEach(function (_hostName) {
  132. hostObjs.add({
  133. hostname: _hostName
  134. });
  135. });
  136. var datanodes = slaveHosts.findProperty('componentName', 'DATANODE');
  137. datanodes.hosts.forEach(function (_datanode) {
  138. var datanode = hostObjs.findProperty('hostname', _datanode.hostname);
  139. if (datanode !== null) {
  140. datanode.isDataNode = true;
  141. }
  142. });
  143. if (this.get('isMrSelected')) {
  144. var taskTrackers = slaveHosts.findProperty('componentName', 'TASKTRACKER');
  145. taskTrackers.hosts.forEach(function (_taskTracker) {
  146. var taskTracker = hostObjs.findProperty('hostname', _taskTracker.hostname);
  147. if (taskTracker !== null) {
  148. taskTracker.isTaskTracker = true;
  149. }
  150. });
  151. }
  152. if (this.isHbaseSelected()) {
  153. var regionServers = slaveHosts.findProperty('componentName', 'HBASE_REGIONSERVER');
  154. regionServers.hosts.forEach(function (_regionServer) {
  155. var regionServer = hostObjs.findProperty('hostname', _regionServer.hostname);
  156. if (regionServer !== null) {
  157. regionServer.isRegionServer = true;
  158. }
  159. });
  160. }
  161. return hostObjs;
  162. }
  163. },
  164. setSlaveHost: function (hostObj) {
  165. hostObj.forEach(function (_hostObj) {
  166. this.get('hosts').pushObject(Ember.Object.create(_hostObj));
  167. }, this);
  168. },
  169. loadSlaveHost: function (hostNames) {
  170. hostNames.forEach(function (_hostName) {
  171. this.get('hosts').pushObject(Ember.Object.create({
  172. hostname: _hostName,
  173. isDataNode: !this.hasMasterComponents(_hostName),
  174. isTaskTracker: !this.hasMasterComponents(_hostName),
  175. isRegionServer: !this.hasMasterComponents(_hostName)
  176. }));
  177. }, this);
  178. },
  179. validate: function () {
  180. return !(this.get('isNoDataNodes') || this.get('isNoTaskTrackers') || this.get('isNoRegionServers'));
  181. },
  182. submit: function () {
  183. if (!this.validate()) {
  184. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  185. return;
  186. }
  187. App.db.setHostSlaveComponents(this.get('host'));
  188. var dataNodeHosts = [];
  189. var taskTrackerHosts = [];
  190. var regionServerHosts = [];
  191. this.get('hosts').forEach(function (host) {
  192. if (host.get('isDataNode')) {
  193. dataNodeHosts.push({
  194. hostname: host.hostname,
  195. group: 'Default'
  196. });
  197. }
  198. if (this.get('isMrSelected') && host.get('isRegionServer')) {
  199. taskTrackerHosts.push({
  200. hostname: host.hostname,
  201. group: 'Default'
  202. });
  203. }
  204. if (this.isHbaseSelected() && host.get('isRegionServer')) {
  205. regionServerHosts.push({
  206. hostname: host.hostname,
  207. group: 'Default'
  208. });
  209. }
  210. }, this);
  211. var slaveComponentHosts = [];
  212. slaveComponentHosts.push({
  213. componentName: 'DATANODE',
  214. displayName: 'DataNode',
  215. hosts: dataNodeHosts
  216. });
  217. if (this.get('isMrSelected')) {
  218. slaveComponentHosts.push({
  219. componentName: 'TASKTRACKER',
  220. displayName: 'TaskTracker',
  221. hosts: taskTrackerHosts
  222. });
  223. }
  224. if (this.isHbaseSelected()) {
  225. slaveComponentHosts.push({
  226. componentName: 'HBASE_REGIONSERVER',
  227. displayName: 'RegionServer',
  228. hosts: regionServerHosts
  229. });
  230. }
  231. App.db.setSlaveComponentHosts(slaveComponentHosts);
  232. App.router.send('next');
  233. }
  234. })
  235. ;