assign_master_components.js 43 KB

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