add_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.AddServiceController = App.WizardController.extend({
  20. name: 'addServiceController',
  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. * installOptions - ssh key, repo info, etc.
  31. * services - services list
  32. * hosts - list of selected hosts
  33. * slaveComponentHosts, - 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: 'addServiceController'
  47. }),
  48. /**
  49. * return new object extended from clusterStatusTemplate
  50. * @return Object
  51. */
  52. getCluster: function(){
  53. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  54. },
  55. /**
  56. * Load confirmed hosts.
  57. * Will be used at <code>Assign Masters(step5)</code> step
  58. */
  59. loadConfirmedHosts: function(){
  60. var hosts = App.db.getHosts();
  61. if(!hosts){
  62. var hosts = {};
  63. App.Host.find().forEach(function(item){
  64. hosts[item.get('id')] = {
  65. name: item.get('id'),
  66. cpu: item.get('cpu'),
  67. memory: item.get('memory'),
  68. disk_info: item.get('diskInfo'),
  69. bootStatus: "REGISTERED",
  70. isInstalled: true
  71. };
  72. });
  73. App.db.setHosts(hosts);
  74. }
  75. this.set('content.hosts', hosts);
  76. console.log('AddServiceController.loadConfirmedHosts: loaded hosts', hosts);
  77. },
  78. /**
  79. * Load services data from server.
  80. */
  81. loadServicesFromServer: function() {
  82. if(App.db.getService()){
  83. return;
  84. }
  85. var displayOrderConfig = require('data/services');
  86. var apiUrl = App.get('stackVersionURL');
  87. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  88. //
  89. apiService.forEach(function(item, index){
  90. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  91. apiService[index].isDisabled = apiService[index].isSelected;
  92. apiService[index].isInstalled = apiService[index].isSelected;
  93. });
  94. this.set('content.services', apiService);
  95. App.db.setService(apiService);
  96. },
  97. /**
  98. * Load services data. Will be used at <code>Select services(step4)</code> step
  99. */
  100. loadServices: function () {
  101. var servicesInfo = App.db.getService();
  102. servicesInfo.forEach(function (item, index) {
  103. servicesInfo[index] = Em.Object.create(item);
  104. });
  105. this.set('content.services', servicesInfo);
  106. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  107. var serviceNames = servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName');
  108. console.log('selected services ', serviceNames);
  109. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  110. },
  111. /**
  112. * Save data to model
  113. * @param stepController App.WizardStep4Controller
  114. */
  115. saveServices: function (stepController) {var serviceNames = [];
  116. App.db.setService(stepController.get('content'));
  117. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  118. stepController.filterProperty('isSelected', true).filterProperty('isInstalled', false).forEach(function (item) {
  119. serviceNames.push(item.serviceName);
  120. });
  121. this.set('content.selectedServiceNames', serviceNames);
  122. App.db.setSelectedServiceNames(serviceNames);
  123. console.log('AddServiceController.selectedServiceNames:', serviceNames);
  124. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  125. },
  126. /**
  127. * Save Master Component Hosts data to Main Controller
  128. * @param stepController App.WizardStep5Controller
  129. */
  130. saveMasterComponentHosts: function (stepController) {
  131. var obj = stepController.get('selectedServicesMasters');
  132. var masterComponentHosts = [];
  133. var installedComponents = App.HostComponent.find();
  134. obj.forEach(function (_component) {
  135. masterComponentHosts.push({
  136. display_name: _component.display_name,
  137. component: _component.component_name,
  138. hostName: _component.selectedHost,
  139. serviceId: _component.serviceId,
  140. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  141. });
  142. });
  143. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  144. App.db.setMasterComponentHosts(masterComponentHosts);
  145. this.set('content.masterComponentHosts', masterComponentHosts);
  146. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  147. },
  148. /**
  149. * Load master component hosts data for using in required step controllers
  150. */
  151. loadMasterComponentHosts: function () {
  152. var masterComponentHosts = App.db.getMasterComponentHosts();
  153. if(!masterComponentHosts){
  154. masterComponentHosts = [];
  155. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  156. masterComponentHosts.push({
  157. component: item.get('componentName'),
  158. hostName: item.get('host.hostName'),
  159. isInstalled: true
  160. })
  161. });
  162. }
  163. this.set("content.masterComponentHosts", masterComponentHosts);
  164. console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  165. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  166. },
  167. /**
  168. * return slaveComponents bound to hosts
  169. * @return {Array}
  170. */
  171. getSlaveComponentHosts: function () {
  172. var components = [{
  173. name : 'DATANODE',
  174. service : 'HDFS'
  175. },
  176. {
  177. name: 'TASKTRACKER',
  178. service: 'MAPREDUCE'
  179. },{
  180. name: 'HBASE_REGIONSERVER',
  181. service: 'HBASE'
  182. }];
  183. var result = [];
  184. var services = App.Service.find();
  185. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  186. for(var index=0; index < components.length; index++){
  187. var comp = components[index];
  188. if(!selectedServices.contains(comp.service)){
  189. continue;
  190. }
  191. var service = services.findProperty('id', comp.service);
  192. var hosts = [];
  193. if(!service){
  194. service = services.findProperty('id', 'HDFS');
  195. service.get('hostComponents').filterProperty('componentName', 'DATANODE').forEach(function (host_component) {
  196. hosts.push({
  197. group: "Default",
  198. hostName: host_component.get('host.id'),
  199. isInstalled: false
  200. });
  201. }, this);
  202. } else {
  203. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  204. hosts.push({
  205. group: "Default",
  206. hostName: host_component.get('host.id'),
  207. isInstalled: true
  208. });
  209. }, this);
  210. }
  211. result.push({
  212. componentName: comp.name,
  213. displayName: App.format.role(comp.name),
  214. hosts: hosts
  215. })
  216. }
  217. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  218. var hosts = [];
  219. clientsHosts.forEach(function (host_component) {
  220. hosts.push({
  221. group: "Default",
  222. hostName: host_component.get('host.id'),
  223. isInstalled: true
  224. });
  225. }, this);
  226. result.push({
  227. componentName: 'CLIENT',
  228. displayName: 'client',
  229. hosts: hosts
  230. })
  231. return result;
  232. },
  233. /**
  234. * Load master component hosts data for using in required step controllers
  235. */
  236. loadSlaveComponentHosts: function () {
  237. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  238. if(!slaveComponentHosts){
  239. slaveComponentHosts = this.getSlaveComponentHosts();
  240. }
  241. this.set("content.slaveComponentHosts", slaveComponentHosts);
  242. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  243. },
  244. /**
  245. * Load information about hosts with clients components
  246. */
  247. loadClients: function(){
  248. var clients = App.db.getClientsForSelectedServices();
  249. this.set('content.clients', clients);
  250. console.log("AddServiceController.loadClients: loaded list ", clients);
  251. },
  252. /**
  253. * Generate clients list for selected services and save it to model
  254. * @param stepController step4WizardController
  255. */
  256. saveClients: function(stepController){
  257. var clients = [];
  258. var serviceComponents = require('data/service_components');
  259. var hostComponents = App.HostComponent.find();
  260. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  261. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  262. if (client) {
  263. clients.pushObject({
  264. component_name: client.component_name,
  265. display_name: client.display_name,
  266. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  267. });
  268. }
  269. }, this);
  270. App.db.setClientsForSelectedServices(clients);
  271. this.set('content.clients', clients);
  272. console.log("AddServiceController.saveClients: saved list ", clients);
  273. },
  274. /**
  275. * Load data for all steps until <code>current step</code>
  276. */
  277. loadAllPriorSteps: function () {
  278. var step = this.get('currentStep');
  279. switch (step) {
  280. case '7':
  281. case '6':
  282. case '5':
  283. this.load('cluster');
  284. case '4':
  285. this.loadServiceConfigProperties();
  286. case '3':
  287. this.loadServices();
  288. this.loadClients();
  289. this.loadSlaveComponentHosts();//depends on loadServices
  290. case '2':
  291. this.loadMasterComponentHosts();
  292. this.loadConfirmedHosts();
  293. case '1':
  294. this.loadServices();
  295. }
  296. },
  297. /**
  298. * Remove all loaded data.
  299. * Created as copy for App.router.clearAllSteps
  300. */
  301. clearAllSteps: function () {
  302. this.clearInstallOptions();
  303. // clear temporary information stored during the install
  304. this.set('content.cluster', this.getCluster());
  305. },
  306. /**
  307. * Clear all temporary data
  308. */
  309. finish: function () {
  310. this.setCurrentStep('1');
  311. this.clearAllSteps();
  312. this.clearStorageData();
  313. App.router.get('updateController').updateAll();
  314. }
  315. });