step6_controller.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. /**
  20. * By Step 6, we have the following information stored in App.db and set on this
  21. * controller by the router:
  22. *
  23. * hosts: App.db.hosts (list of all hosts the user selected in Step 3)
  24. * selectedServiceNames: App.db.selectedServiceNames (the services that the user selected in Step 4)
  25. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  26. *
  27. * Step 6 will set the following information in App.db:
  28. * hostSlaveComponents: App.db.hostSlaveComponents (hosts-to-slave-components mapping the user selected in Steo 6)
  29. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  30. *
  31. */
  32. App.InstallerStep6Controller = Em.Controller.extend({
  33. hosts: [],
  34. // TODO: hook up with user host selection
  35. rawHosts: require('data/mock/hosts'),
  36. selectedServiceNames: null,
  37. masterComponentHosts: require('data/mock/master_component_hosts'),
  38. hasMasterComponents: function(hostname) {
  39. var hasMaster = false;
  40. this.get('masterComponentHosts').forEach(function(masterComponent) {
  41. if (masterComponent.hosts.contains(hostname)) {
  42. hasMaster = true;
  43. }
  44. });
  45. return hasMaster;
  46. },
  47. isAllDataNodes: function() {
  48. return this.get('hosts').everyProperty('isDataNode', true);
  49. }.property('hosts.@each.isDataNode'),
  50. isAllTaskTrackers: function() {
  51. return this.get('hosts').everyProperty('isTaskTracker', true);
  52. }.property('hosts.@each.isTaskTracker'),
  53. isAllRegionServers: function() {
  54. return this.get('hosts').everyProperty('isRegionServer', true);
  55. }.property('hosts.@each.isRegionServer'),
  56. isNoDataNodes: function() {
  57. return this.get('hosts').everyProperty('isDataNode', false);
  58. }.property('hosts.@each.isDataNode'),
  59. isNoTaskTrackers: function() {
  60. return this.get('hosts').everyProperty('isTaskTracker', false);
  61. }.property('hosts.@each.isTaskTracker'),
  62. isNoRegionServers: function() {
  63. return this.get('hosts').everyProperty('isRegionServer', false);
  64. }.property('hosts.@each.isRegionServer'),
  65. selectAllDataNodes: function() {
  66. this.get('hosts').setEach('isDataNode', true);
  67. },
  68. selectAllTaskTrackers: function() {
  69. this.get('hosts').setEach('isTaskTracker', true);
  70. },
  71. selectAllRegionServers: function() {
  72. this.get('hosts').setEach('isRegionServer', true);
  73. },
  74. deselectAllDataNodes: function() {
  75. this.get('hosts').setEach('isDataNode', false);
  76. },
  77. deselectAllTaskTrackers: function() {
  78. this.get('hosts').setEach('isTaskTracker', false);
  79. },
  80. deselectAllRegionServers: function() {
  81. this.get('hosts').setEach('isRegionServer', false);
  82. },
  83. init: function() {
  84. this._super();
  85. this.get('rawHosts').forEach(function(host) {
  86. host.isDataNode = host.isTaskTracker = host.isRegionServer = !this.hasMasterComponents(host.hostname);
  87. this.get('hosts').pushObject(Ember.Object.create(host));
  88. }, this);
  89. },
  90. validate: function() {
  91. return !(this.get('isNoDataNodes') || this.get('isNoTaskTrackers') || this.get('isNoRegionServers'));
  92. },
  93. submit: function() {
  94. if (!this.validate()) {
  95. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  96. return;
  97. }
  98. App.db.setHostSlaveComponents(this.get('host'));
  99. var dataNodeHosts = [];
  100. var taskTrackerHosts = [];
  101. var regionServerHosts = [];
  102. this.get('hosts').forEach(function (host) {
  103. if (host.get('isDataNode')) {
  104. dataNodeHosts.push({
  105. hostname: host.hostname,
  106. group: 'Default'
  107. });
  108. }
  109. if (host.get('isTaskTracker')) {
  110. taskTrackerHosts.push({
  111. hostname: host.hostname,
  112. group: 'Default'
  113. });
  114. }
  115. if (host.get('isRegionServer')) {
  116. regionServerHosts.push({
  117. hostname: host.hostname,
  118. group: 'Default'
  119. });
  120. }
  121. });
  122. var slaveComponentHosts = [];
  123. slaveComponentHosts.push({
  124. componentName: 'DataNode',
  125. hosts: dataNodeHosts
  126. });
  127. slaveComponentHosts.push({
  128. componentName: 'TaskTracker',
  129. hosts: taskTrackerHosts
  130. });
  131. slaveComponentHosts.push({
  132. componentName: 'RegionServer',
  133. hosts: regionServerHosts
  134. });
  135. App.db.setSlaveComponentHosts(slaveComponentHosts);
  136. App.router.transitionTo('step7');
  137. }
  138. });