add_controller.js 17 KB

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