add_controller.js 16 KB

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