step5_controller.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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. var blueprintUtils = require('utils/blueprint');
  20. var numberUtils = require('utils/number_utils');
  21. var validationUtils = require('utils/validator');
  22. App.WizardStep5Controller = Em.Controller.extend(App.BlueprintMixin, {
  23. name: "wizardStep5Controller",
  24. /**
  25. * Step title
  26. * Custom if <code>App.ReassignMasterController</code> is used
  27. * @type {string}
  28. */
  29. title: function () {
  30. if (this.get('content.controllerName') == 'reassignMasterController') {
  31. return Em.I18n.t('installer.step5.reassign.header');
  32. }
  33. return Em.I18n.t('installer.step5.header');
  34. }.property('content.controllerName'),
  35. /**
  36. * Is ReassignWizard used
  37. * @type {bool}
  38. */
  39. isReassignWizard: function () {
  40. return this.get('content.controllerName') == 'reassignMasterController';
  41. }.property('content.controllerName'),
  42. /**
  43. * Is isHighAvailabilityWizard used
  44. * @type {bool}
  45. */
  46. isHighAvailabilityWizard: function () {
  47. return this.get('content.controllerName') == 'highAvailabilityWizardController';
  48. }.property('content.controllerName'),
  49. /**
  50. * Check if <code>installerWizard</code> used
  51. * @type {bool}
  52. */
  53. isInstallerWizard: function () {
  54. return this.get('content.controllerName') === 'installerController';
  55. }.property('content.controllerName'),
  56. /**
  57. * Is AddServiceWizard used
  58. * @type {bool}
  59. */
  60. isAddServiceWizard: function () {
  61. return this.get('content.controllerName') == 'addServiceController';
  62. }.property('content.controllerName'),
  63. /**
  64. * Master components which could be assigned to multiple hosts
  65. * @type {string[]}
  66. */
  67. multipleComponents: function () {
  68. return App.get('components.multipleMasters');
  69. }.property('App.components.multipleMasters'),
  70. /**
  71. * Master components which could be assigned to multiple hosts
  72. * @type {string[]}
  73. */
  74. addableComponents: function () {
  75. return App.get('components.addableMasterInstallerWizard');
  76. }.property('App.components.addableMasterInstallerWizard'),
  77. /**
  78. * Define state for submit button
  79. * @type {bool}
  80. */
  81. submitDisabled: false,
  82. /**
  83. * Trigger for executing host names check for components
  84. * Should de "triggered" when host changed for some component and when new multiple component is added/removed
  85. * @type {bool}
  86. */
  87. hostNameCheckTrigger: false,
  88. /**
  89. * List of hosts
  90. * @type {Array}
  91. */
  92. hosts: [],
  93. /**
  94. * Name of multiple component which host name was changed last
  95. * @type {Object|null}
  96. */
  97. componentToRebalance: null,
  98. /**
  99. * Name of component which host was changed last
  100. * @type {string}
  101. */
  102. lastChangedComponent: null,
  103. /**
  104. * Flag for rebalance multiple components
  105. * @type {number}
  106. */
  107. rebalanceComponentHostsCounter: 0,
  108. /**
  109. * @type {Ember.Enumerable}
  110. */
  111. servicesMasters: [],
  112. /**
  113. * @type {Ember.Enumerable}
  114. */
  115. selectedServicesMasters: [],
  116. /**
  117. * Is data for current step loaded
  118. * @type {bool}
  119. */
  120. isLoaded: false,
  121. /**
  122. * Validation error messages which don't related with any master
  123. */
  124. generalErrorMessages: [],
  125. /**
  126. * Validation warning messages which don't related with any master
  127. */
  128. generalWarningMessages: [],
  129. /**
  130. * true if any error exists
  131. */
  132. anyError: function() {
  133. return this.get('servicesMasters').some(function(m) { return m.get('errorMessage'); }) || this.get('generalErrorMessages').some(function(m) { return m; });
  134. }.property('servicesMasters.@each.errorMessage', 'generalErrorMessages'),
  135. /**
  136. * true if any warning exists
  137. */
  138. anyWarning: function() {
  139. return this.get('servicesMasters').some(function(m) { return m.get('warnMessage'); }) || this.get('generalWarningMessages').some(function(m) { return m; });
  140. }.property('servicesMasters.@each.warnMessage', 'generalWarningMessages'),
  141. /**
  142. * Clear loaded recommendations
  143. */
  144. clearRecommendations: function() {
  145. if (this.get('content.recommendations')) {
  146. this.set('content.recommendations', null);
  147. }
  148. },
  149. /**
  150. * List of host with assigned masters
  151. * Format:
  152. * <code>
  153. * [
  154. * {
  155. * host_name: '',
  156. * hostInfo: {},
  157. * masterServices: [],
  158. * masterServicesToDisplay: [] // used only in template
  159. * },
  160. * ....
  161. * ]
  162. * </code>
  163. * @type {Ember.Enumerable}
  164. */
  165. masterHostMapping: function () {
  166. var mapping = [], mappingObject, mappedHosts, hostObj;
  167. //get the unique assigned hosts and find the master services assigned to them
  168. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  169. mappedHosts.forEach(function (item) {
  170. hostObj = this.get("hosts").findProperty("host_name", item);
  171. // User may input invalid host name (this is handled in hostname checker). Here we just skip it
  172. if (!hostObj) return;
  173. var masterServices = this.get("selectedServicesMasters").filterProperty("selectedHost", item),
  174. masterServicesToDisplay = [];
  175. masterServices.mapProperty('display_name').uniq().forEach(function (n) {
  176. masterServicesToDisplay.pushObject(masterServices.findProperty('display_name', n));
  177. });
  178. mappingObject = Em.Object.create({
  179. host_name: item,
  180. hostInfo: hostObj.host_info,
  181. masterServices: masterServices,
  182. masterServicesToDisplay: masterServicesToDisplay
  183. });
  184. mapping.pushObject(mappingObject);
  185. }, this);
  186. return mapping.sortProperty('host_name');
  187. }.property("selectedServicesMasters.@each.selectedHost", 'selectedServicesMasters.@each.isHostNameValid'),
  188. /**
  189. * Count of hosts without masters
  190. * @type {number}
  191. */
  192. remainingHosts: function () {
  193. if (this.get('content.controllerName') === 'installerController') {
  194. return 0;
  195. } else {
  196. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  197. }
  198. }.property('masterHostMapping.length', 'selectedServicesMasters.@each.selectedHost'),
  199. /**
  200. * Update submit button status
  201. * @metohd updateIsSubmitDisabled
  202. */
  203. updateIsSubmitDisabled: function () {
  204. var self = this;
  205. if (self.thereIsNoMasters()) {
  206. return false;
  207. }
  208. if (App.get('supports.serverRecommendValidate')) {
  209. self.set('submitDisabled', true);
  210. // reset previous recommendations
  211. this.clearRecommendations();
  212. if (self.get('servicesMasters').length === 0) {
  213. return;
  214. }
  215. var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
  216. if (!isSubmitDisabled) {
  217. self.recommendAndValidate();
  218. }
  219. } else {
  220. var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
  221. self.set('submitDisabled', isSubmitDisabled);
  222. return isSubmitDisabled;
  223. }
  224. }.observes('servicesMasters.@each.selectedHost', 'servicesMasters.@each.isHostNameValid'),
  225. /**
  226. * Send AJAX request to validate current host layout
  227. * @param blueprint - blueprint for validation (can be with/withour slave/client components)
  228. */
  229. validate: function(blueprint, callback) {
  230. var self = this;
  231. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  232. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  233. var services = installedServices.concat(selectedServices).uniq();
  234. var hostNames = self.get('hosts').mapProperty('host_name');
  235. App.ajax.send({
  236. name: 'config.validations',
  237. sender: self,
  238. data: {
  239. stackVersionUrl: App.get('stackVersionURL'),
  240. hosts: hostNames,
  241. services: services,
  242. validate: 'host_groups',
  243. recommendations: blueprint
  244. },
  245. success: 'updateValidationsSuccessCallback',
  246. error: 'updateValidationsErrorCallback'
  247. }).
  248. then(function() {
  249. if (callback) {
  250. callback();
  251. }
  252. }
  253. );
  254. },
  255. /**
  256. * Success-callback for validations request
  257. * @param {object} data
  258. * @method updateValidationsSuccessCallback
  259. */
  260. updateValidationsSuccessCallback: function (data) {
  261. var self = this;
  262. var generalErrorMessages = [];
  263. var generalWarningMessages = [];
  264. this.get('servicesMasters').setEach('warnMessage', null);
  265. this.get('servicesMasters').setEach('errorMessage', null);
  266. var anyErrors = false;
  267. var validationData = validationUtils.filterNotInstalledComponents(data);
  268. validationData.filterProperty('type', 'host-component').forEach(function(item) {
  269. var master = self.get('servicesMasters').find(function(m) {
  270. return m.component_name === item['component-name'] && m.selectedHost === item.host;
  271. });
  272. if (master) {
  273. if (item.level === 'ERROR') {
  274. anyErrors = true;
  275. master.set('errorMessage', item.message);
  276. } else if (item.level === 'WARN') {
  277. master.set('warnMessage', item.message);
  278. }
  279. } else {
  280. var details = " (" + item['component-name'] + " on " + item.host + ")";
  281. if (item.level === 'ERROR') {
  282. anyErrors = true;
  283. generalErrorMessages.push(item.message + details);
  284. } else if (item.level === 'WARN') {
  285. generalWarningMessages.push(item.message + details);
  286. }
  287. }
  288. });
  289. this.set('generalErrorMessages', generalErrorMessages);
  290. this.set('generalWarningMessages', generalWarningMessages);
  291. // use this.set('submitDisabled', anyErrors); is validation results should block next button
  292. // It's because showValidationIssuesAcceptBox allow use accept validation issues and continue
  293. this.set('submitDisabled', false); //this.set('submitDisabled', anyErrors);
  294. },
  295. /**
  296. * Error-callback for validations request
  297. * @param {object} jqXHR
  298. * @param {object} ajaxOptions
  299. * @param {string} error
  300. * @param {object} opt
  301. * @method updateValidationsErrorCallback
  302. */
  303. updateValidationsErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  304. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.method, jqXHR.status);
  305. console.log('Load validations failed');
  306. },
  307. /**
  308. * Composes selected values of comboboxes into master blueprint + merge it with currenlty installed slave blueprint
  309. */
  310. getCurrentBlueprint: function() {
  311. var self = this;
  312. var res = {
  313. blueprint: { host_groups: [] },
  314. blueprint_cluster_binding: { host_groups: [] }
  315. };
  316. var mapping = self.get('masterHostMapping');
  317. mapping.forEach(function(item, i) {
  318. var group_name = 'host-group-' + (i+1);
  319. var host_group = {
  320. name: group_name,
  321. components: item.masterServices.map(function(master) {
  322. return { name: master.component_name };
  323. })
  324. };
  325. var binding = {
  326. name: group_name,
  327. hosts: [ { fqdn: item.host_name } ]
  328. };
  329. res.blueprint.host_groups.push(host_group);
  330. res.blueprint_cluster_binding.host_groups.push(binding);
  331. });
  332. return blueprintUtils.mergeBlueprints(res, self.getCurrentSlaveBlueprint());
  333. },
  334. /**
  335. * Clear controller data (hosts, masters etc)
  336. * @method clearStep
  337. */
  338. clearStep: function () {
  339. this.set('hosts', []);
  340. this.set('selectedServicesMasters', []);
  341. this.set('servicesMasters', []);
  342. App.StackServiceComponent.find().forEach(function (stackComponent) {
  343. stackComponent.set('serviceComponentId', 1);
  344. }, this);
  345. },
  346. /**
  347. * Load controller data (hosts, host components etc)
  348. * @method loadStep
  349. */
  350. loadStep: function () {
  351. console.log("WizardStep5Controller: Loading step5: Assign Masters");
  352. this.clearStep();
  353. this.renderHostInfo();
  354. if (App.get('supports.serverRecommendValidate')) {
  355. this.loadComponentsRecommendationsFromServer(this.loadStepCallback);
  356. } else {
  357. this.loadComponentsRecommendationsLocally(this.loadStepCallback);
  358. }
  359. },
  360. /**
  361. * Callback after load controller data (hosts, host components etc)
  362. * @method loadStepCallback
  363. */
  364. loadStepCallback: function(components, self) {
  365. self.renderComponents(components);
  366. self.get('addableComponents').forEach(function (componentName) {
  367. self.updateComponent(componentName);
  368. }, self);
  369. if (self.thereIsNoMasters()) {
  370. console.log('no master components to add');
  371. App.router.send('next');
  372. }
  373. },
  374. /**
  375. * Returns true if there is no new master components which need assigment to host
  376. */
  377. thereIsNoMasters: function() {
  378. return !this.get("selectedServicesMasters").filterProperty('isInstalled', false).length;
  379. },
  380. /**
  381. * Used to set showAddControl flag for installer wizard
  382. * @method updateComponent
  383. */
  384. updateComponent: function (componentName) {
  385. var component = this.last(componentName);
  386. if (!component) {
  387. return;
  388. }
  389. var services = App.StackService.find().filterProperty('isInstalled', true).mapProperty('serviceName');
  390. var currentService = componentName.split('_')[0];
  391. var showControl = !services.contains(currentService);
  392. if (showControl) {
  393. var mastersLength = this.get("selectedServicesMasters").filterProperty("component_name", componentName).length;
  394. if (mastersLength < this.get("hosts.length") && !this.get('isReassignWizard') && !this.get('isHighAvailabilityWizard')) {
  395. component.set('showAddControl', true);
  396. } else if (mastersLength == 1 || this.get('isReassignWizard') || this.get('isHighAvailabilityWizard')) {
  397. component.set('showRemoveControl', false);
  398. }
  399. }
  400. },
  401. /**
  402. * Load active host list to <code>hosts</code> variable
  403. * @method renderHostInfo
  404. */
  405. renderHostInfo: function () {
  406. var hostInfo = this.get('content.hosts');
  407. var result = [];
  408. for (var index in hostInfo) {
  409. var _host = hostInfo[index];
  410. if (_host.bootStatus === 'REGISTERED') {
  411. result.push(Em.Object.create({
  412. host_name: _host.name,
  413. cpu: _host.cpu,
  414. memory: _host.memory,
  415. disk_info: _host.disk_info,
  416. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  417. }));
  418. }
  419. }
  420. this.set("hosts", result);
  421. this.sortHosts(this.get('hosts'));
  422. this.set('isLoaded', true);
  423. },
  424. /**
  425. * Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
  426. * @param {object[]} hosts
  427. */
  428. sortHosts: function (hosts) {
  429. hosts.sort(function (a, b) {
  430. if (a.get('memory') == b.get('memory')) {
  431. if (a.get('cpu') == b.get('cpu')) {
  432. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  433. }
  434. return b.get('cpu') - a.get('cpu'); // cores desc
  435. }
  436. return b.get('memory') - a.get('memory'); // ram desc
  437. });
  438. },
  439. /**
  440. * Get recommendations info from API
  441. * @return {undefined}
  442. * @param function(componentInstallationobjects, this) callback
  443. * @param bool includeMasters
  444. */
  445. loadComponentsRecommendationsFromServer: function(callback, includeMasters) {
  446. var self = this;
  447. if (this.get('content.recommendations')) {
  448. // Don't do AJAX call if recommendations has been already received
  449. // But if user returns to previous step (selecting services), stored recommendations will be cleared in routers' next handler and AJAX call will be made again
  450. callback(self.createComponentInstallationObjects(), self);
  451. } else {
  452. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  453. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  454. var services = installedServices.concat(selectedServices).uniq();
  455. var hostNames = self.get('hosts').mapProperty('host_name');
  456. var data = {
  457. stackVersionUrl: App.get('stackVersionURL'),
  458. hosts: hostNames,
  459. services: services,
  460. recommend: 'host_groups'
  461. };
  462. if (includeMasters) {
  463. // Made partial recommendation request for reflect in blueprint host-layout changes which were made by user in UI
  464. data.recommendations = self.getCurrentBlueprint();
  465. } else if (!self.get('isInstallerWizard')) {
  466. data.recommendations = self.getCurrentMasterSlaveBlueprint();
  467. }
  468. return App.ajax.send({
  469. name: 'wizard.loadrecommendations',
  470. sender: self,
  471. data: data,
  472. success: 'loadRecommendationsSuccessCallback',
  473. error: 'loadRecommendationsErrorCallback'
  474. }).
  475. then(function () {
  476. callback(self.createComponentInstallationObjects(), self);
  477. });
  478. }
  479. },
  480. /**
  481. * Create components for displaying component-host comboboxes in UI assign dialog
  482. * expects content.recommendations will be filled with recommendations API call result
  483. * @return {Object[]}
  484. */
  485. createComponentInstallationObjects: function() {
  486. var self = this;
  487. var masterComponents = [];
  488. if (self.get('isAddServiceWizard')) {
  489. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnAddServiceAssignMasterPage');
  490. } else {
  491. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage');
  492. }
  493. var masterHosts = self.get('content.masterComponentHosts'); //saved to local storage info
  494. var selectedNotInstalledServices = self.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  495. var recommendations = this.get('content.recommendations');
  496. var resultComponents = [];
  497. var multipleComponentHasBeenAdded = {};
  498. recommendations.blueprint.host_groups.forEach(function(host_group) {
  499. var hosts = recommendations.blueprint_cluster_binding.host_groups.findProperty('name', host_group.name).hosts;
  500. hosts.forEach(function(host) {
  501. host_group.components.forEach(function(component) {
  502. var willBeAdded = true;
  503. var fullComponent = masterComponents.findProperty('componentName', component.name);
  504. // If it's master component which should be shown
  505. if (fullComponent) {
  506. // If service is already installed and not being added as a new service then render on UI only those master components
  507. // that have already installed hostComponents.
  508. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  509. var isNotSelectedService = !selectedNotInstalledServices.contains(fullComponent.get('serviceName'));
  510. if (isNotSelectedService) {
  511. willBeAdded = App.HostComponent.find().someProperty('componentName', component.name);
  512. }
  513. if (willBeAdded) {
  514. var savedComponents = masterHosts.filterProperty('component', component.name);
  515. if (self.get('multipleComponents').contains(component.name) && savedComponents.length > 0) {
  516. if (!multipleComponentHasBeenAdded[component.name]) {
  517. multipleComponentHasBeenAdded[component.name] = true;
  518. savedComponents.forEach(function(saved) {
  519. resultComponents.push(self.createComponentInstallationObject(fullComponent, host.fqdn, saved));
  520. });
  521. }
  522. } else {
  523. var savedComponent = masterHosts.findProperty('component', component.name);
  524. resultComponents.push(self.createComponentInstallationObject(fullComponent, host.fqdn, savedComponent));
  525. }
  526. }
  527. }
  528. });
  529. });
  530. });
  531. return resultComponents;
  532. },
  533. /**
  534. * Create component for displaying component-host comboboxes in UI assign dialog
  535. * @param fullComponent - full component description
  536. * @param hostName - host fqdn where component will be installed
  537. * @param savedComponent - the same object which function returns but created before
  538. * @return {Object}
  539. */
  540. createComponentInstallationObject: function(fullComponent, hostName, savedComponent) {
  541. var componentName = fullComponent.get('componentName');
  542. var componentObj = {};
  543. componentObj.component_name = componentName;
  544. componentObj.display_name = App.format.role(fullComponent.get('componentName'));
  545. componentObj.serviceId = fullComponent.get('serviceName');
  546. componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', componentName).get('isCoHostedComponent') && !this.get('isReassignWizard');
  547. if (savedComponent) {
  548. componentObj.selectedHost = savedComponent.hostName;
  549. componentObj.isInstalled = savedComponent.isInstalled;
  550. } else {
  551. componentObj.selectedHost = hostName;
  552. componentObj.isInstalled = false;
  553. }
  554. return componentObj;
  555. },
  556. /**
  557. * Success-callback for recommendations request
  558. * @param {object} data
  559. * @method loadRecommendationsSuccessCallback
  560. */
  561. loadRecommendationsSuccessCallback: function (data) {
  562. this.set('content.recommendations', data.resources[0].recommendations);
  563. },
  564. /**
  565. * Error-callback for recommendations request
  566. * @param {object} jqXHR
  567. * @param {object} ajaxOptions
  568. * @param {string} error
  569. * @param {object} opt
  570. * @method loadRecommendationsErrorCallback
  571. */
  572. loadRecommendationsErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  573. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.method, jqXHR.status);
  574. console.log('Load recommendations failed');
  575. },
  576. /**
  577. * Load services info to appropriate variable and return masterComponentHosts
  578. * @return {Object[]}
  579. */
  580. loadComponentsRecommendationsLocally: function (callback) {
  581. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  582. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  583. var services = installedServices.concat(selectedServices).uniq();
  584. var selectedNotInstalledServices = this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  585. var masterComponents = [];
  586. //get full list from mock data
  587. if (this.get('isAddServiceWizard')) {
  588. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnAddServiceAssignMasterPage');
  589. } else {
  590. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage');
  591. }
  592. var masterHosts = this.get('content.masterComponentHosts'); //saved to local storage info
  593. var resultComponents = [];
  594. for (var index = 0; index < services.length; index++) {
  595. var componentInfo = masterComponents.filterProperty('serviceName', services[index]);
  596. // If service is already installed and not being added as a new service then render on UI only those master components
  597. // that have already installed hostComponents.
  598. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  599. var isNotSelectedService = !selectedNotInstalledServices.contains(services[index]);
  600. if (isNotSelectedService) {
  601. componentInfo = componentInfo.filter(function (_component) {
  602. return App.HostComponent.find().someProperty('componentName',_component.get('componentName'));
  603. });
  604. }
  605. componentInfo.forEach(function (_componentInfo) {
  606. if (this.get('multipleComponents').contains(_componentInfo.get('componentName'))) {
  607. var savedComponents = masterHosts.filterProperty('component', _componentInfo.get('componentName'));
  608. if (savedComponents.length) {
  609. savedComponents.forEach(function (item) {
  610. var multipleMasterHost = {};
  611. multipleMasterHost.component_name = _componentInfo.get('componentName');
  612. multipleMasterHost.display_name = _componentInfo.get('displayName');
  613. multipleMasterHost.selectedHost = item.hostName;
  614. multipleMasterHost.serviceId = services[index];
  615. multipleMasterHost.isInstalled = item.isInstalled;
  616. multipleMasterHost.isServiceCoHost = false;
  617. resultComponents.push(multipleMasterHost);
  618. })
  619. } else {
  620. var multipleMasterHosts = this.selectHostLocally(_componentInfo.get('componentName'));
  621. multipleMasterHosts.forEach(function (_host) {
  622. var multipleMasterHost = {};
  623. multipleMasterHost.component_name = _componentInfo.get('componentName');
  624. multipleMasterHost.display_name = _componentInfo.get('displayName');
  625. multipleMasterHost.selectedHost = _host;
  626. multipleMasterHost.serviceId = services[index];
  627. multipleMasterHost.isInstalled = false;
  628. multipleMasterHost.isServiceCoHost = false;
  629. resultComponents.push(multipleMasterHost);
  630. });
  631. }
  632. } else {
  633. var savedComponent = masterHosts.findProperty('component', _componentInfo.get('componentName'));
  634. var componentObj = {};
  635. componentObj.component_name = _componentInfo.get('componentName');
  636. componentObj.display_name = _componentInfo.get('displayName');
  637. componentObj.selectedHost = savedComponent ? savedComponent.hostName : this.selectHostLocally(_componentInfo.get('componentName')); // call the method that plays selectNode algorithm or fetches from server
  638. componentObj.isInstalled = savedComponent ? savedComponent.isInstalled : false;
  639. componentObj.serviceId = services[index];
  640. componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', _componentInfo.get('componentName')).get('isCoHostedComponent') && !this.get('isReassignWizard');
  641. resultComponents.push(componentObj);
  642. }
  643. }, this);
  644. }
  645. callback(resultComponents, this);
  646. },
  647. /**
  648. * @param {string} componentName
  649. * @returns {bool}
  650. * @private
  651. * @method _isHiveCoHost
  652. */
  653. _isHiveCoHost: function (componentName) {
  654. return ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName) && !this.get('isReassignWizard');
  655. },
  656. /**
  657. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  658. * @param {Ember.Enumerable} masterComponents
  659. * @method renderComponents
  660. */
  661. renderComponents: function (masterComponents) {
  662. var installedServices = App.StackService.find().filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName'); //list of shown services
  663. var result = [];
  664. var serviceComponentId, previousComponentName;
  665. masterComponents.forEach(function (item) {
  666. var serviceComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  667. var showRemoveControl = installedServices.contains(serviceComponent.get('stackService.serviceName')) &&
  668. (masterComponents.filterProperty('component_name', item.component_name).length > 1);
  669. var componentObj = Em.Object.create(item);
  670. console.log("TRACE: render master component name is: " + item.component_name);
  671. var masterComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  672. if (masterComponent.get('isMasterWithMultipleInstances')) {
  673. previousComponentName = item.component_name;
  674. componentObj.set('serviceComponentId', result.filterProperty('component_name', item.component_name).length + 1);
  675. componentObj.set("showRemoveControl", showRemoveControl);
  676. }
  677. componentObj.set('isHostNameValid', true);
  678. result.push(componentObj);
  679. }, this);
  680. result = this.sortComponentsByServiceName(result);
  681. this.set("selectedServicesMasters", result);
  682. if (this.get('isReassignWizard')) {
  683. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  684. components.setEach('isInstalled', false);
  685. this.set('servicesMasters', components);
  686. } else {
  687. this.set('servicesMasters', result);
  688. }
  689. },
  690. sortComponentsByServiceName: function(components) {
  691. var displayOrder = App.StackService.displayOrder;
  692. return components.sort(function (a, b) {
  693. var aValue = displayOrder.indexOf(a.serviceId) != -1 ? displayOrder.indexOf(a.serviceId) : components.length;
  694. var bValue = displayOrder.indexOf(b.serviceId) != -1 ? displayOrder.indexOf(b.serviceId) : components.length;
  695. return aValue - bValue;
  696. });
  697. },
  698. /**
  699. * Update dependent co-hosted components according to the change in the component host
  700. * @method updateCoHosts
  701. */
  702. updateCoHosts: function () {
  703. var components = App.StackServiceComponent.find().filterProperty('isOtherComponentCoHosted');
  704. var selectedServicesMasters = this.get('selectedServicesMasters');
  705. components.forEach(function (component) {
  706. var componentName = component.get('componentName');
  707. var hostComponent = selectedServicesMasters.findProperty('component_name', componentName);
  708. var dependentCoHosts = component.get('coHostedComponents');
  709. dependentCoHosts.forEach(function (coHostedComponent) {
  710. var dependentHostComponent = selectedServicesMasters.findProperty('component_name', coHostedComponent);
  711. if (hostComponent && dependentHostComponent) dependentHostComponent.set('selectedHost', hostComponent.get('selectedHost'));
  712. }, this);
  713. }, this);
  714. }.observes('selectedServicesMasters.@each.selectedHost'),
  715. /**
  716. * select and return host for component by scheme
  717. * Scheme is an object that has keys which compared to number of hosts,
  718. * if key more that number of hosts, then return value of that key.
  719. * Value is index of host in hosts array.
  720. *
  721. * @param {object} componentName
  722. * @param {object} hosts
  723. * @return {string}
  724. * @method getHostForComponent
  725. */
  726. getHostForComponent: function (componentName, hosts) {
  727. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  728. if (component) {
  729. var selectionScheme = App.StackServiceComponent.find().findProperty('componentName', componentName).get('selectionSchemeForMasterComponent');
  730. } else {
  731. return hosts[0];
  732. }
  733. if (hosts.length === 1 || $.isEmptyObject(selectionScheme)) {
  734. return hosts[0];
  735. } else {
  736. for (var i in selectionScheme) {
  737. if (window.isFinite(i)) {
  738. if (hosts.length < window.parseInt(i)) {
  739. return hosts[selectionScheme[i]];
  740. }
  741. }
  742. }
  743. return hosts[selectionScheme['else']]
  744. }
  745. },
  746. /**
  747. * Get list of host names for master component with multiple instances
  748. * @param {Object} component
  749. * @param {Object} hosts
  750. * @returns {string[]}
  751. * @method getHostsForComponent
  752. */
  753. getHostsForComponent: function (component, hosts) {
  754. var defaultNoOfMasterHosts = component.get('defaultNoOfMasterHosts');
  755. var masterHosts = [];
  756. if (hosts.length < defaultNoOfMasterHosts) {
  757. defaultNoOfMasterHosts = hosts.length;
  758. }
  759. for (var index = 0; index < defaultNoOfMasterHosts; index++) {
  760. masterHosts.push(hosts[index]);
  761. }
  762. return masterHosts;
  763. },
  764. /**
  765. * Return hostName of masterNode for specified service
  766. * @param componentName
  767. * @return {string|string[]}
  768. * @method selectHostLocally
  769. */
  770. selectHostLocally: function (componentName) {
  771. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  772. var hostNames = this.get('hosts').mapProperty('host_name');
  773. if (hostNames.length > 1 && App.StackServiceComponent.find().filterProperty('isNotPreferableOnAmbariServerHost').mapProperty('componentName').contains(componentName)) {
  774. hostNames = this.get('hosts').mapProperty('host_name').filter(function (item) {
  775. return item !== location.hostname;
  776. }, this);
  777. }
  778. if (this.get('multipleComponents').contains(componentName)) {
  779. if (component.get('defaultNoOfMasterHosts') > 1) {
  780. return this.getHostsForComponent(component, hostNames);
  781. } else {
  782. return [this.getHostForComponent(componentName, hostNames)];
  783. }
  784. } else {
  785. return this.getHostForComponent(componentName, hostNames);
  786. }
  787. },
  788. /**
  789. * On change callback for inputs
  790. * @param {string} componentName
  791. * @param {string} selectedHost
  792. * @param {number} serviceComponentId
  793. * @method assignHostToMaster
  794. */
  795. assignHostToMaster: function (componentName, selectedHost, serviceComponentId) {
  796. var flag = this.isHostNameValid(componentName, selectedHost);
  797. this.updateIsHostNameValidFlag(componentName, serviceComponentId, flag);
  798. if (serviceComponentId) {
  799. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("selectedHost", selectedHost);
  800. }
  801. else {
  802. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  803. }
  804. },
  805. /**
  806. * Determines if hostName is valid for component:
  807. * <ul>
  808. * <li>host name shouldn't be empty</li>
  809. * <li>host should exist</li>
  810. * <li>host should have only one component with <code>componentName</code></li>
  811. * </ul>
  812. * @param {string} componentName
  813. * @param {string} selectedHost
  814. * @returns {boolean} true - valid, false - invalid
  815. * @method isHostNameValid
  816. */
  817. isHostNameValid: function (componentName, selectedHost) {
  818. return (selectedHost.trim() !== '') &&
  819. this.get('hosts').mapProperty('host_name').contains(selectedHost) &&
  820. (this.get('selectedServicesMasters').
  821. filterProperty('component_name', componentName).
  822. mapProperty('selectedHost').
  823. filter(function (h) {
  824. return h === selectedHost;
  825. }).length <= 1);
  826. },
  827. /**
  828. * Update <code>isHostNameValid</code> property with <code>flag</code> value
  829. * for component with name <code>componentName</code> and
  830. * <code>serviceComponentId</code>-property equal to <code>serviceComponentId</code>-parameter value
  831. * @param {string} componentName
  832. * @param {number} serviceComponentId
  833. * @param {bool} flag
  834. * @method updateIsHostNameValidFlag
  835. */
  836. updateIsHostNameValidFlag: function (componentName, serviceComponentId, flag) {
  837. if (componentName) {
  838. if (serviceComponentId) {
  839. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("isHostNameValid", flag);
  840. } else {
  841. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("isHostNameValid", flag);
  842. }
  843. }
  844. },
  845. /**
  846. * Returns last component of selected type
  847. * @param {string} componentName
  848. * @return {Em.Object|null}
  849. * @method last
  850. */
  851. last: function (componentName) {
  852. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  853. },
  854. /**
  855. * Add new component to ZooKeeper Server and Hbase master
  856. * @param {string} componentName
  857. * @return {bool} true - added, false - not added
  858. * @method addComponent
  859. */
  860. addComponent: function (componentName) {
  861. /*
  862. * Logic: If ZooKeeper or Hbase service is selected then there can be
  863. * minimum 1 ZooKeeper or Hbase master in total, and
  864. * maximum 1 ZooKeeper or Hbase on every host
  865. */
  866. var maxNumMasters = this.get("hosts.length"),
  867. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  868. newMaster = null,
  869. masterHosts = null,
  870. suggestedHost = null,
  871. i = 0,
  872. lastMaster = null;
  873. if (!currentMasters.length) {
  874. console.log('ALERT: Zookeeper service was not selected');
  875. return false;
  876. }
  877. if (currentMasters.get("length") < maxNumMasters) {
  878. currentMasters.set("lastObject.showAddControl", false);
  879. currentMasters.set("lastObject.showRemoveControl", true);
  880. //create a new master component host based on an existing one
  881. newMaster = Em.Object.create({});
  882. lastMaster = currentMasters.get("lastObject");
  883. newMaster.set("display_name", lastMaster.get("display_name"));
  884. newMaster.set("component_name", lastMaster.get("component_name"));
  885. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  886. newMaster.set("serviceId", lastMaster.get("serviceId"));
  887. newMaster.set("isInstalled", false);
  888. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  889. newMaster.set("showAddControl", false);
  890. } else {
  891. newMaster.set("showAddControl", true);
  892. }
  893. newMaster.set("showRemoveControl", true);
  894. //get recommended host for the new Zookeeper server
  895. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  896. for (i = 0; i < this.get("hosts.length"); i++) {
  897. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  898. suggestedHost = this.get("hosts")[i].get("host_name");
  899. break;
  900. }
  901. }
  902. newMaster.set("selectedHost", suggestedHost);
  903. newMaster.set("serviceComponentId", (currentMasters.get("lastObject.serviceComponentId") + 1));
  904. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  905. this.set('componentToRebalance', componentName);
  906. this.incrementProperty('rebalanceComponentHostsCounter');
  907. this.toggleProperty('hostNameCheckTrigger');
  908. return true;
  909. }
  910. return false;//if no more zookeepers can be added
  911. },
  912. /**
  913. * Remove component from ZooKeeper server or Hbase Master
  914. * @param {string} componentName
  915. * @param {number} serviceComponentId
  916. * @return {bool} true - removed, false - no
  917. * @method removeComponent
  918. */
  919. removeComponent: function (componentName, serviceComponentId) {
  920. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  921. //work only if the multiple master service is selected in previous step
  922. if (currentMasters.length <= 1) {
  923. return false;
  924. }
  925. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("serviceComponentId", serviceComponentId)));
  926. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  927. if (currentMasters.get("length") < this.get("hosts.length")) {
  928. currentMasters.set("lastObject.showAddControl", true);
  929. }
  930. if (currentMasters.get("length") === 1) {
  931. currentMasters.set("lastObject.showRemoveControl", false);
  932. }
  933. this.set('componentToRebalance', componentName);
  934. this.incrementProperty('rebalanceComponentHostsCounter');
  935. this.toggleProperty('hostNameCheckTrigger');
  936. return true;
  937. },
  938. recommendAndValidate: function(callback) {
  939. var self = this;
  940. // load recommendations with partial request
  941. self.loadComponentsRecommendationsFromServer(function() {
  942. // For validation use latest received recommendations because ir contains current master layout and recommended slave/client layout
  943. self.validate(self.get('content.recommendations'), function() {
  944. if (callback) {
  945. callback();
  946. }
  947. });
  948. }, true);
  949. },
  950. /**
  951. * Submit button click handler
  952. * @metohd submit
  953. */
  954. submit: function () {
  955. var self = this;
  956. var goNextStepIfValid = function() {
  957. if (!self.get('submitDisabled')) {
  958. App.router.send('next');
  959. }
  960. };
  961. if (App.get('supports.serverRecommendValidate')) {
  962. self.recommendAndValidate(function() {
  963. self.showValidationIssuesAcceptBox(goNextStepIfValid);
  964. });
  965. } else {
  966. self.updateIsSubmitDisabled();
  967. goNextStepIfValid();
  968. }
  969. },
  970. /**
  971. * In case of any validation issues shows accept dialog box for user which allow cancel and fix issues or continue anyway
  972. * @metohd submit
  973. */
  974. showValidationIssuesAcceptBox: function(callback) {
  975. var self = this;
  976. if (self.get('anyWarning') || self.get('anyError')) {
  977. App.ModalPopup.show({
  978. primary: Em.I18n.t('common.continueAnyway'),
  979. header: Em.I18n.t('installer.step5.validationIssuesAttention.header'),
  980. body: Em.I18n.t('installer.step5.validationIssuesAttention'),
  981. onPrimary: function () {
  982. this.hide();
  983. callback();
  984. }
  985. });
  986. } else {
  987. callback();
  988. }
  989. }
  990. });