add_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. App.AddHostController = App.WizardController.extend({
  20. name: 'addHostController',
  21. totalSteps: 7,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. /**
  27. * All wizards data will be stored in this variable
  28. *
  29. * cluster - cluster name
  30. * hosts - hosts, ssh key, repo info, etc.
  31. * services - services list
  32. * hostsInfo - list of selected hosts
  33. * slaveComponentHosts, hostSlaveComponents - info about slave hosts
  34. * masterComponentHosts - info about master hosts
  35. * config??? - to be described later
  36. */
  37. content: Em.Object.create({
  38. cluster: null,
  39. hosts: null,
  40. installOptions: null,
  41. services: null,
  42. slaveComponentHosts: null,
  43. masterComponentHosts: null,
  44. serviceConfigProperties: null,
  45. advancedServiceConfig: null,
  46. controllerName: 'addHostController'
  47. }),
  48. components:require('data/service_components'),
  49. /**
  50. * return new object extended from clusterStatusTemplate
  51. * @return Object
  52. */
  53. getCluster: function(){
  54. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  55. },
  56. /**
  57. * return new object extended from installOptionsTemplate
  58. * @return Object
  59. */
  60. getInstallOptions: function(){
  61. return jQuery.extend({}, this.get('installOptionsTemplate'));
  62. },
  63. /**
  64. * return empty hosts array
  65. * @return Array
  66. */
  67. getHosts: function(){
  68. return [];
  69. },
  70. /**
  71. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  72. * @param hosts Array of hosts, which we want to delete
  73. */
  74. removeHosts: function (hosts) {
  75. //todo Replace this code with real logic
  76. App.db.removeHosts(hosts);
  77. },
  78. /**
  79. * Load services data from server.
  80. */
  81. loadServicesFromServer: function() {
  82. var displayOrderConfig = require('data/services');
  83. var apiUrl = App.get('stackVersionURL');
  84. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  85. //
  86. apiService.forEach(function(item, index){
  87. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  88. apiService[index].isDisabled = apiService[index].isSelected;
  89. apiService[index].isInstalled = apiService[index].isSelected;
  90. });
  91. this.set('content.services', apiService);
  92. App.db.setService(apiService);
  93. },
  94. /**
  95. * Load services data. Will be used at <code>Select services(step4)</code> step
  96. */
  97. loadServices: function () {
  98. var servicesInfo = App.db.getService();
  99. servicesInfo.forEach(function (item, index) {
  100. servicesInfo[index] = Em.Object.create(item);
  101. });
  102. this.set('content.services', servicesInfo);
  103. console.log('AddHostController.loadServices: loaded data ', servicesInfo);
  104. var serviceNames = servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName');
  105. console.log('selected services ', serviceNames);
  106. this.set('content.skipMasterStep', !serviceNames.contains('HBASE') && !serviceNames.contains('ZOOKEEPER'));
  107. },
  108. /**
  109. * Load master component hosts data for using in required step controllers
  110. */
  111. loadMasterComponentHosts: function () {
  112. var masterComponentHosts = App.db.getMasterComponentHosts();
  113. if (!masterComponentHosts) {
  114. masterComponentHosts = [];
  115. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  116. masterComponentHosts.push({
  117. component: item.get('componentName'),
  118. hostName: item.get('host.hostName'),
  119. isInstalled: true,
  120. serviceId: item.get('service.id'),
  121. display_name: item.get('displayName')
  122. })
  123. });
  124. App.db.setMasterComponentHosts(masterComponentHosts);
  125. }
  126. this.set("content.masterComponentHosts", masterComponentHosts);
  127. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  128. },
  129. /**
  130. * Save HBase and ZooKeeper to main controller
  131. * @param stepController
  132. */
  133. saveHbZk: function(stepController) {
  134. var self = this;
  135. var hosts = stepController.get('hosts');
  136. var headers = stepController.get('headers');
  137. var masterComponentHosts = App.db.getMasterComponentHosts();
  138. headers.forEach(function(header) {
  139. var rm = masterComponentHosts.filterProperty('component', header.get('name'));
  140. if(rm) {
  141. masterComponentHosts.removeObjects(rm);
  142. }
  143. });
  144. headers.forEach(function(header) {
  145. var component = self.get('components').findProperty('component_name', header.get('name'));
  146. hosts.forEach(function(host) {
  147. if (host.get('checkboxes').findProperty('title', component.display_name).checked) {
  148. masterComponentHosts .push({
  149. display_name: component.display_name,
  150. component: component.component_name,
  151. hostName: host.get('hostName'),
  152. serviceId: component.service_name,
  153. isInstalled: false
  154. });
  155. }
  156. });
  157. });
  158. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  159. App.db.setMasterComponentHosts(masterComponentHosts);
  160. this.set('content.masterComponentHosts', masterComponentHosts);
  161. },
  162. /**
  163. * return slaveComponents bound to hosts
  164. * @return {Array}
  165. */
  166. getSlaveComponentHosts: function () {
  167. var components = [
  168. {
  169. name: 'DATANODE',
  170. service: 'HDFS'
  171. },
  172. {
  173. name: 'TASKTRACKER',
  174. service: 'MAPREDUCE'
  175. },
  176. {
  177. name: 'HBASE_REGIONSERVER',
  178. service: 'HBASE'
  179. }
  180. ];
  181. var result = [];
  182. var services = App.Service.find();
  183. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  184. for (var index = 0; index < components.length; index++) {
  185. var comp = components[index];
  186. if (!selectedServices.contains(comp.service)) {
  187. continue;
  188. }
  189. var service = services.findProperty('id', comp.service);
  190. var hosts = [];
  191. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  192. hosts.push({
  193. group: "Default",
  194. hostName: host_component.get('host.id'),
  195. isInstalled: true
  196. });
  197. }, this);
  198. result.push({
  199. componentName: comp.name,
  200. displayName: App.format.role(comp.name),
  201. hosts: hosts,
  202. isInstalled: true
  203. })
  204. }
  205. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  206. var hosts = [];
  207. clientsHosts.forEach(function (host_component) {
  208. hosts.push({
  209. group: "Default",
  210. hostName: host_component.get('host.id'),
  211. isInstalled: true
  212. });
  213. }, this);
  214. result.push({
  215. componentName: 'CLIENT',
  216. displayName: 'client',
  217. hosts: hosts,
  218. isInstalled: true
  219. })
  220. return result;
  221. },
  222. /**
  223. * Load master component hosts data for using in required step controllers
  224. */
  225. loadSlaveComponentHosts: function () {
  226. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  227. if (!slaveComponentHosts) {
  228. slaveComponentHosts = this.getSlaveComponentHosts();
  229. }
  230. this.set("content.slaveComponentHosts", slaveComponentHosts);
  231. console.log("AddHostController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  232. },
  233. /**
  234. * Load information about hosts with clients components
  235. */
  236. loadClients: function () {
  237. var clients = App.db.getClientsForSelectedServices();
  238. this.set('content.clients', clients);
  239. console.log("AddHostController.loadClients: loaded list ", clients);
  240. },
  241. /**
  242. * Generate clients list for selected services and save it to model
  243. * @param stepController step4WizardController
  244. */
  245. saveClients: function () {
  246. var clients = [];
  247. var serviceComponents = require('data/service_components');
  248. var hostComponents = App.HostComponent.find();
  249. this.get('content.services').filterProperty('isSelected', true).forEach(function (_service) {
  250. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  251. if (client) {
  252. clients.pushObject({
  253. component_name: client.component_name,
  254. display_name: client.display_name,
  255. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  256. });
  257. }
  258. }, this);
  259. App.db.setClientsForSelectedServices(clients);
  260. this.set('content.clients', clients);
  261. console.log("AddHostController.saveClients: saved list ", clients);
  262. },
  263. /**
  264. * Load data for all steps until <code>current step</code>
  265. */
  266. loadAllPriorSteps: function () {
  267. var step = this.get('currentStep');
  268. switch (step) {
  269. case '9':
  270. case '8':
  271. case '7':
  272. case '6':
  273. case '5':
  274. this.loadServiceConfigProperties();
  275. case '4':
  276. case '3':
  277. this.loadClients();
  278. this.loadServices();
  279. this.loadMasterComponentHosts();
  280. this.loadSlaveComponentHosts();
  281. this.load('hosts');
  282. case '2':
  283. this.loadServices();
  284. case '1':
  285. this.load('hosts');
  286. this.load('installOptions');
  287. this.load('cluster');
  288. }
  289. },
  290. /**
  291. * Remove all loaded data.
  292. * Created as copy for App.router.clearAllSteps
  293. */
  294. clearAllSteps: function () {
  295. this.clearInstallOptions();
  296. // clear temporary information stored during the install
  297. this.set('content.cluster', this.getCluster());
  298. },
  299. /**
  300. * Clear all temporary data
  301. */
  302. finish: function () {
  303. this.setCurrentStep('1');
  304. this.clearAllSteps();
  305. this.clearStorageData();
  306. App.router.get('updateController').updateAll();
  307. }
  308. });