step6_controller.js 10 KB

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