add_controller.js 17 KB

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