add_controller.js 17 KB

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