step6_controller.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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: false,
  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. var recommendations = this.get('content.recommendations');
  373. // Get all host-component pairs from recommendations
  374. var componentHostPairs = recommendations.blueprint.host_groups.map(function (group) {
  375. return group.components.map(function (component) {
  376. return recommendations.blueprint_cluster_binding.host_groups.findProperty('name', group.name).hosts.map(function (host) {
  377. return { component: component.name, host: host.fqdn};
  378. });
  379. });
  380. });
  381. // Flatten results twice because of two map() call before
  382. componentHostPairs = [].concat.apply([], componentHostPairs);
  383. componentHostPairs = [].concat.apply([], componentHostPairs);
  384. var clientComponents = App.get('components.clients');
  385. hostsObj.forEach(function (host) {
  386. var checkboxes = host.get('checkboxes');
  387. checkboxes.forEach(function (checkbox) {
  388. var recommended = componentHostPairs.some(function (pair) {
  389. var componentMatch = pair.component === checkbox.component;
  390. if (checkbox.component === 'CLIENT' && !componentMatch) {
  391. componentMatch = clientComponents.contains(pair.component);
  392. }
  393. return pair.host === host.hostName && componentMatch;
  394. });
  395. checkbox.checked = recommended;
  396. });
  397. });
  398. } else {
  399. this.get('headers').forEach(function (header) {
  400. var nodes = slaveComponents.findProperty('componentName', header.get('name'));
  401. if (nodes) {
  402. nodes.hosts.forEach(function (_node) {
  403. var node = hostsObj.findProperty('hostName', _node.hostName);
  404. if (node) {
  405. node.get('checkboxes').findProperty('title', header.get('label')).set('checked', true);
  406. node.get('checkboxes').findProperty('title', header.get('label')).set('isInstalled', _node.isInstalled);
  407. }
  408. });
  409. }
  410. });
  411. }
  412. this.selectClientHost(hostsObj);
  413. return hostsObj;
  414. },
  415. /**
  416. *
  417. * @param hostsObj
  418. */
  419. selectClientHost: function (hostsObj) {
  420. if (!this.get('isClientsSet')) {
  421. var nonMasterHost = hostsObj.findProperty('hasMaster', false);
  422. var clientHost = !!nonMasterHost ? nonMasterHost : hostsObj[hostsObj.length - 1]; // last host
  423. var clientCheckBox = clientHost.get('checkboxes').findProperty('component', 'CLIENT');
  424. if (clientCheckBox) {
  425. clientCheckBox.set('checked', true);
  426. }
  427. this.set('isClientsSet', true);
  428. }
  429. },
  430. /**
  431. * Select checkboxes which correspond to master components
  432. *
  433. * @param {Array} hostsObj
  434. * @return {Array}
  435. * @method selectMasterComponents
  436. */
  437. selectMasterComponents: function (hostsObj) {
  438. var masterComponentHosts = this.get('content.masterComponentHosts');
  439. console.log('Master components selected on:', masterComponentHosts.mapProperty('hostName').uniq().join(", "));
  440. if (masterComponentHosts) {
  441. masterComponentHosts.forEach(function (item) {
  442. var host = hostsObj.findProperty('hostName', item.hostName);
  443. if (host) {
  444. var checkbox = host.get('checkboxes').findProperty('component', item.component);
  445. if (checkbox) {
  446. checkbox.set('checked', true);
  447. }
  448. }
  449. });
  450. }
  451. return hostsObj;
  452. },
  453. /**
  454. * Return list of master components for specified <code>hostname</code>
  455. * @param {string} hostName
  456. * @return {string[]}
  457. * @method getMasterComponentsForHost
  458. */
  459. getMasterComponentsForHost: function (hostName) {
  460. return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
  461. },
  462. callValidation: function (successCallback) {
  463. this.callServerSideValidation(successCallback);
  464. },
  465. /**
  466. * Update submit button status
  467. * @metohd callServerSideValidation
  468. */
  469. callServerSideValidation: function (successCallback) {
  470. var self = this;
  471. // We do not want to disable Next due to server validation issues - hence commented out line below
  472. // self.set('submitDisabled', true);
  473. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  474. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  475. var services = installedServices.concat(selectedServices).uniq();
  476. var hostNames = self.get('hosts').mapProperty('hostName');
  477. var slaveBlueprint = self.getCurrentBlueprint();
  478. var masterBlueprint = null;
  479. var invisibleSlaves = App.StackServiceComponent.find().filterProperty("isSlave").filterProperty("isShownOnInstallerSlaveClientPage", false).mapProperty("componentName");
  480. if (this.get('isInstallerWizard') || this.get('isAddServiceWizard')) {
  481. masterBlueprint = self.getCurrentMastersBlueprint();
  482. var invisibleMasters = [];
  483. if (this.get('isInstallerWizard')) {
  484. invisibleMasters = App.StackServiceComponent.find().filterProperty("isMaster").filterProperty("isShownOnInstallerAssignMasterPage", false).mapProperty("componentName");
  485. } else if (this.get('isAddServiceWizard')) {
  486. invisibleMasters = App.StackServiceComponent.find().filterProperty("isMaster").filterProperty("isShownOnAddServiceAssignMasterPage", false).mapProperty("componentName");
  487. }
  488. var selectedClientComponents = self.get('content.clients').mapProperty('component_name');
  489. var alreadyInstalledClients = App.get('components.clients').reject(function (c) {
  490. return selectedClientComponents.contains(c);
  491. });
  492. var invisibleComponents = invisibleMasters.concat(invisibleSlaves).concat(alreadyInstalledClients);
  493. var invisibleBlueprint = blueprintUtils.filterByComponents(this.get('content.recommendations'), invisibleComponents);
  494. masterBlueprint = blueprintUtils.mergeBlueprints(masterBlueprint, invisibleBlueprint);
  495. } else if (this.get('isAddHostWizard')) {
  496. masterBlueprint = self.getCurrentMasterSlaveBlueprint();
  497. hostNames = hostNames.concat(App.Host.find().mapProperty("hostName")).uniq();
  498. slaveBlueprint = blueprintUtils.addComponentsToBlueprint(slaveBlueprint, invisibleSlaves);
  499. }
  500. var bluePrintsForValidation = blueprintUtils.mergeBlueprints(masterBlueprint, slaveBlueprint);
  501. this.set('content.recommendationsHostGroups', bluePrintsForValidation);
  502. App.ajax.send({
  503. name: 'config.validations',
  504. sender: self,
  505. data: {
  506. stackVersionUrl: App.get('stackVersionURL'),
  507. hosts: hostNames,
  508. services: services,
  509. validate: 'host_groups',
  510. recommendations: bluePrintsForValidation
  511. },
  512. success: 'updateValidationsSuccessCallback',
  513. error: 'updateValidationsErrorCallback'
  514. }).
  515. then(function () {
  516. if (!self.get('submitDisabled') && successCallback) {
  517. successCallback();
  518. }
  519. }
  520. );
  521. },
  522. /**
  523. * Success-callback for validations request
  524. * @param {object} data
  525. * @method updateValidationsSuccessCallback
  526. */
  527. updateValidationsSuccessCallback: function (data) {
  528. var self = this;
  529. //data = JSON.parse(data); // temporary fix
  530. var clientComponents = App.get('components.clients');
  531. this.set('generalErrorMessages', []);
  532. this.set('generalWarningMessages', []);
  533. this.get('hosts').setEach('warnMessages', []);
  534. this.get('hosts').setEach('errorMessages', []);
  535. this.get('hosts').setEach('anyMessage', false);
  536. this.get('hosts').forEach(function (host) {
  537. host.checkboxes.setEach('hasWarnMessage', false);
  538. host.checkboxes.setEach('hasErrorMessage', false);
  539. });
  540. var anyErrors = false;
  541. var anyGeneralClientErrors = false; // any error/warning for any client component (under "CLIENT" alias)
  542. var validationData = validationUtils.filterNotInstalledComponents(data);
  543. validationData.filterProperty('type', 'host-component').filter(function (i) {
  544. return !(i['component-name'] && App.StackServiceComponent.find().findProperty('componentName', i['component-name']).get('isMaster'));
  545. }).forEach(function (item) {
  546. var checkboxWithIssue = null;
  547. var isGeneralClientValidationItem = clientComponents.contains(item['component-name']); // it is an error/warning for any client component (under "CLIENT" alias)
  548. var host = self.get('hosts').find(function (h) {
  549. return h.hostName === item.host && h.checkboxes.some(function (checkbox) {
  550. var isClientComponent = checkbox.component === "CLIENT" && isGeneralClientValidationItem;
  551. if (checkbox.component === item['component-name'] || isClientComponent) {
  552. checkboxWithIssue = checkbox;
  553. return true;
  554. } else {
  555. return false;
  556. }
  557. });
  558. });
  559. if (host) {
  560. host.set('anyMessage', true);
  561. if (item.level === 'ERROR') {
  562. anyErrors = true;
  563. host.get('errorMessages').push(item.message);
  564. checkboxWithIssue.set('hasErrorMessage', true);
  565. } else if (item.level === 'WARN') {
  566. host.get('warnMessages').push(item.message);
  567. checkboxWithIssue.set('hasWarnMessage', true);
  568. }
  569. } else {
  570. var component;
  571. if (isGeneralClientValidationItem) {
  572. if (!anyGeneralClientErrors) {
  573. anyGeneralClientErrors = true;
  574. component = "Client";
  575. }
  576. } else {
  577. component = item['component-name'];
  578. }
  579. if (component || !item['component-name']) {
  580. var details = "";
  581. if (item.host) {
  582. details += " (" + item.host + ")";
  583. }
  584. if (item.level === 'ERROR') {
  585. anyErrors = true;
  586. self.get('generalErrorMessages').push(item.message + details);
  587. } else if (item.level === 'WARN') {
  588. self.get('generalWarningMessages').push(item.message + details);
  589. }
  590. }
  591. }
  592. });
  593. // use this.set('submitDisabled', anyErrors); is validation results should block next button
  594. // It's because showValidationIssuesAcceptBox allow use accept validation issues and continue
  595. // this.set('submitDisabled', false);
  596. },
  597. /**
  598. * Error-callback for validations request
  599. * @param {object} jqXHR
  600. * @param {object} ajaxOptions
  601. * @param {string} error
  602. * @param {object} opt
  603. * @method updateValidationsErrorCallback
  604. */
  605. updateValidationsErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  606. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.method, jqXHR.status);
  607. console.log('Load validations failed');
  608. },
  609. /**
  610. * Composes selected values of comboboxes into blueprint format
  611. */
  612. getCurrentBlueprint: function () {
  613. var self = this;
  614. var res = {
  615. blueprint: { host_groups: [] },
  616. blueprint_cluster_binding: { host_groups: [] }
  617. };
  618. var clientComponents = self.get('content.clients').mapProperty('component_name');
  619. var mapping = self.get('hosts');
  620. mapping.forEach(function (item, i) {
  621. var group_name = 'host-group-' + (i+1);
  622. var host_group = {
  623. name: group_name,
  624. components: item.checkboxes.filterProperty('checked', true).map(function (checkbox) {
  625. if (checkbox.component === "CLIENT") {
  626. return clientComponents.map(function (client) {
  627. return { name: client };
  628. });
  629. } else {
  630. return { name: checkbox.component };
  631. }
  632. })
  633. };
  634. host_group.components = [].concat.apply([], host_group.components);
  635. var binding = {
  636. name: group_name,
  637. hosts: [
  638. { fqdn: item.hostName }
  639. ]
  640. };
  641. res.blueprint.host_groups.push(host_group);
  642. res.blueprint_cluster_binding.host_groups.push(binding);
  643. });
  644. return res;
  645. },
  646. /**
  647. * Create blueprint from assigned master components to appropriate hosts
  648. * @returns {Object}
  649. * @method getCurrentMastersBlueprint
  650. */
  651. getCurrentMastersBlueprint: function () {
  652. var res = {
  653. blueprint: { host_groups: [] },
  654. blueprint_cluster_binding: { host_groups: [] }
  655. };
  656. var masters = this.get('content.masterComponentHosts');
  657. var hosts = this.get('content.hosts');
  658. Em.keys(hosts).forEach(function (host, i) {
  659. var group_name = 'host-group-' + (i + 1);
  660. var components = [];
  661. masters.forEach(function (master) {
  662. if (master.hostName === host) {
  663. components.push({
  664. name: master.component
  665. });
  666. }
  667. });
  668. res.blueprint.host_groups.push({
  669. name: group_name,
  670. components: components
  671. });
  672. res.blueprint_cluster_binding.host_groups.push({
  673. name: group_name,
  674. hosts: [
  675. {
  676. fqdn: host
  677. }
  678. ]
  679. });
  680. }, this);
  681. return blueprintUtils.mergeBlueprints(res, this.getCurrentSlaveBlueprint());
  682. },
  683. /**
  684. * In case of any validation issues shows accept dialog box for user which allow cancel and fix issues or continue anyway
  685. * @metohd submit
  686. */
  687. showValidationIssuesAcceptBox: function(callback) {
  688. var self = this;
  689. if (self.get('anyWarnings') || self.get('anyErrors')) {
  690. App.ModalPopup.show({
  691. primary: Em.I18n.t('common.continueAnyway'),
  692. header: Em.I18n.t('installer.step6.validationIssuesAttention.header'),
  693. body: Em.I18n.t('installer.step6.validationIssuesAttention'),
  694. onPrimary: function () {
  695. this.hide();
  696. callback();
  697. }
  698. });
  699. } else {
  700. callback();
  701. }
  702. }
  703. });