step6_controller.js 10.0 KB

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