step6_controller.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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: null,
  38. masterComponentHosts: require('data/mock/master_component_hosts'),
  39. showHbase: 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. isNoDataNodes: function () {
  55. return this.get('hosts').everyProperty('isDataNode', false);
  56. }.property('hosts.@each.isDataNode'),
  57. isNoTaskTrackers: function () {
  58. return this.get('hosts').everyProperty('isTaskTracker', false);
  59. }.property('hosts.@each.isTaskTracker'),
  60. isNoRegionServers: function () {
  61. return this.get('hosts').everyProperty('isRegionServer', false);
  62. }.property('hosts.@each.isRegionServer'),
  63. isHbaseSelected: function () {
  64. var services = db.getSelectedServiceNames();
  65. console.log('isHbase selected is: ' + services.contains('HBASE'));
  66. return services.contains('HBASE');
  67. },
  68. selectAllDataNodes: function () {
  69. this.get('hosts').setEach('isDataNode', true);
  70. },
  71. selectAllTaskTrackers: function () {
  72. this.get('hosts').setEach('isTaskTracker', true);
  73. },
  74. selectAllRegionServers: function () {
  75. this.get('hosts').setEach('isRegionServer', true);
  76. },
  77. deselectAllDataNodes: function () {
  78. this.get('hosts').setEach('isDataNode', false);
  79. },
  80. deselectAllTaskTrackers: function () {
  81. this.get('hosts').setEach('isTaskTracker', false);
  82. },
  83. deselectAllRegionServers: function () {
  84. this.get('hosts').setEach('isRegionServer', false);
  85. },
  86. clearStep: function () {
  87. this.set('hosts', []);
  88. },
  89. loadStep: function (reload) {
  90. console.log("TRACE: Loading step6: Assign Slaves");
  91. this.clearStep();
  92. this.set('showHbase', this.isHbaseSelected());
  93. if (reload === true) {
  94. this.setSlaveHost(this.getHostNames());
  95. } else {
  96. this.loadSlaveHost(this.getSlaveHosts());
  97. }
  98. },
  99. navigateStep: function () {
  100. if (App.router.get('isFwdNavigation') === true && !App.router.get('backBtnForHigherStep')) {
  101. this.loadStep(true);
  102. }
  103. App.router.set('backBtnForHigherStep', false);
  104. },
  105. getSlaveHosts: function () {
  106. var slaveHosts = App.db.getSlaveComponentHosts();
  107. var hostNames = this.getHostNames();
  108. var hostObjs = new Ember.Set();
  109. hostNames.forEach(function (_hostName) {
  110. hostObjs.add({
  111. hostname: _hostName
  112. });
  113. });
  114. var datanodes = slaveHosts.findProperty('componentName', 'DataNode');
  115. datanodes.hosts.forEach(function (_datanode) {
  116. var datanode = hostObjs.findProperty('hostname', _datanode.hostname);
  117. if (datanode !== null) {
  118. datanode.isDataNode = true;
  119. }
  120. });
  121. var taskTrackers = slaveHosts.findProperty('componentName', 'TaskTracker');
  122. taskTrackers.hosts.forEach(function (_taskTracker) {
  123. var taskTracker = hostObjs.findProperty('hostname', _taskTracker.hostname);
  124. if (taskTracker !== null) {
  125. taskTracker.isTaskTracker = true;
  126. }
  127. });
  128. if (this.isHbaseSelected()) {
  129. var regionServers = slaveHosts.findProperty('componentName', 'RegionServer');
  130. regionServers.hosts.forEach(function (_regionServer) {
  131. var regionServer = hostObjs.findProperty('hostname', _regionServer.hostname);
  132. if (regionServer !== null) {
  133. regionServer.isRegionServer = true;
  134. }
  135. });
  136. }
  137. return hostObjs;
  138. },
  139. loadSlaveHost: function (hostObj) {
  140. hostObj.forEach(function (_hostObj) {
  141. this.get('hosts').pushObject(Ember.Object.create(_hostObj));
  142. }, this);
  143. },
  144. setSlaveHost: function (hostNames) {
  145. hostNames.forEach(function (_hostName) {
  146. this.get('hosts').pushObject(Ember.Object.create({
  147. hostname: _hostName,
  148. isDataNode: !this.hasMasterComponents(_hostName),
  149. isTaskTracker: !this.hasMasterComponents(_hostName),
  150. isRegionServer: !this.hasMasterComponents(_hostName)
  151. }));
  152. }, this);
  153. },
  154. getHostNames: function () {
  155. var hostInfo = db.getHosts();
  156. var hostNames = [];
  157. for (var index in hostInfo) {
  158. if (hostInfo[index].bootStatus === 'success')
  159. hostNames.push(hostInfo[index].name);
  160. }
  161. return hostNames;
  162. },
  163. validate: function () {
  164. return !(this.get('isNoDataNodes') || this.get('isNoTaskTrackers') || this.get('isNoRegionServers'));
  165. },
  166. submit: function () {
  167. if (!this.validate()) {
  168. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  169. return;
  170. }
  171. App.db.setHostSlaveComponents(this.get('host'));
  172. var dataNodeHosts = [];
  173. var taskTrackerHosts = [];
  174. var regionServerHosts = [];
  175. this.get('hosts').forEach(function (host) {
  176. if (host.get('isDataNode')) {
  177. dataNodeHosts.push({
  178. hostname: host.hostname,
  179. group: 'Default'
  180. });
  181. }
  182. if (host.get('isTaskTracker')) {
  183. taskTrackerHosts.push({
  184. hostname: host.hostname,
  185. group: 'Default'
  186. });
  187. }
  188. if (this.isHbaseSelected() && host.get('isRegionServer')) {
  189. regionServerHosts.push({
  190. hostname: host.hostname,
  191. group: 'Default'
  192. });
  193. }
  194. }, this);
  195. var slaveComponentHosts = [];
  196. slaveComponentHosts.push({
  197. componentName: 'DataNode',
  198. hosts: dataNodeHosts
  199. });
  200. slaveComponentHosts.push({
  201. componentName: 'TaskTracker',
  202. hosts: taskTrackerHosts
  203. });
  204. if (this.isHbaseSelected()) {
  205. slaveComponentHosts.push({
  206. componentName: 'RegionServer',
  207. hosts: regionServerHosts
  208. });
  209. }
  210. App.db.setSlaveComponentHosts(slaveComponentHosts);
  211. App.router.transitionTo('step7');
  212. }
  213. });