add_controller.js 16 KB

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