step6_controller.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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 db = require('utils/db');
  20. var stringUtils = require('utils/string_utils');
  21. var blueprintUtils = require('utils/blueprint');
  22. var validationUtils = require('utils/validator');
  23. /**
  24. * By Step 6, we have the following information stored in App.db and set on this
  25. * controller by the router:
  26. *
  27. * hosts: App.db.hosts (list of all hosts the user selected in Step 3)
  28. * selectedServiceNames: App.db.selectedServiceNames (the services that the user selected in Step 4)
  29. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  30. *
  31. * Step 6 will set the following information in App.db:
  32. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  33. *
  34. */
  35. App.WizardStep6Controller = Em.Controller.extend(App.BlueprintMixin, {
  36. /**
  37. * List of hosts
  38. * @type {object[]}
  39. */
  40. hosts: [],
  41. /**
  42. * List of components info about selecting/deselecting status for components.
  43. *
  44. * @type {Array}
  45. * @item {Em.Object}
  46. * @property name {String} - component name
  47. * @property label {String} - component display name
  48. * @property allChecked {bool} - all checkboxes are checked
  49. * @property noChecked {bool} - no checkboxes checked
  50. */
  51. headers: [],
  52. /**
  53. * @type {bool}
  54. */
  55. isLoaded: false,
  56. /**
  57. * Indication if user has chosen hosts to install clients
  58. * @type {bool}
  59. */
  60. isClientsSet: false,
  61. /**
  62. * Define state for submit button
  63. * @type {bool}
  64. */
  65. submitDisabled: true,
  66. /**
  67. * Check if <code>addHostWizard</code> used
  68. * @type {bool}
  69. */
  70. isAddHostWizard: function () {
  71. return this.get('content.controllerName') === 'addHostController';
  72. }.property('content.controllerName'),
  73. /**
  74. * Check if <code>installerWizard</code> used
  75. * @type {bool}
  76. */
  77. isInstallerWizard: function () {
  78. return this.get('content.controllerName') === 'installerController';
  79. }.property('content.controllerName'),
  80. /**
  81. * Check if <code>addServiceWizard</code> used
  82. * @type {bool}
  83. */
  84. isAddServiceWizard: function () {
  85. return this.get('content.controllerName') === 'addServiceController';
  86. }.property('content.controllerName'),
  87. installedServiceNames: function () {
  88. return this.get('content.services').filterProperty('isInstalled').mapProperty('serviceName');
  89. }.property('content.services').cacheable(),
  90. /**
  91. * Validation error messages which don't related with any master
  92. */
  93. generalErrorMessages: [],
  94. /**
  95. * Validation warning messages which don't related with any master
  96. */
  97. generalWarningMessages: [],
  98. /**
  99. * true if validation has any general (which is not related with concrete host) error message
  100. */
  101. anyGeneralErrors: function() {
  102. var messages = this.get('generalErrorMessages');
  103. return this.get('errorMessage') || (messages && messages.length > 0);
  104. }.property('generalErrorMessages', 'generalErrorMessages.@each', 'errorMessage'),
  105. /**
  106. * true if validation has any general (which is not related with concrete host) warning message
  107. */
  108. anyGeneralWarnings: function() {
  109. var messages = this.get('generalWarningMessages');
  110. return messages && messages.length > 0;
  111. }.property('generalWarningMessages', 'generalWarningMessages.@each'),
  112. /**
  113. * true if validation has any general (which is not related with concrete host) error or warning message
  114. */
  115. anyGeneralIssues: function () {
  116. return this.get('anyGeneralErrors') || this.get('anyGeneralWarnings');
  117. }.property('anyGeneralErrors', 'anyGeneralWarnings'),
  118. /**
  119. * true if validation has any error message (general or host specific)
  120. */
  121. anyErrors: function() {
  122. return this.get('anyGeneralErrors') || this.get('hosts').some(function(h) { return h.get('errorMessages').length > 0; });
  123. }.property('anyGeneralErrors', 'hosts.@each.errorMessages'),
  124. /**
  125. * true if validation has any warning message (general or host specific)
  126. */
  127. anyWarnings: function() {
  128. return this.get('anyGeneralWarnings') || this.get('hosts').some(function(h) { return h.get('warnMessages').length > 0; });
  129. }.property('anyGeneralWarnings', 'hosts.@each.warnMessages'),
  130. openSlavesAndClientsIssues: function () {
  131. App.ModalPopup.show({
  132. header: Em.I18n.t('installer.step6.validationSlavesAndClients.popup.header'),
  133. bodyClass: Em.View.extend({
  134. controller: this,
  135. templateName: require('templates/wizard/step6/step6_issues_popup')
  136. }),
  137. secondary: null
  138. });
  139. },
  140. /**
  141. * Verify condition that at least one checkbox of each component was checked
  142. * @method clearError
  143. */
  144. clearError: function () {
  145. var self = this;
  146. var isError = false;
  147. var err = false;
  148. var hosts = this.get('hosts');
  149. var headers = this.get('headers');
  150. var headersMap = {};
  151. headers.forEach(function (header) {
  152. headersMap[header.name] = true;
  153. });
  154. hosts.forEach(function (host) {
  155. host.get('checkboxes').forEach(function (checkbox) {
  156. if (headersMap[checkbox.get('component')]) {
  157. headersMap[checkbox.get('component')] = !checkbox.get('checked');
  158. }
  159. });
  160. });
  161. for (var i in headersMap) {
  162. err |= headersMap[i];
  163. }
  164. if (!err) {
  165. this.set('errorMessage', '');
  166. }
  167. if (this.get('isAddHostWizard')) {
  168. hosts.forEach(function (host) {
  169. isError = false;
  170. headers.forEach(function (header) {
  171. isError |= host.get('checkboxes').findProperty('title', header.get('label')).checked;
  172. });
  173. isError = !isError;
  174. if (!isError) {
  175. self.set('errorMessage', '');
  176. }
  177. });
  178. }
  179. },
  180. /**
  181. * Clear Step6 data like <code>hosts</code>, <code>headers</code> etc
  182. * @method clearStep
  183. */
  184. clearStep: function () {
  185. this.set('hosts', []);
  186. this.set('headers', []);
  187. this.clearError();
  188. this.set('isLoaded', false);
  189. },
  190. /**
  191. * Enable some service for all hosts
  192. * @param {object} event
  193. * @method selectAllNodes
  194. */
  195. selectAllNodes: function (event) {
  196. var name = Em.get(event, 'context.name');
  197. if (name) {
  198. this.setAllNodes(name, true);
  199. this.callValidation();
  200. }
  201. },
  202. /**
  203. * Disable some services for all hosts
  204. * @param {object} event
  205. * @method deselectAllNodes
  206. */
  207. deselectAllNodes: function (event) {
  208. var name = Em.get(event, 'context.name');
  209. if (name) {
  210. this.setAllNodes(name, false);
  211. this.callValidation();
  212. }
  213. },
  214. /**
  215. * Enable/disable some service for all hosts
  216. * @param {String} component - component name
  217. * @param {bool} checked - true - enable, false - disable
  218. * @method setAllNodes
  219. */
  220. setAllNodes: function (component, checked) {
  221. this.get('hosts').forEach(function (host) {
  222. host.get('checkboxes').filterProperty('isInstalled', false).forEach(function (checkbox) {
  223. if (checkbox.get('component') === component) {
  224. checkbox.set('checked', checked);
  225. }
  226. });
  227. });
  228. this.checkCallback(component);
  229. },
  230. /**
  231. * Checkbox check callback
  232. * Verify if all/none checkboxes for current component are checked
  233. * @param {String} component
  234. * @method checkCallback
  235. */
  236. checkCallback: function (component) {
  237. var header = this.get('headers').findProperty('name', component);
  238. if (header) {
  239. var hosts = this.get('hosts');
  240. var allTrue = true;
  241. var allFalse = true;
  242. hosts.forEach(function (host) {
  243. host.get('checkboxes').forEach(function (checkbox) {
  244. if (checkbox.get('component') === component && !checkbox.get('isInstalled')) {
  245. allTrue = allTrue && checkbox.get('checked');
  246. allFalse = allFalse && !checkbox.get('checked');
  247. }
  248. });
  249. });
  250. header.set('allChecked', allTrue);
  251. header.set('noChecked', allFalse);
  252. }
  253. this.clearError();
  254. },
  255. /**
  256. * Init step6 data
  257. * @method loadStep
  258. */
  259. loadStep: function () {
  260. console.log("WizardStep6Controller: Loading step6: Assign Slaves");
  261. this.clearStep();
  262. var selectedServices = App.StackService.find().filterProperty('isSelected');
  263. var installedServices = App.StackService.find().filterProperty('isInstalled');
  264. var services;
  265. if (this.get('isInstallerWizard')) services = selectedServices;
  266. else if (this.get('isAddHostWizard')) services = installedServices;
  267. else if (this.get('isAddServiceWizard')) services = installedServices.concat(selectedServices);
  268. var headers = Em.A([]);
  269. services.forEach(function (stackService) {
  270. stackService.get('serviceComponents').forEach(function (serviceComponent) {
  271. if (serviceComponent.get('isShownOnInstallerSlaveClientPage')) {
  272. headers.pushObject(Em.Object.create({
  273. name: serviceComponent.get('componentName'),
  274. label: App.format.role(serviceComponent.get('componentName')),
  275. allChecked: false,
  276. isRequired: serviceComponent.get('isRequired'),
  277. noChecked: true,
  278. isDisabled: installedServices.someProperty('serviceName', stackService.get('serviceName')) && this.get('isAddServiceWizard')
  279. }));
  280. }
  281. }, this);
  282. }, this);
  283. if (this.get('content.clients') && !!this.get('content.clients').length) {
  284. headers.pushObject(Em.Object.create({
  285. name: 'CLIENT',
  286. label: App.format.role('CLIENT'),
  287. allChecked: false,
  288. noChecked: true,
  289. isDisabled: false
  290. }));
  291. }
  292. this.get('headers').pushObjects(headers);
  293. this.render();
  294. if (this.get('content.skipSlavesStep')) {
  295. App.router.send('next');
  296. } else {
  297. this.callValidation();
  298. }
  299. },
  300. /**
  301. * Get active host names
  302. * @return {string[]}
  303. * @method getHostNames
  304. */
  305. getHostNames: function () {
  306. var hostInfo = this.get('content.hosts');
  307. var hostNames = [];
  308. //flag identify whether get all hosts or only uninstalled(newly added) hosts
  309. var getUninstalledHosts = (this.get('content.controllerName') !== 'addServiceController');
  310. for (var index in hostInfo) {
  311. if (hostInfo.hasOwnProperty(index)) {
  312. if (hostInfo[index].bootStatus === 'REGISTERED') {
  313. if (!getUninstalledHosts || !hostInfo[index].isInstalled) {
  314. hostNames.push(hostInfo[index].name);
  315. }
  316. }
  317. }
  318. }
  319. return hostNames;
  320. },
  321. /**
  322. * Load all data needed for this module. Then it automatically renders in template
  323. * @method render
  324. */
  325. render: function () {
  326. var hostsObj = [],
  327. masterHosts = [],
  328. headers = this.get('headers'),
  329. masterHostNames = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  330. this.getHostNames().forEach(function (_hostName) {
  331. var hasMaster = masterHostNames.contains(_hostName);
  332. var obj = Em.Object.create({
  333. hostName: _hostName,
  334. hasMaster: hasMaster,
  335. checkboxes: []
  336. });
  337. headers.forEach(function (header) {
  338. obj.checkboxes.pushObject(Em.Object.create({
  339. component: header.name,
  340. title: header.label,
  341. checked: false,
  342. isInstalled: false,
  343. isDisabled: header.get('isDisabled')
  344. }));
  345. });
  346. if (hasMaster) {
  347. masterHosts.pushObject(obj)
  348. } else {
  349. hostsObj.pushObject(obj);
  350. }
  351. });
  352. //hosts with master components should be in the beginning of list
  353. hostsObj.unshift.apply(hostsObj, masterHosts);
  354. hostsObj = this.renderSlaves(hostsObj);
  355. this.set('hosts', hostsObj);
  356. headers.forEach(function (header) {
  357. this.checkCallback(header.get('name'));
  358. }, this);
  359. this.set('isLoaded', true);
  360. },
  361. /**
  362. * Set checked values for slaves checkboxes
  363. * @param {Array} hostsObj
  364. * @return {Array}
  365. * @method renderSlaves
  366. */
  367. renderSlaves: function (hostsObj) {
  368. var headers = this.get('headers');
  369. var clientHeaders = headers.findProperty('name', 'CLIENT');
  370. var slaveComponents = this.get('content.slaveComponentHosts');
  371. if (!slaveComponents) { // we are at this page for the first time
  372. if (!App.get('supports.serverRecommendValidate')) {
  373. hostsObj.forEach(function (host) {
  374. var checkboxes = host.get('checkboxes');
  375. checkboxes.setEach('checked', !host.hasMaster);
  376. checkboxes.setEach('isInstalled', false);
  377. if (clientHeaders) {
  378. checkboxes.findProperty('title', clientHeaders.get('label')).set('checked', false);
  379. }
  380. });
  381. this.selectClientHost(hostsObj);
  382. if (this.get('isInstallerWizard') && hostsObj.everyProperty('hasMaster', true)) {
  383. var lastHost = hostsObj[hostsObj.length - 1];
  384. lastHost.get('checkboxes').setEach('checked', true);
  385. }
  386. } else {
  387. var recommendations = this.get('content.recommendations');
  388. // Get all host-component pairs from recommendations
  389. var componentHostPairs = recommendations.blueprint.host_groups.map(function (group) {
  390. return group.components.map(function (component) {
  391. return recommendations.blueprint_cluster_binding.host_groups.findProperty('name', group.name).hosts.map(function (host) {
  392. return { component: component.name, host: host.fqdn};
  393. });
  394. });
  395. });
  396. // Flatten results twice because of two map() call before
  397. componentHostPairs = [].concat.apply([], componentHostPairs);
  398. componentHostPairs = [].concat.apply([], componentHostPairs);
  399. var clientComponents = App.get('components.clients');
  400. hostsObj.forEach(function (host) {
  401. var checkboxes = host.get('checkboxes');
  402. checkboxes.forEach(function (checkbox) {
  403. var recommended = componentHostPairs.some(function (pair) {
  404. var componentMatch = pair.component === checkbox.component;
  405. if (checkbox.component === 'CLIENT' && !componentMatch) {
  406. componentMatch = clientComponents.contains(pair.component);
  407. }
  408. return pair.host === host.hostName && componentMatch;
  409. });
  410. checkbox.checked = recommended;
  411. });
  412. });
  413. }
  414. } else {
  415. this.get('headers').forEach(function (header) {
  416. var nodes = slaveComponents.findProperty('componentName', header.get('name'));
  417. if (nodes) {
  418. nodes.hosts.forEach(function (_node) {
  419. var node = hostsObj.findProperty('hostName', _node.hostName);
  420. if (node) {
  421. node.get('checkboxes').findProperty('title', header.get('label')).set('checked', true);
  422. node.get('checkboxes').findProperty('title', header.get('label')).set('isInstalled', _node.isInstalled);
  423. }
  424. });
  425. }
  426. });
  427. }
  428. this.selectClientHost(hostsObj);
  429. return hostsObj;
  430. },
  431. /**
  432. *
  433. * @param hostsObj
  434. */
  435. selectClientHost: function (hostsObj) {
  436. if (!this.get('isClientsSet')) {
  437. var nonMasterHost = hostsObj.findProperty('hasMaster', false);
  438. var clientHost = !!nonMasterHost ? nonMasterHost : hostsObj[hostsObj.length - 1]; // last host
  439. var clientCheckBox = clientHost.get('checkboxes').findProperty('component', 'CLIENT');
  440. if (clientCheckBox) {
  441. clientCheckBox.set('checked', true);
  442. }
  443. this.set('isClientsSet', true);
  444. }
  445. },
  446. /**
  447. * Select checkboxes which correspond to master components
  448. *
  449. * @param {Array} hostsObj
  450. * @return {Array}
  451. * @method selectMasterComponents
  452. */
  453. selectMasterComponents: function (hostsObj) {
  454. var masterComponentHosts = this.get('content.masterComponentHosts');
  455. console.log('Master components selected on:', masterComponentHosts.mapProperty('hostName').uniq().join(", "));
  456. if (masterComponentHosts) {
  457. masterComponentHosts.forEach(function (item) {
  458. var host = hostsObj.findProperty('hostName', item.hostName);
  459. if (host) {
  460. var checkbox = host.get('checkboxes').findProperty('component', item.component);
  461. if (checkbox) {
  462. checkbox.set('checked', true);
  463. }
  464. }
  465. });
  466. }
  467. return hostsObj;
  468. },
  469. /**
  470. * Return list of master components for specified <code>hostname</code>
  471. * @param {string} hostName
  472. * @return {string[]}
  473. * @method getMasterComponentsForHost
  474. */
  475. getMasterComponentsForHost: function (hostName) {
  476. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  477. },
  478. callValidation: function (successCallback) {
  479. var self = this;
  480. if (App.get('supports.serverRecommendValidate')) {
  481. self.callServerSideValidation(successCallback);
  482. } else {
  483. var res = self.callClientSideValidation();
  484. self.set('submitDisabled', !res);
  485. if (res && successCallback) {
  486. successCallback();
  487. }
  488. }
  489. },
  490. /**
  491. * Update submit button status
  492. * @metohd callServerSideValidation
  493. */
  494. callServerSideValidation: function (successCallback) {
  495. var self = this;
  496. self.set('submitDisabled', true);
  497. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  498. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  499. var services = installedServices.concat(selectedServices).uniq();
  500. var hostNames = self.get('hosts').mapProperty('hostName');
  501. var slaveBlueprint = self.getCurrentBlueprint();
  502. var masterBlueprint = null;
  503. var invisibleSlaves = App.StackServiceComponent.find().filterProperty("isSlave").filterProperty("isShownOnInstallerSlaveClientPage", false).mapProperty("componentName");
  504. if (this.get('isInstallerWizard') || this.get('isAddServiceWizard')) {
  505. masterBlueprint = self.getCurrentMastersBlueprint();
  506. var invisibleMasters = [];
  507. if (this.get('isInstallerWizard')) {
  508. invisibleMasters = App.StackServiceComponent.find().filterProperty("isMaster").filterProperty("isShownOnInstallerAssignMasterPage", false).mapProperty("componentName");
  509. } else if (this.get('isAddServiceWizard')) {
  510. invisibleMasters = App.StackServiceComponent.find().filterProperty("isMaster").filterProperty("isShownOnAddServiceAssignMasterPage", false).mapProperty("componentName");
  511. }
  512. var selectedClientComponents = self.get('content.clients').mapProperty('component_name');
  513. var alreadyInstalledClients = App.get('components.clients').reject(function (c) {
  514. return selectedClientComponents.contains(c);
  515. });
  516. var invisibleComponents = invisibleMasters.concat(invisibleSlaves).concat(alreadyInstalledClients);
  517. var invisibleBlueprint = blueprintUtils.filterByComponents(this.get('content.recommendations'), invisibleComponents);
  518. masterBlueprint = blueprintUtils.mergeBlueprints(masterBlueprint, invisibleBlueprint);
  519. } else if (this.get('isAddHostWizard')) {
  520. masterBlueprint = self.getCurrentMasterSlaveBlueprint();
  521. hostNames = hostNames.concat(App.Host.find().mapProperty("hostName")).uniq();
  522. slaveBlueprint = blueprintUtils.addComponentsToBlueprint(slaveBlueprint, invisibleSlaves);
  523. }
  524. var bluePrintsForValidation = blueprintUtils.mergeBlueprints(masterBlueprint, slaveBlueprint);
  525. this.set('content.recommendationsHostGroups', bluePrintsForValidation);
  526. App.ajax.send({
  527. name: 'config.validations',
  528. sender: self,
  529. data: {
  530. stackVersionUrl: App.get('stackVersionURL'),
  531. hosts: hostNames,
  532. services: services,
  533. validate: 'host_groups',
  534. recommendations: bluePrintsForValidation
  535. },
  536. success: 'updateValidationsSuccessCallback'
  537. }).
  538. retry({
  539. times: App.maxRetries,
  540. timeout: App.timeout
  541. }).
  542. then(function () {
  543. if (!self.get('submitDisabled') && successCallback) {
  544. successCallback();
  545. }
  546. }, function () {
  547. App.showReloadPopup();
  548. console.log('Load validations failed');
  549. }
  550. );
  551. },
  552. /**
  553. * Success-callback for validations request
  554. * @param {object} data
  555. * @method updateValidationsSuccessCallback
  556. */
  557. updateValidationsSuccessCallback: function (data) {
  558. var self = this;
  559. //data = JSON.parse(data); // temporary fix
  560. var clientComponents = App.get('components.clients');
  561. this.set('generalErrorMessages', []);
  562. this.set('generalWarningMessages', []);
  563. this.get('hosts').setEach('warnMessages', []);
  564. this.get('hosts').setEach('errorMessages', []);
  565. this.get('hosts').setEach('anyMessage', false);
  566. this.get('hosts').forEach(function (host) {
  567. host.checkboxes.setEach('hasWarnMessage', false);
  568. host.checkboxes.setEach('hasErrorMessage', false);
  569. });
  570. var anyErrors = false;
  571. var anyGeneralClientErrors = false; // any error/warning for any client component (under "CLIENT" alias)
  572. var validationData = validationUtils.filterNotInstalledComponents(data);
  573. validationData.filterProperty('type', 'host-component').filter(function (i) {
  574. return !(i['component-name'] && App.StackServiceComponent.find().findProperty('componentName', i['component-name']).get('isMaster'));
  575. }).forEach(function (item) {
  576. var checkboxWithIssue = null;
  577. var isGeneralClientValidationItem = clientComponents.contains(item['component-name']); // it is an error/warning for any client component (under "CLIENT" alias)
  578. var host = self.get('hosts').find(function (h) {
  579. return h.hostName === item.host && h.checkboxes.some(function (checkbox) {
  580. var isClientComponent = checkbox.component === "CLIENT" && isGeneralClientValidationItem;
  581. if (checkbox.component === item['component-name'] || isClientComponent) {
  582. checkboxWithIssue = checkbox;
  583. return true;
  584. } else {
  585. return false;
  586. }
  587. });
  588. });
  589. if (host) {
  590. host.set('anyMessage', true);
  591. if (item.level === 'ERROR') {
  592. anyErrors = true;
  593. host.get('errorMessages').push(item.message);
  594. checkboxWithIssue.set('hasErrorMessage', true);
  595. } else if (item.level === 'WARN') {
  596. host.get('warnMessages').push(item.message);
  597. checkboxWithIssue.set('hasWarnMessage', true);
  598. }
  599. } else {
  600. var component;
  601. if (isGeneralClientValidationItem) {
  602. if (!anyGeneralClientErrors) {
  603. anyGeneralClientErrors = true;
  604. component = "Client";
  605. }
  606. } else {
  607. component = item['component-name'];
  608. }
  609. if (component || !item['component-name']) {
  610. var details = "";
  611. if (item.host) {
  612. details += " (" + item.host + ")";
  613. }
  614. if (item.level === 'ERROR') {
  615. anyErrors = true;
  616. self.get('generalErrorMessages').push(item.message + details);
  617. } else if (item.level === 'WARN') {
  618. self.get('generalWarningMessages').push(item.message + details);
  619. }
  620. }
  621. }
  622. });
  623. // use this.set('submitDisabled', anyErrors); is validation results should block next button
  624. // It's because showValidationIssuesAcceptBox allow use accept validation issues and continue
  625. this.set('submitDisabled', false);
  626. },
  627. /**
  628. * Composes selected values of comboboxes into blueprint format
  629. */
  630. getCurrentBlueprint: function () {
  631. var self = this;
  632. var res = {
  633. blueprint: { host_groups: [] },
  634. blueprint_cluster_binding: { host_groups: [] }
  635. };
  636. var clientComponents = self.get('content.clients').mapProperty('component_name');
  637. var mapping = self.get('hosts');
  638. mapping.forEach(function (item, i) {
  639. var group_name = 'host-group-' + (i+1);
  640. var host_group = {
  641. name: group_name,
  642. components: item.checkboxes.filterProperty('checked', true).map(function (checkbox) {
  643. if (checkbox.component === "CLIENT") {
  644. return clientComponents.map(function (client) {
  645. return { name: client };
  646. });
  647. } else {
  648. return { name: checkbox.component };
  649. }
  650. })
  651. };
  652. host_group.components = [].concat.apply([], host_group.components);
  653. var binding = {
  654. name: group_name,
  655. hosts: [
  656. { fqdn: item.hostName }
  657. ]
  658. };
  659. res.blueprint.host_groups.push(host_group);
  660. res.blueprint_cluster_binding.host_groups.push(binding);
  661. });
  662. return res;
  663. },
  664. /**
  665. * Create blueprint from assigned master components to appropriate hosts
  666. * @returns {Object}
  667. * @method getCurrentMastersBlueprint
  668. */
  669. getCurrentMastersBlueprint: function () {
  670. var res = {
  671. blueprint: { host_groups: [] },
  672. blueprint_cluster_binding: { host_groups: [] }
  673. };
  674. var masters = this.get('content.masterComponentHosts');
  675. var hosts = this.get('content.hosts');
  676. Em.keys(hosts).forEach(function (host, i) {
  677. var group_name = 'host-group-' + (i + 1);
  678. var components = [];
  679. masters.forEach(function (master) {
  680. if (master.hostName === host) {
  681. components.push({
  682. name: master.component
  683. });
  684. }
  685. });
  686. res.blueprint.host_groups.push({
  687. name: group_name,
  688. components: components
  689. });
  690. res.blueprint_cluster_binding.host_groups.push({
  691. name: group_name,
  692. hosts: [
  693. {
  694. fqdn: host
  695. }
  696. ]
  697. });
  698. }, this);
  699. return blueprintUtils.mergeBlueprints(res, this.getCurrentSlaveBlueprint());
  700. },
  701. /**
  702. * callClientSideValidation form. Return do we have errors or not
  703. * @return {bool}
  704. * @method callClientSideValidation
  705. */
  706. callClientSideValidation: function () {
  707. if (this.get('isAddHostWizard')) {
  708. return this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForHost'));
  709. }
  710. else {
  711. if (this.get('isInstallerWizard')) {
  712. return this.validateEachComponent() && this.validateEachHost(Em.I18n.t('installer.step6.error.mustSelectOneForSlaveHost'));
  713. }
  714. else {
  715. if (this.get('isAddServiceWizard')) {
  716. return this.validateEachComponent();
  717. }
  718. return true;
  719. }
  720. }
  721. },
  722. /**
  723. * Validate all components for each host. Return do we have errors or not
  724. * @return {bool}
  725. * @method validateEachHost
  726. */
  727. validateEachHost: function (errorMsg) {
  728. var isError = false;
  729. var hosts = this.get('hosts');
  730. var headers = this.get('headers');
  731. for (var i = 0; i < hosts.length; i++) {
  732. if (this.get('isInstallerWizard') && this.get('content.masterComponentHosts').someProperty('hostName', hosts[i].hostName)) {
  733. continue;
  734. }
  735. var checkboxes = hosts[i].get('checkboxes');
  736. isError = false;
  737. headers.forEach(function (header) {
  738. isError = isError || checkboxes.findProperty('title', header.get('label')).checked;
  739. });
  740. isError = !isError;
  741. if (isError) {
  742. this.set('errorMessage', errorMsg);
  743. break;
  744. }
  745. }
  746. return !isError;
  747. },
  748. /**
  749. * Check for minimum required count of components to install.
  750. *
  751. * @return {bool}
  752. * @method validateEachComponent
  753. */
  754. validateEachComponent: function () {
  755. var isError = false;
  756. var hosts = this.get('hosts');
  757. var headers = this.get('headers');
  758. var componentsToInstall = [];
  759. headers.forEach(function (header) {
  760. var checkboxes = hosts.mapProperty('checkboxes').reduce(function (cItem, pItem) {
  761. return cItem.concat(pItem);
  762. });
  763. var selectedCount = checkboxes.filterProperty('component', header.get('name')).filterProperty('checked').length;
  764. if (header.get('name') == 'CLIENT') {
  765. var clientsMinCount = 0;
  766. var serviceNames = this.get('installedServiceNames').concat(this.get('content.selectedServiceNames'));
  767. // find max value for `minToInstall` property
  768. serviceNames.forEach(function (serviceName) {
  769. App.StackServiceComponent.find().filterProperty('stackService.serviceName', serviceName).filterProperty('isClient')
  770. .mapProperty('minToInstall').forEach(function (ctMinCount) {
  771. clientsMinCount = ctMinCount > clientsMinCount ? ctMinCount : clientsMinCount;
  772. });
  773. });
  774. if (selectedCount < clientsMinCount) {
  775. isError = true;
  776. var requiredQuantity = (clientsMinCount > hosts.length ? hosts.length : clientsMinCount) - selectedCount;
  777. componentsToInstall.push(requiredQuantity + ' ' + stringUtils.pluralize(requiredQuantity, Em.I18n.t('common.client')));
  778. }
  779. } else {
  780. var stackComponent = App.StackServiceComponent.find().findProperty('componentName', header.get('name'));
  781. if (selectedCount < stackComponent.get('minToInstall')) {
  782. isError = true;
  783. var requiredQuantity = (stackComponent.get('minToInstall') > hosts.length ? hosts.length : stackComponent.get('minToInstall')) - selectedCount;
  784. componentsToInstall.push(requiredQuantity + ' ' + stringUtils.pluralize(requiredQuantity, stackComponent.get('displayName')));
  785. }
  786. }
  787. }, this);
  788. if (componentsToInstall.length) {
  789. this.set('errorMessage', Em.I18n.t('installer.step6.error.mustSelectComponents').format(componentsToInstall.join(', ')));
  790. }
  791. return !isError;
  792. },
  793. /**
  794. * In case of any validation issues shows accept dialog box for user which allow cancel and fix issues or continue anyway
  795. * @metohd submit
  796. */
  797. showValidationIssuesAcceptBox: function(callback) {
  798. var self = this;
  799. if (App.get('supports.serverRecommendValidate') && (self.get('anyWarnings') || self.get('anyErrors'))) {
  800. App.ModalPopup.show({
  801. primary: Em.I18n.t('common.continueAnyway'),
  802. header: Em.I18n.t('installer.step6.validationIssuesAttention.header'),
  803. body: Em.I18n.t('installer.step6.validationIssuesAttention'),
  804. onPrimary: function () {
  805. this.hide();
  806. callback();
  807. }
  808. });
  809. } else {
  810. callback();
  811. }
  812. }
  813. });