step6_controller.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. loadStep: function () {
  87. if (App.router.get('isFwdNavigation') === true) {
  88. console.log("TRACE: Loading step6: Assign Slaves");
  89. this.set('hosts', []);
  90. this.set('showHbase', this.isHbaseSelected());
  91. this.setSlaveHost(this.getHostNames());
  92. }
  93. },
  94. setSlaveHost: function (hostNames) {
  95. hostNames.forEach(function (_hostName) {
  96. this.get('hosts').pushObject(Ember.Object.create({
  97. hostname: _hostName,
  98. isDataNode: !this.hasMasterComponents(_hostName),
  99. isTaskTracker: !this.hasMasterComponents(_hostName),
  100. isRegionServer: !this.hasMasterComponents(_hostName)
  101. }));
  102. }, this);
  103. },
  104. getHostNames: function () {
  105. var hostInfo = db.getHosts();
  106. var hostNames = [];
  107. for (var index in hostInfo) {
  108. hostNames.push(hostInfo[index].name);
  109. }
  110. return hostNames;
  111. },
  112. validate: function () {
  113. return !(this.get('isNoDataNodes') || this.get('isNoTaskTrackers') || this.get('isNoRegionServers'));
  114. },
  115. submit: function () {
  116. if (!this.validate()) {
  117. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  118. return;
  119. }
  120. App.db.setHostSlaveComponents(this.get('host'));
  121. var dataNodeHosts = [];
  122. var taskTrackerHosts = [];
  123. var regionServerHosts = [];
  124. this.get('hosts').forEach(function (host) {
  125. if (host.get('isDataNode')) {
  126. dataNodeHosts.push({
  127. hostname: host.hostname,
  128. group: 'Default'
  129. });
  130. }
  131. if (host.get('isTaskTracker')) {
  132. taskTrackerHosts.push({
  133. hostname: host.hostname,
  134. group: 'Default'
  135. });
  136. }
  137. if (this.isHbaseSelected() && host.get('isRegionServer')) {
  138. regionServerHosts.push({
  139. hostname: host.hostname,
  140. group: 'Default'
  141. });
  142. }
  143. }, this);
  144. var slaveComponentHosts = [];
  145. slaveComponentHosts.push({
  146. componentName: 'DataNode',
  147. hosts: dataNodeHosts
  148. });
  149. slaveComponentHosts.push({
  150. componentName: 'TaskTracker',
  151. hosts: taskTrackerHosts
  152. });
  153. if (this.isHbaseSelected()) {
  154. slaveComponentHosts.push({
  155. componentName: 'RegionServer',
  156. hosts: regionServerHosts
  157. });
  158. }
  159. App.db.setSlaveComponentHosts(slaveComponentHosts);
  160. App.router.transitionTo('step7');
  161. }
  162. });