add_controller.js 16 KB

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