add_controller.js 16 KB

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