step6_controller.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. selectAllDataNodes: function () {
  72. this.get('hosts').setEach('isDataNode', true);
  73. },
  74. selectAllTaskTrackers: function () {
  75. this.get('hosts').setEach('isTaskTracker', true);
  76. },
  77. selectAllRegionServers: function () {
  78. this.get('hosts').setEach('isRegionServer', true);
  79. },
  80. deselectAllDataNodes: function () {
  81. this.get('hosts').setEach('isDataNode', false);
  82. },
  83. deselectAllTaskTrackers: function () {
  84. this.get('hosts').setEach('isTaskTracker', false);
  85. },
  86. deselectAllRegionServers: function () {
  87. this.get('hosts').setEach('isRegionServer', false);
  88. },
  89. clearStep: function () {
  90. this.set('hosts', []);
  91. this.set('selectedServiceNames', []);
  92. },
  93. loadStep: function () {
  94. console.log("TRACE: Loading step6: Assign Slaves");
  95. this.clearStep();
  96. this.set('selectedServiceNames',db.getSelectedServiceNames());
  97. this.set('showHbase', this.isHbaseSelected());
  98. this.set('showTaskTracker', this.get('isMrSelected'));
  99. this.setSlaveHost(this.getSlaveHosts());
  100. },
  101. navigateStep: function () {
  102. this.loadStep();
  103. },
  104. getHostNames: function () {
  105. var hostInfo = db.getHosts();
  106. var hostNames = [];
  107. for (var index in hostInfo) {
  108. if (hostInfo[index].bootStatus === 'success')
  109. hostNames.push(hostInfo[index].name);
  110. }
  111. return hostNames;
  112. },
  113. getSlaveHosts: function () {
  114. var hostObjs = new Ember.Set();
  115. var allHosts = this.getHostNames();
  116. var slaveHosts = App.db.getSlaveComponentHosts();
  117. if (slaveHosts === undefined || slaveHosts === null) {
  118. allHosts.forEach(function (_hostname) {
  119. var hostObj = {};
  120. hostObj.hostname = _hostname;
  121. hostObj.isDataNode = !this.hasMasterComponents(_hostname);
  122. hostObj.isTaskTracker = !this.hasMasterComponents(_hostname);
  123. hostObj.isRegionServer = !this.hasMasterComponents(_hostname);
  124. hostObjs.add(hostObj);
  125. }, this);
  126. return hostObjs;
  127. } else {
  128. allHosts.forEach(function (_hostName) {
  129. hostObjs.add({
  130. hostname: _hostName
  131. });
  132. });
  133. var datanodes = slaveHosts.findProperty('componentName', 'DATANODE');
  134. datanodes.hosts.forEach(function (_datanode) {
  135. var datanode = hostObjs.findProperty('hostname', _datanode.hostname);
  136. if (datanode !== null) {
  137. datanode.isDataNode = true;
  138. }
  139. });
  140. if (this.get('isMrSelected')) {
  141. var taskTrackers = slaveHosts.findProperty('componentName', 'TASKTRACKER');
  142. taskTrackers.hosts.forEach(function (_taskTracker) {
  143. var taskTracker = hostObjs.findProperty('hostname', _taskTracker.hostname);
  144. if (taskTracker !== null) {
  145. taskTracker.isTaskTracker = true;
  146. }
  147. });
  148. }
  149. if (this.isHbaseSelected()) {
  150. var regionServers = slaveHosts.findProperty('componentName', 'HBASE_REGIONSERVER');
  151. regionServers.hosts.forEach(function (_regionServer) {
  152. var regionServer = hostObjs.findProperty('hostname', _regionServer.hostname);
  153. if (regionServer !== null) {
  154. regionServer.isRegionServer = true;
  155. }
  156. });
  157. }
  158. return hostObjs;
  159. }
  160. },
  161. setSlaveHost: function (hostObj) {
  162. hostObj.forEach(function (_hostObj) {
  163. this.get('hosts').pushObject(Ember.Object.create(_hostObj));
  164. }, this);
  165. },
  166. loadSlaveHost: function (hostNames) {
  167. hostNames.forEach(function (_hostName) {
  168. this.get('hosts').pushObject(Ember.Object.create({
  169. hostname: _hostName,
  170. isDataNode: !this.hasMasterComponents(_hostName),
  171. isTaskTracker: !this.hasMasterComponents(_hostName),
  172. isRegionServer: !this.hasMasterComponents(_hostName)
  173. }));
  174. }, this);
  175. },
  176. validate: function () {
  177. return !(this.get('isNoDataNodes') || this.get('isNoTaskTrackers') || this.get('isNoRegionServers'));
  178. },
  179. submit: function () {
  180. if (!this.validate()) {
  181. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  182. return;
  183. }
  184. App.db.setHostSlaveComponents(this.get('host'));
  185. var dataNodeHosts = [];
  186. var taskTrackerHosts = [];
  187. var regionServerHosts = [];
  188. this.get('hosts').forEach(function (host) {
  189. if (host.get('isDataNode')) {
  190. dataNodeHosts.push({
  191. hostname: host.hostname,
  192. group: 'Default'
  193. });
  194. }
  195. if (this.get('isMrSelected') && host.get('isRegionServer')) {
  196. taskTrackerHosts.push({
  197. hostname: host.hostname,
  198. group: 'Default'
  199. });
  200. }
  201. if (this.isHbaseSelected() && host.get('isRegionServer')) {
  202. regionServerHosts.push({
  203. hostname: host.hostname,
  204. group: 'Default'
  205. });
  206. }
  207. }, this);
  208. var slaveComponentHosts = [];
  209. slaveComponentHosts.push({
  210. componentName: 'DATANODE',
  211. displayName: 'DataNode',
  212. hosts: dataNodeHosts
  213. });
  214. if (this.get('isMrSelected')) {
  215. slaveComponentHosts.push({
  216. componentName: 'TASKTRACKER',
  217. displayName: 'TaskTracker',
  218. hosts: taskTrackerHosts
  219. });
  220. }
  221. if (this.isHbaseSelected()) {
  222. slaveComponentHosts.push({
  223. componentName: 'HBASE_REGIONSERVER',
  224. displayName: 'RegionServer',
  225. hosts: regionServerHosts
  226. });
  227. }
  228. App.db.setSlaveComponentHosts(slaveComponentHosts);
  229. App.router.send('next');
  230. }
  231. })
  232. ;