add_controller.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. serviceToInstall: function() {
  27. return App.get('router.mainAdminStackAndUpgradeController.serviceToInstall');
  28. }.property('App.router.mainAdminStackAndUpgradeController.serviceToInstall'),
  29. /**
  30. * All wizards data will be stored in this variable
  31. *
  32. * cluster - cluster name
  33. * installOptions - ssh key, repo info, etc.
  34. * services - services list
  35. * hosts - list of selected hosts
  36. * slaveComponentHosts, - info about slave hosts
  37. * masterComponentHosts - info about master hosts
  38. * config??? - to be described later
  39. */
  40. content: Em.Object.create({
  41. cluster: null,
  42. hosts: null,
  43. installOptions: null,
  44. services: null,
  45. slaveComponentHosts: null,
  46. masterComponentHosts: null,
  47. serviceConfigProperties: null,
  48. advancedServiceConfig: null,
  49. controllerName: 'addServiceController',
  50. configGroups: [],
  51. clients: [],
  52. additionalClients: [],
  53. smokeuser: "ambari-qa",
  54. group: "hadoop"
  55. }),
  56. setCurrentStep: function (currentStep, completed) {
  57. this._super(currentStep, completed);
  58. App.clusterStatus.setClusterStatus({
  59. wizardControllerName: this.get('name'),
  60. localdb: App.db.data
  61. });
  62. },
  63. /**
  64. * Load services data. Will be used at <code>Select services(step4)</code> step
  65. */
  66. loadServices: function () {
  67. var services = this.getDBProperty('services');
  68. if (!services) {
  69. services = {
  70. selectedServices: [],
  71. installedServices: []
  72. };
  73. App.StackService.find().forEach(function (item) {
  74. var isInstalled = App.Service.find().someProperty('id', item.get('serviceName'));
  75. var isSelected = item.get('serviceName') == this.get('serviceToInstall');
  76. item.set('isSelected', isInstalled || isSelected);
  77. item.set('isInstalled', isInstalled);
  78. if (isInstalled) {
  79. services.selectedServices.push(item.get('serviceName'));
  80. services.installedServices.push(item.get('serviceName'));
  81. } else if(isSelected) {
  82. services.selectedServices.push(item.get('serviceName'));
  83. }
  84. }, this);
  85. this.setDBProperty('services', services);
  86. } else {
  87. App.StackService.find().forEach(function (item) {
  88. var isSelected = services.selectedServices.contains(item.get('serviceName')) || item.get('serviceName') == this.get('serviceToInstall');
  89. var isInstalled = services.installedServices.contains(item.get('serviceName'));
  90. item.set('isSelected', isSelected || (this.get("currentStep") == "1" ? isInstalled : isSelected));
  91. item.set('isInstalled', isInstalled);
  92. }, this);
  93. var isServiceWithSlave = App.StackService.find().filterProperty('isSelected').filterProperty('hasSlave').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  94. var isServiceWithClient = App.StackService.find().filterProperty('isSelected').filterProperty('hasClient').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  95. this.set('content.skipSlavesStep', !isServiceWithSlave && !isServiceWithClient);
  96. if (this.get('content.skipSlavesStep')) {
  97. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  98. }
  99. }
  100. this.set('content.services', App.StackService.find());
  101. },
  102. /**
  103. * Save data to model
  104. * @param stepController App.WizardStep4Controller
  105. */
  106. saveServices: function (stepController) {
  107. var services = {
  108. selectedServices: [],
  109. installedServices: []
  110. };
  111. var selectedServices = stepController.get('content').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  112. services.selectedServices.pushObjects(selectedServices);
  113. services.installedServices.pushObjects(stepController.get('content').filterProperty('isInstalled', true).mapProperty('serviceName'));
  114. this.setDBProperty('services', services);
  115. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  116. this.set('content.selectedServiceNames', selectedServices);
  117. this.setDBProperty('selectedServiceNames', selectedServices);
  118. var isServiceWithSlave = stepController.get('content').filterProperty('isSelected').filterProperty('hasSlave').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  119. var isServiceWithClient = App.StackService.find().filterProperty('isSelected').filterProperty('hasClient').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  120. this.set('content.skipSlavesStep', !isServiceWithSlave && !isServiceWithClient);
  121. if (this.get('content.skipSlavesStep')) {
  122. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  123. }
  124. },
  125. /**
  126. * Save Master Component Hosts data to Main Controller
  127. * @param stepController App.WizardStep5Controller
  128. */
  129. saveMasterComponentHosts: function (stepController) {
  130. var obj = stepController.get('selectedServicesMasters');
  131. var masterComponentHosts = [];
  132. var installedComponents = App.HostComponent.find();
  133. obj.forEach(function (_component) {
  134. var installedComponent = installedComponents.findProperty('componentName', _component.component_name);
  135. masterComponentHosts.push({
  136. display_name: _component.display_name,
  137. component: _component.component_name,
  138. hostName: _component.selectedHost,
  139. serviceId: _component.serviceId,
  140. isInstalled: !!installedComponent,
  141. workStatus: installedComponent && installedComponent.get('workStatus')
  142. });
  143. });
  144. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  145. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  146. this.set('content.masterComponentHosts', masterComponentHosts);
  147. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  148. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  149. },
  150. /**
  151. * Load master component hosts data for using in required step controllers
  152. */
  153. loadMasterComponentHosts: function () {
  154. this._super();
  155. this.set('content.skipMasterStep', App.StackService.find().filterProperty('isSelected').filterProperty('hasMaster').everyProperty('isInstalled', true));
  156. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  157. },
  158. /**
  159. * Does service have any configs
  160. * @param {string} serviceName
  161. * @returns {boolean}
  162. */
  163. isServiceNotConfigurable: function (serviceName) {
  164. return App.get('services.noConfigTypes').contains(serviceName);
  165. },
  166. /**
  167. * Should Config Step be skipped (based on selected services list)
  168. * @returns {boolean}
  169. */
  170. skipConfigStep: function () {
  171. var skipConfigStep = true;
  172. var selectedServices = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  173. selectedServices.map(function (serviceName) {
  174. skipConfigStep = skipConfigStep && this.isServiceNotConfigurable(serviceName);
  175. }, this);
  176. return skipConfigStep;
  177. },
  178. loadServiceConfigProperties: function () {
  179. this._super();
  180. if (!this.get('content.services')) {
  181. this.loadServices();
  182. }
  183. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  184. this.set('content.skipConfigStep', this.skipConfigStep());
  185. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  186. }
  187. },
  188. saveServiceConfigProperties: function (stepController) {
  189. this._super(stepController);
  190. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  191. this.set('content.skipConfigStep', this.skipConfigStep());
  192. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  193. }
  194. },
  195. /**
  196. * Load master component hosts data for using in required step controllers
  197. */
  198. loadSlaveComponentHosts: function () {
  199. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts'),
  200. hosts = this.getDBProperty('hosts'),
  201. host_names = Em.keys(hosts);
  202. if (!Em.isNone(slaveComponentHosts)) {
  203. slaveComponentHosts.forEach(function (component) {
  204. component.hosts.forEach(function (host) {
  205. //Em.set(host, 'hostName', hosts[host.host_id].name);
  206. for (var i = 0; i < host_names.length; i++) {
  207. if (hosts[host_names[i]].id === host.host_id) {
  208. host.hostName = host_names[i];
  209. break;
  210. }
  211. }
  212. });
  213. });
  214. }
  215. if (!slaveComponentHosts) {
  216. slaveComponentHosts = this.getSlaveComponentHosts();
  217. }
  218. this.set("content.slaveComponentHosts", slaveComponentHosts);
  219. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  220. },
  221. /**
  222. * return slaveComponents bound to hosts
  223. * @return {Array}
  224. */
  225. getSlaveComponentHosts: function () {
  226. var components = this.get('slaveComponents');
  227. var result = [];
  228. var installedServices = App.Service.find().mapProperty('serviceName');
  229. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  230. var installedComponentsMap = {};
  231. var uninstalledComponents = [];
  232. var hosts = this.get('content.hosts');
  233. var masterComponents = App.get('components.masters');
  234. var nonMasterComponentHosts = [];
  235. components.forEach(function (component) {
  236. if (installedServices.contains(component.get('serviceName'))) {
  237. installedComponentsMap[component.get('componentName')] = [];
  238. } else if (selectedServices.contains(component.get('serviceName'))) {
  239. uninstalledComponents.push(component);
  240. }
  241. }, this);
  242. for (var hostName in hosts) {
  243. if (hosts[hostName].isInstalled) {
  244. var isMasterComponentHosted = false;
  245. hosts[hostName].hostComponents.forEach(function (component) {
  246. if (installedComponentsMap[component.HostRoles.component_name]) {
  247. installedComponentsMap[component.HostRoles.component_name].push(hostName);
  248. }
  249. if (masterComponents.contains(component.HostRoles.component_name)) {
  250. isMasterComponentHosted = true;
  251. }
  252. }, this);
  253. if (!isMasterComponentHosted) {
  254. nonMasterComponentHosts.push(hostName);
  255. }
  256. }
  257. }
  258. for (var componentName in installedComponentsMap) {
  259. var component = {
  260. componentName: componentName,
  261. displayName: App.format.role(componentName),
  262. hosts: [],
  263. isInstalled: true
  264. };
  265. installedComponentsMap[componentName].forEach(function (hostName) {
  266. component.hosts.push({
  267. group: "Default",
  268. hostName: hostName,
  269. isInstalled: true
  270. });
  271. }, this);
  272. result.push(component);
  273. }
  274. if (!nonMasterComponentHosts.length) {
  275. nonMasterComponentHosts.push(Object.keys(this.get('content.hosts'))[0]);
  276. }
  277. var uninstalledComponentHosts = nonMasterComponentHosts.map(function(_hostName){
  278. return {
  279. group: "Default",
  280. hostName: _hostName,
  281. isInstalled: false
  282. }
  283. });
  284. uninstalledComponents.forEach(function (component) {
  285. result.push({
  286. componentName: component.get('componentName'),
  287. displayName: App.format.role(component.get('componentName')),
  288. hosts: uninstalledComponentHosts,
  289. isInstalled: false
  290. })
  291. });
  292. return result;
  293. },
  294. /**
  295. * Generate clients list for selected services and save it to model
  296. * @param stepController step4WizardController
  297. */
  298. saveClients: function (stepController) {
  299. var clients = [];
  300. var serviceComponents = App.StackServiceComponent.find();
  301. this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled',false).forEach(function (_service) {
  302. var serviceClients = serviceComponents.filterProperty('serviceName', _service.get('serviceName')).filterProperty('isClient');
  303. serviceClients.forEach(function (client) {
  304. clients.push({
  305. component_name: client.get('componentName'),
  306. display_name: client.get('displayName'),
  307. isInstalled: false
  308. });
  309. }, this);
  310. }, this);
  311. this.setDBProperty('clientInfo', clients);
  312. this.set('content.clients', clients);
  313. console.log("AddServiceController.saveClients: saved list ", clients);
  314. },
  315. /**
  316. * Load data for all steps until <code>current step</code>
  317. */
  318. loadAllPriorSteps: function () {
  319. var step = this.get('currentStep');
  320. switch (step) {
  321. case '7':
  322. case '6':
  323. case '5':
  324. this.load('cluster');
  325. this.set('content.additionalClients', []);
  326. case '4':
  327. this.loadServiceConfigGroups();
  328. this.loadServiceConfigProperties();
  329. case '3':
  330. this.loadServices();
  331. this.loadClients();
  332. this.loadSlaveComponentHosts();//depends on loadServices
  333. case '2':
  334. this.loadMasterComponentHosts();
  335. this.load('hosts');
  336. case '1':
  337. this.loadServices();
  338. }
  339. },
  340. /**
  341. * Remove all loaded data.
  342. * Created as copy for App.router.clearAllSteps
  343. */
  344. clearAllSteps: function () {
  345. this.clearInstallOptions();
  346. // clear temporary information stored during the install
  347. this.set('content.cluster', this.getCluster());
  348. },
  349. /**
  350. * Clear all temporary data
  351. */
  352. finish: function () {
  353. this.clearAllSteps();
  354. this.clearStorageData();
  355. this.resetDbNamespace();
  356. App.router.get('updateController').updateAll();
  357. },
  358. /**
  359. * genarates data for ajax request to launch install services
  360. * @method generateDataForInstallServices
  361. * @param {Array} selectedServices
  362. * @returns {{context: *, ServiceInfo: {state: string}, urlParams: string}}
  363. */
  364. generateDataForInstallServices: function(selectedServices) {
  365. if (selectedServices.contains('OOZIE')) {
  366. selectedServices = selectedServices.concat(['HDFS', 'YARN', 'MAPREDUCE', 'MAPREDUCE2']);
  367. }
  368. return {
  369. "context": Em.I18n.t('requestInfo.installServices'),
  370. "ServiceInfo": {"state": "INSTALLED"},
  371. "urlParams": "ServiceInfo/service_name.in(" + selectedServices.join(',') + ")"
  372. };
  373. },
  374. installServices: function (callback) {
  375. this.set('content.cluster.oldRequestsId', []);
  376. this.installAdditionalClients();
  377. var name = 'common.services.update';
  378. var selectedServices = this.get('content.services').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
  379. var data = this.generateDataForInstallServices(selectedServices);
  380. this.installServicesRequest(name, data, callback);
  381. },
  382. installServicesRequest: function (name, data, callback) {
  383. callback = callback || Em.K;
  384. App.ajax.send({
  385. name: name,
  386. sender: this,
  387. data: data,
  388. success: 'installServicesSuccessCallback',
  389. error: 'installServicesErrorCallback'
  390. }).then(callback, callback);
  391. },
  392. /**
  393. * installs clients before install new services
  394. * on host where some components require this
  395. * @method installAdditionalClients
  396. */
  397. installAdditionalClients: function () {
  398. this.get('content.additionalClients').forEach(function (c) {
  399. if (c.hostNames.length > 0) {
  400. var queryStr = 'HostRoles/component_name='+ c.componentName + '&HostRoles/host_name.in(' + c.hostNames.join() + ')';
  401. App.ajax.send({
  402. name: 'common.host_component.update',
  403. sender: this,
  404. data: {
  405. query: queryStr,
  406. context: 'Install ' + App.format.role(c.componentName),
  407. HostRoles: {
  408. state: 'INSTALLED'
  409. }
  410. }
  411. });
  412. }
  413. }, this);
  414. }
  415. });