step6_controller.js 7.9 KB

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