step6_controller.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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.WizardStep6Controller = Em.Controller.extend({
  34. hosts: [],
  35. isAllDataNodes: function () {
  36. return this.get('hosts').everyProperty('isDataNode', true);
  37. }.property('hosts.@each.isDataNode'),
  38. isAllTaskTrackers: function () {
  39. return this.get('hosts').everyProperty('isTaskTracker', true);
  40. }.property('hosts.@each.isTaskTracker'),
  41. isAllRegionServers: function () {
  42. return this.get('hosts').everyProperty('isRegionServer', true);
  43. }.property('hosts.@each.isRegionServer'),
  44. isAllClients: function () {
  45. return this.get('hosts').everyProperty('isClient', true);
  46. }.property('hosts.@each.isClient'),
  47. isNoDataNodes: function () {
  48. return this.get('hosts').everyProperty('isDataNode', false);
  49. }.property('hosts.@each.isDataNode'),
  50. isNoTaskTrackers: function () {
  51. return this.get('hosts').everyProperty('isTaskTracker', false);
  52. }.property('hosts.@each.isTaskTracker'),
  53. isNoRegionServers: function () {
  54. return this.get('hosts').everyProperty('isRegionServer', false);
  55. }.property('hosts.@each.isRegionServer'),
  56. isNoClients: function () {
  57. return this.get('hosts').everyProperty('isClient', false);
  58. }.property('hosts.@each.isClient'),
  59. /**
  60. * Return whether Hbase service was selected or not.
  61. * Calculate this information on <code>content.services</code> variable
  62. * @return Boolean
  63. */
  64. isHbSelected: function () {
  65. return this.get('content.services').findProperty('serviceName', 'HBASE').get('isSelected');
  66. }.property('content'),
  67. /**
  68. * Return whether MapReduce service was selected or not.
  69. * Calculate this information on <code>content.services</code> variable
  70. * @return Boolean
  71. */
  72. isMrSelected: function () {
  73. return this.get('content.services').findProperty('serviceName', 'MAPREDUCE').get('isSelected');
  74. }.property('content'),
  75. clearError: function () {
  76. if (this.get('isNoDataNodes') === false &&
  77. (this.get('isNoTaskTrackers') === false || this.get('isMrSelected') === false) &&
  78. (this.get('isNoRegionServers') === false || this.get('isHbSelected') === false) &&
  79. this.get('isNoClients') === false) {
  80. this.set('errorMessage', '');
  81. }
  82. }.observes('isNoDataNodes', 'isNoTaskTrackers', 'isNoRegionServers', 'isNoClients'),
  83. /**
  84. * Check whether current host is currently selected as master
  85. * @param hostname
  86. * @return {Boolean}
  87. */
  88. hasMasterComponents: function (hostname) {
  89. return this.get('content.masterComponentHosts').someProperty('hostName', hostname);
  90. },
  91. selectAllDataNodes: function () {
  92. this.get('hosts').setEach('isDataNode', true);
  93. },
  94. selectAllTaskTrackers: function () {
  95. this.get('hosts').setEach('isTaskTracker', true);
  96. },
  97. selectAllRegionServers: function () {
  98. this.get('hosts').setEach('isRegionServer', true);
  99. },
  100. selectAllClients: function () {
  101. this.get('hosts').setEach('isClient', true);
  102. },
  103. deselectAllDataNodes: function () {
  104. this.get('hosts').setEach('isDataNode', false);
  105. },
  106. deselectAllTaskTrackers: function () {
  107. this.get('hosts').setEach('isTaskTracker', false);
  108. },
  109. deselectAllRegionServers: function () {
  110. this.get('hosts').setEach('isRegionServer', false);
  111. },
  112. deselectAllClients: function () {
  113. this.get('hosts').setEach('isClient', false);
  114. },
  115. clearStep: function () {
  116. this.set('hosts', []);
  117. this.clearError();
  118. },
  119. loadStep: function () {
  120. console.log("WizardStep6Controller: Loading step6: Assign Slaves");
  121. this.clearStep();
  122. this.renderSlaveHosts();
  123. },
  124. /**
  125. * Get active host names
  126. * @return {Array}
  127. */
  128. getHostNames: function () {
  129. var hostInfo = this.get('content.hostsInfo');
  130. var hostNames = [];
  131. for (var index in hostInfo) {
  132. if (hostInfo[index].bootStatus === 'success' || true) //TODO: remove true after integration with bootstrap
  133. hostNames.push(hostInfo[index].name);
  134. }
  135. return hostNames;
  136. },
  137. /**
  138. * Load all data needed for this module. Then it automatically renders in template
  139. * @return {Ember.Set}
  140. */
  141. renderSlaveHosts: function () {
  142. var hostsObj = Em.Set.create();
  143. var allHosts = this.getHostNames();
  144. var slaveHosts = this.get('content.slaveComponentHosts');
  145. allHosts.forEach(function (_hostName) {
  146. hostsObj.push(Em.Object.create({
  147. hostname: _hostName,
  148. isMaster: false,
  149. isDataNode: false,
  150. isTaskTracker: false,
  151. isRegionServer: false,
  152. isClient: false
  153. }));
  154. });
  155. if (!slaveHosts) { // we are at this page for the first time
  156. hostsObj.forEach(function (host) {
  157. host.isMaster = this.hasMasterComponents(host.hostname);
  158. host.isDataNode = host.isTaskTracker
  159. = host.isRegionServer = !host.isMaster;
  160. }, this);
  161. if (hostsObj.someProperty('isDataNode', true)) {
  162. hostsObj.findProperty('isDataNode', true).set('isClient', true);
  163. }
  164. } else {
  165. var dataNodes = slaveHosts.findProperty('componentName', 'DATANODE');
  166. dataNodes.hosts.forEach(function (_dataNode) {
  167. var dataNode = hostsObj.findProperty('hostname', _dataNode.hostname);
  168. if (dataNode) {
  169. dataNode.set('isDataNode', true);
  170. }
  171. });
  172. if(this.get('isMrSelected')) {
  173. var taskTrackers = slaveHosts.findProperty('componentName', 'TASKTRACKER');
  174. taskTrackers.hosts.forEach(function (_taskTracker) {
  175. var taskTracker = hostsObj.findProperty('hostname', _taskTracker.hostname);
  176. if (taskTracker) {
  177. taskTracker.set('isTaskTracker', true);
  178. }
  179. });
  180. }
  181. if (this.get('isHbSelected')) {
  182. var regionServers = slaveHosts.findProperty('componentName', 'HBASE_REGIONSERVER');
  183. regionServers.hosts.forEach(function (_regionServer) {
  184. var regionServer = hostsObj.findProperty('hostname', _regionServer.hostname);
  185. if (regionServer) {
  186. regionServer.set('isRegionServer', true);
  187. }
  188. });
  189. }
  190. var clients = slaveHosts.findProperty('componentName', 'CLIENT');
  191. clients.hosts.forEach(function (_client) {
  192. var client = hostsObj.findProperty('hostname', _client.hostname);
  193. if (client) {
  194. client.set('isClient', true);
  195. }
  196. }, this);
  197. allHosts.forEach(function (_hostname) {
  198. var host = hostsObj.findProperty('hostname', _hostname);
  199. if (host) {
  200. host.set('isMaster', this.hasMasterComponents(_hostname));
  201. }
  202. }, this);
  203. }
  204. hostsObj.forEach(function(host){
  205. this.get('hosts').pushObject(host);
  206. }, this);
  207. },
  208. /**
  209. * Return list of master components for specified <code>hostname</code>
  210. * @param hostname
  211. * @return {*}
  212. */
  213. getMasterComponentsForHost: function (hostname) {
  214. var hostInfo = this.get('content.hostToMasterComponent').findProperty('hostname', hostname);
  215. if(hostInfo){
  216. return hostInfo.components;
  217. }
  218. return false;
  219. },
  220. /**
  221. * Validate form. Return do we have errors or not
  222. * @return {Boolean}
  223. */
  224. validate: function () {
  225. var isError = this.get('isNoDataNodes') || this.get('isNoClients')
  226. || ( this.get('isMrSelected') && this.get('isNoTaskTrackers'))
  227. || ( this.get('isHbSelected') &&this.get('isNoRegionServers'));
  228. if(isError){
  229. this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
  230. }
  231. return !isError;
  232. }
  233. });