installer.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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 stringUtils = require('utils/string_utils');
  20. App.InstallerController = App.WizardController.extend({
  21. name: 'installerController',
  22. isCheckInProgress: false,
  23. totalSteps: 11,
  24. content: Em.Object.create({
  25. cluster: null,
  26. installOptions: null,
  27. hosts: null,
  28. services: null,
  29. slaveComponentHosts: null,
  30. masterComponentHosts: null,
  31. serviceConfigProperties: null,
  32. advancedServiceConfig: null,
  33. configGroups: [],
  34. slaveGroupProperties: null,
  35. stacks: null,
  36. clients: [],
  37. /**
  38. * recommendations for host groups loaded from server
  39. */
  40. recommendations: null,
  41. /**
  42. * recommendationsHostGroups - current component assignment after 5 and 6 steps,
  43. * or adding hiveserver2 interactive on "configure services" page
  44. * (uses for host groups validation and to load recommended configs)
  45. */
  46. recommendationsHostGroups: null,
  47. controllerName: 'installerController'
  48. }),
  49. /**
  50. * Wizard properties in local storage, which should be cleaned right after wizard has been finished
  51. */
  52. dbPropertiesToClean: [
  53. 'service',
  54. 'hosts',
  55. 'masterComponentHosts',
  56. 'slaveComponentHosts',
  57. 'cluster',
  58. 'allHostNames',
  59. 'installOptions',
  60. 'allHostNamesPattern',
  61. 'serviceComponents',
  62. 'clientInfo',
  63. 'selectedServiceNames',
  64. 'serviceConfigGroups',
  65. 'serviceConfigProperties',
  66. 'fileNamesToUpdate',
  67. 'bootStatus',
  68. 'stacksVersions',
  69. 'currentStep',
  70. 'serviceInfo',
  71. 'hostInfo',
  72. 'recommendations',
  73. 'recommendationsHostGroups',
  74. 'recommendationsConfigs'
  75. ],
  76. init: function () {
  77. this._super();
  78. this.get('isStepDisabled').setEach('value', true);
  79. this.get('isStepDisabled').pushObject(Ember.Object.create({
  80. step: 0,
  81. value: true
  82. }));
  83. },
  84. /**
  85. * redefined connectOutlet method to avoid view loading by unauthorized user
  86. * @param view
  87. * @param content
  88. */
  89. connectOutlet: function (view, content) {
  90. if (App.db.getAuthenticated()) {
  91. this._super(view, content);
  92. }
  93. },
  94. getCluster: function () {
  95. return jQuery.extend({}, this.get('clusterStatusTemplate'));
  96. },
  97. getHosts: function () {
  98. return [];
  99. },
  100. /**
  101. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  102. * @param hosts Array of hosts, which we want to delete
  103. */
  104. removeHosts: function (hosts) {
  105. var dbHosts = this.getDBProperty('hosts');
  106. hosts.forEach(function (_hostInfo) {
  107. var host = _hostInfo.name;
  108. delete dbHosts[host];
  109. });
  110. this.setDBProperty('hosts', dbHosts);
  111. },
  112. /**
  113. * Load confirmed hosts.
  114. * Will be used at <code>Assign Masters(step5)</code> step
  115. */
  116. loadConfirmedHosts: function () {
  117. this.set('content.hosts', this.getDBProperty('hosts') || {});
  118. },
  119. /**
  120. * Load services data. Will be used at <code>Select services(step4)</code> step
  121. */
  122. loadServices: function () {
  123. var dfd = $.Deferred();
  124. var self = this;
  125. var stackServices = App.StackService.find().mapProperty('serviceName');
  126. if (!(stackServices && !!stackServices.length && App.StackService.find().objectAt(0).get('stackVersion') == App.get('currentStackVersionNumber'))) {
  127. this.loadServiceComponents().complete(function () {
  128. self.set('content.services', App.StackService.find());
  129. dfd.resolve();
  130. });
  131. } else {
  132. dfd.resolve();
  133. }
  134. return dfd.promise();
  135. },
  136. /**
  137. * total set of hosts registered to cluster, analog of App.Host model,
  138. * used in Installer wizard until hosts are installed
  139. */
  140. allHosts: function () {
  141. var rawHosts = this.get('content.hosts');
  142. var masterComponents = this.get('content.masterComponentHosts');
  143. var slaveComponents = this.get('content.slaveComponentHosts');
  144. var hosts = [];
  145. masterComponents.forEach(function (component) {
  146. var host = rawHosts[component.hostName];
  147. if (host.hostComponents) {
  148. host.hostComponents.push(Em.Object.create({
  149. componentName: component.component,
  150. displayName: component.display_name
  151. }));
  152. } else {
  153. rawHosts[component.hostName].hostComponents = [
  154. Em.Object.create({
  155. componentName: component.component,
  156. displayName: component.display_name
  157. })
  158. ]
  159. }
  160. });
  161. slaveComponents.forEach(function (component) {
  162. component.hosts.forEach(function (rawHost) {
  163. var host = rawHosts[rawHost.hostName];
  164. if (host.hostComponents) {
  165. host.hostComponents.push(Em.Object.create({
  166. componentName: component.componentName,
  167. displayName: component.displayName
  168. }));
  169. } else {
  170. rawHosts[rawHost.hostName].hostComponents = [
  171. Em.Object.create({
  172. componentName: component.componentName,
  173. displayName: component.displayName
  174. })
  175. ]
  176. }
  177. });
  178. });
  179. for (var hostName in rawHosts) {
  180. var host = rawHosts[hostName];
  181. var disksOverallCapacity = 0;
  182. var diskFree = 0;
  183. host.disk_info.forEach(function (disk) {
  184. disksOverallCapacity += parseFloat(disk.size);
  185. diskFree += parseFloat(disk.available);
  186. });
  187. hosts.pushObject(Em.Object.create({
  188. id: host.name,
  189. ip: host.ip,
  190. osType: host.os_type,
  191. osArch: host.os_arch,
  192. hostName: host.name,
  193. publicHostName: host.name,
  194. cpu: host.cpu,
  195. memory: host.memory,
  196. diskInfo: host.disk_info,
  197. diskTotal: disksOverallCapacity / (1024 * 1024),
  198. diskFree: diskFree / (1024 * 1024),
  199. hostComponents: host.hostComponents || []
  200. }
  201. ))
  202. }
  203. return hosts;
  204. }.property('content.hosts'),
  205. stacks: [],
  206. /**
  207. * stack names used as auxiliary data to query stacks by name
  208. */
  209. stackNames: [],
  210. /**
  211. * Load stacks data from server or take exist data from in memory variable {{content.stacks}}
  212. * The series of API calls will be called When landing first time on Select Stacks page
  213. * or on hitting refresh post select stacks page in installer wizard
  214. */
  215. loadStacks: function () {
  216. var stacks = this.get('content.stacks');
  217. var dfd = $.Deferred();
  218. App.configsCollection.clearAll();
  219. App.Section.find().clear();
  220. App.SubSection.find().clear();
  221. App.SubSectionTab.find().clear();
  222. App.Tab.find().clear();
  223. this.set('stackConfigsLoaded', false);
  224. if (stacks && stacks.get('length')) {
  225. App.set('currentStackVersion', App.Stack.find().findProperty('isSelected').get('id'));
  226. dfd.resolve(true);
  227. } else {
  228. App.ajax.send({
  229. name: 'wizard.stacks',
  230. sender: this,
  231. success: 'loadStacksSuccessCallback',
  232. error: 'loadStacksErrorCallback'
  233. }).complete(function () {
  234. dfd.resolve(false);
  235. });
  236. }
  237. return dfd.promise();
  238. },
  239. /**
  240. * Send queries to load versions for each stack
  241. */
  242. loadStacksSuccessCallback: function (data) {
  243. this.get('stacks').clear();
  244. this.set('stackNames', data.items.mapProperty('Stacks.stack_name'));
  245. },
  246. /**
  247. * onError callback for loading stacks data
  248. */
  249. loadStacksErrorCallback: function () {
  250. },
  251. /**
  252. * query every stack names from server
  253. * @return {Array}
  254. */
  255. loadStacksVersions: function () {
  256. var requests = [];
  257. this.get('stackNames').forEach(function (stackName) {
  258. requests.push(App.ajax.send({
  259. name: 'wizard.stacks_versions',
  260. sender: this,
  261. data: {
  262. stackName: stackName
  263. },
  264. success: 'loadStacksVersionsSuccessCallback',
  265. error: 'loadStacksVersionsErrorCallback'
  266. }));
  267. }, this);
  268. this.set('loadStacksRequestsCounter', requests.length);
  269. return requests;
  270. },
  271. /**
  272. * Counter for counting number of successful requests to load stack versions
  273. */
  274. loadStacksRequestsCounter: 0,
  275. /**
  276. * Parse loaded data and create array of stacks objects
  277. */
  278. loadStacksVersionsSuccessCallback: function (data) {
  279. var stacks = App.db.getStacks();
  280. var isStacksExistInDb = stacks && stacks.length;
  281. if (isStacksExistInDb) {
  282. stacks.forEach(function (_stack) {
  283. var stack = data.items.filterProperty('Versions.stack_name', _stack.stack_name).findProperty('Versions.stack_version', _stack.stack_version);
  284. if (stack) {
  285. stack.Versions.is_selected = _stack.is_selected;
  286. }
  287. }, this);
  288. }
  289. App.stackMapper.map(data);
  290. if (!this.decrementProperty('loadStacksRequestsCounter')) {
  291. if (!isStacksExistInDb) {
  292. var defaultStackVersion = App.Stack.find().findProperty('id', App.defaultStackVersion);
  293. if (defaultStackVersion) {
  294. defaultStackVersion.set('isSelected', true)
  295. } else {
  296. App.Stack.find().objectAt(0).set('isSelected', true);
  297. }
  298. }
  299. this.set('content.stacks', App.Stack.find());
  300. App.set('currentStackVersion', App.Stack.find().findProperty('isSelected').get('id'));
  301. }
  302. },
  303. /**
  304. * onError callback for loading stacks data
  305. */
  306. loadStacksVersionsErrorCallback: function () {
  307. },
  308. /**
  309. * check server version and web client version
  310. */
  311. checkServerClientVersion: function () {
  312. var dfd = $.Deferred();
  313. var self = this;
  314. self.getServerVersion().done(function () {
  315. dfd.resolve();
  316. });
  317. return dfd.promise();
  318. },
  319. getServerVersion: function () {
  320. return App.ajax.send({
  321. name: 'ambari.service',
  322. sender: this,
  323. data: {
  324. fields: '?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true'
  325. },
  326. success: 'getServerVersionSuccessCallback',
  327. error: 'getServerVersionErrorCallback'
  328. });
  329. },
  330. getServerVersionSuccessCallback: function (data) {
  331. var clientVersion = App.get('version');
  332. var serverVersion = (data.RootServiceComponents.component_version).toString();
  333. this.set('ambariServerVersion', serverVersion);
  334. if (clientVersion) {
  335. this.set('versionConflictAlertBody', Em.I18n.t('app.versionMismatchAlert.body').format(serverVersion, clientVersion));
  336. this.set('isServerClientVersionMismatch', clientVersion != serverVersion);
  337. } else {
  338. this.set('isServerClientVersionMismatch', false);
  339. }
  340. App.set('isManagedMySQLForHiveEnabled', App.config.isManagedMySQLForHiveAllowed(data.RootServiceComponents.properties['server.os_family']));
  341. },
  342. getServerVersionErrorCallback: function () {
  343. },
  344. /**
  345. * set stacks from server to content and local DB
  346. */
  347. setStacks: function () {
  348. var result = App.Stack.find() || [];
  349. Em.assert('Stack model is not populated', result.get('length'));
  350. App.db.setStacks(result.slice());
  351. this.set('content.stacks', result);
  352. },
  353. /**
  354. * Save data to model
  355. * @param stepController App.WizardStep4Controller
  356. */
  357. saveServices: function (stepController) {
  358. var selectedServiceNames = [];
  359. var installedServiceNames = [];
  360. stepController.filterProperty('isSelected').forEach(function (item) {
  361. selectedServiceNames.push(item.get('serviceName'));
  362. });
  363. stepController.filterProperty('isInstalled').forEach(function (item) {
  364. installedServiceNames.push(item.get('serviceName'));
  365. });
  366. this.set('content.services', App.StackService.find());
  367. this.set('content.selectedServiceNames', selectedServiceNames);
  368. this.set('content.installedServiceNames', installedServiceNames);
  369. this.setDBProperties({
  370. selectedServiceNames: selectedServiceNames,
  371. installedServiceNames: installedServiceNames
  372. });
  373. },
  374. /**
  375. * Save Master Component Hosts data to Main Controller
  376. * @param stepController App.WizardStep5Controller
  377. */
  378. saveMasterComponentHosts: function (stepController) {
  379. var obj = stepController.get('selectedServicesMasters'),
  380. hosts = this.getDBProperty('hosts');
  381. var masterComponentHosts = [];
  382. obj.forEach(function (_component) {
  383. masterComponentHosts.push({
  384. display_name: _component.get('display_name'),
  385. component: _component.get('component_name'),
  386. serviceId: _component.get('serviceId'),
  387. isInstalled: false,
  388. host_id: hosts[_component.get('selectedHost')].id
  389. });
  390. });
  391. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  392. this.set('content.masterComponentHosts', masterComponentHosts);
  393. },
  394. /**
  395. * Load master component hosts data for using in required step controllers
  396. */
  397. loadMasterComponentHosts: function () {
  398. var props = this.getDBProperties(['masterComponentHosts', 'hosts']);
  399. var masterComponentHosts = props.masterComponentHosts,
  400. hosts = props.hosts || {},
  401. host_names = Em.keys(hosts);
  402. if (Em.isNone(masterComponentHosts)) {
  403. masterComponentHosts = [];
  404. }
  405. else {
  406. masterComponentHosts.forEach(function (component) {
  407. for (var i = 0; i < host_names.length; i++) {
  408. if (hosts[host_names[i]].id === component.host_id) {
  409. component.hostName = host_names[i];
  410. break;
  411. }
  412. }
  413. });
  414. }
  415. this.set("content.masterComponentHosts", masterComponentHosts);
  416. },
  417. loadCurrentHostGroups: function () {
  418. this.set("content.recommendationsHostGroups", this.getDBProperty('recommendationsHostGroups'));
  419. },
  420. loadRecommendationsConfigs: function () {
  421. App.router.set("wizardStep7Controller.recommendationsConfigs", this.getDBProperty('recommendationsConfigs'));
  422. },
  423. /**
  424. * Load master component hosts data for using in required step controllers
  425. */
  426. loadSlaveComponentHosts: function () {
  427. var props = this.getDBProperties(['slaveComponentHosts', 'hosts']);
  428. var slaveComponentHosts = props.slaveComponentHosts,
  429. hosts = props.hosts || {},
  430. host_names = Em.keys(hosts);
  431. if (!Em.isNone(slaveComponentHosts)) {
  432. slaveComponentHosts.forEach(function (component) {
  433. component.hosts.forEach(function (host) {
  434. for (var i = 0; i < host_names.length; i++) {
  435. if (hosts[host_names[i]].id === host.host_id) {
  436. host.hostName = host_names[i];
  437. break;
  438. }
  439. }
  440. });
  441. });
  442. }
  443. this.set("content.slaveComponentHosts", slaveComponentHosts);
  444. },
  445. /**
  446. * Load serviceConfigProperties to model
  447. */
  448. loadServiceConfigProperties: function () {
  449. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  450. this.set('content.serviceConfigProperties', serviceConfigProperties);
  451. },
  452. /**
  453. * Generate clients list for selected services and save it to model
  454. * @param stepController step4WizardController
  455. */
  456. saveClients: function (stepController) {
  457. var clients = [];
  458. stepController.get('content').filterProperty('isSelected', true).forEach(function (_service) {
  459. var client = _service.get('serviceComponents').filterProperty('isClient', true);
  460. client.forEach(function (clientComponent) {
  461. clients.pushObject({
  462. component_name: clientComponent.get('componentName'),
  463. display_name: clientComponent.get('displayName'),
  464. isInstalled: false
  465. });
  466. }, this);
  467. }, this);
  468. this.setDBProperty('clientInfo', clients);
  469. this.set('content.clients', clients);
  470. },
  471. /**
  472. * Check validation of the customized local urls
  473. */
  474. checkRepoURL: function (wizardStep1Controller) {
  475. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  476. selectedStack.set('reload', true);
  477. var nameVersionCombo = selectedStack.get('id');
  478. var stackName = nameVersionCombo.split('-')[0];
  479. var stackVersion = nameVersionCombo.split('-')[1];
  480. var dfd = $.Deferred();
  481. if (selectedStack && selectedStack.get('operatingSystems')) {
  482. this.set('validationCnt', selectedStack.get('repositories').filterProperty('isSelected').length);
  483. var verifyBaseUrl = !wizardStep1Controller.get('skipValidationChecked');
  484. selectedStack.get('operatingSystems').forEach(function (os) {
  485. if (os.get('isSelected')) {
  486. os.get('repositories').forEach(function (repo) {
  487. repo.setProperties({
  488. errorTitle: '',
  489. errorContent: '',
  490. validation: App.Repository.validation['INPROGRESS']
  491. });
  492. this.set('content.isCheckInProgress', true);
  493. App.ajax.send({
  494. name: 'wizard.advanced_repositories.valid_url',
  495. sender: this,
  496. data: {
  497. stackName: stackName,
  498. stackVersion: stackVersion,
  499. repoId: repo.get('repoId'),
  500. osType: os.get('osType'),
  501. osId: os.get('id'),
  502. dfd: dfd,
  503. data: {
  504. 'Repositories': {
  505. 'base_url': repo.get('baseUrl'),
  506. "verify_base_url": verifyBaseUrl
  507. }
  508. }
  509. },
  510. success: 'checkRepoURLSuccessCallback',
  511. error: 'checkRepoURLErrorCallback'
  512. });
  513. }, this);
  514. }
  515. }, this);
  516. }
  517. return dfd.promise();
  518. },
  519. /**
  520. * onSuccess callback for check Repo URL.
  521. */
  522. checkRepoURLSuccessCallback: function (response, request, data) {
  523. var selectedStack = this.get('content.stacks').findProperty('isSelected');
  524. if (selectedStack && selectedStack.get('operatingSystems')) {
  525. var os = selectedStack.get('operatingSystems').findProperty('id', data.osId);
  526. var repo = os.get('repositories').findProperty('repoId', data.repoId);
  527. if (repo) {
  528. repo.set('validation', App.Repository.validation['OK']);
  529. }
  530. }
  531. this.set('validationCnt', this.get('validationCnt') - 1);
  532. if (!this.get('validationCnt')) {
  533. this.set('content.isCheckInProgress', false);
  534. data.dfd.resolve();
  535. }
  536. },
  537. /**
  538. * onError callback for check Repo URL.
  539. */
  540. checkRepoURLErrorCallback: function (request, ajaxOptions, error, data, params) {
  541. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  542. if (selectedStack && selectedStack.get('operatingSystems')) {
  543. var os = selectedStack.get('operatingSystems').findProperty('id', params.osId);
  544. var repo = os.get('repositories').findProperty('repoId', params.repoId);
  545. if (repo) {
  546. repo.setProperties({
  547. validation: App.Repository.validation['INVALID'],
  548. errorTitle: request.status + ":" + request.statusText,
  549. errorContent: $.parseJSON(request.responseText) ? $.parseJSON(request.responseText).message : ""
  550. });
  551. }
  552. }
  553. this.set('content.isCheckInProgress', false);
  554. params.dfd.reject();
  555. },
  556. loadMap: {
  557. '0': [
  558. {
  559. type: 'sync',
  560. callback: function () {
  561. this.load('cluster');
  562. }
  563. }
  564. ],
  565. '1': [
  566. {
  567. type: 'async',
  568. callback: function () {
  569. var dfd = $.Deferred();
  570. this.loadStacks().always(function() {
  571. App.router.get('clusterController').loadAmbariProperties().always(function() {
  572. dfd.resolve();
  573. });
  574. });
  575. return dfd.promise();
  576. }
  577. },
  578. {
  579. type: 'async',
  580. callback: function (stacksLoaded) {
  581. var dfd = $.Deferred();
  582. if (!stacksLoaded) {
  583. $.when.apply(this, this.loadStacksVersions()).done(function () {
  584. dfd.resolve(stacksLoaded);
  585. });
  586. } else {
  587. dfd.resolve(stacksLoaded);
  588. }
  589. return dfd.promise();
  590. }
  591. }
  592. ],
  593. '2': [
  594. {
  595. type: 'sync',
  596. callback: function () {
  597. this.load('installOptions');
  598. }
  599. }
  600. ],
  601. '3': [
  602. {
  603. type: 'sync',
  604. callback: function () {
  605. this.loadConfirmedHosts();
  606. }
  607. }
  608. ],
  609. '4': [
  610. {
  611. type: 'async',
  612. callback: function () {
  613. return this.loadServices();
  614. }
  615. }
  616. ],
  617. '5': [
  618. {
  619. type: 'sync',
  620. callback: function () {
  621. this.setSkipSlavesStep(App.StackService.find().filterProperty('isSelected'), 6);
  622. this.loadMasterComponentHosts();
  623. this.loadConfirmedHosts();
  624. this.loadRecommendations();
  625. }
  626. }
  627. ],
  628. '6': [
  629. {
  630. type: 'sync',
  631. callback: function () {
  632. this.loadSlaveComponentHosts();
  633. this.loadClients();
  634. this.loadRecommendations();
  635. }
  636. }
  637. ],
  638. '7': [
  639. {
  640. type: 'async',
  641. callback: function () {
  642. this.loadServiceConfigGroups();
  643. this.loadServiceConfigProperties();
  644. this.loadCurrentHostGroups();
  645. this.loadRecommendationsConfigs();
  646. return this.loadConfigThemes();
  647. }
  648. }
  649. ]
  650. },
  651. /**
  652. * Clear all temporary data
  653. */
  654. finish: function () {
  655. this.setCurrentStep('0');
  656. this.clearStorageData();
  657. App.router.get('userSettingsController').postUserPref('show_bg', true);
  658. },
  659. /**
  660. * Save cluster provisioning state to the server
  661. * @param state cluster provisioning state
  662. */
  663. setClusterProvisioningState: function (state) {
  664. return App.ajax.send({
  665. name: 'cluster.save_provisioning_state',
  666. sender: this,
  667. data: {
  668. state: state
  669. }
  670. });
  671. },
  672. setStepsEnable: function () {
  673. for (var i = 0; i <= this.totalSteps; i++) {
  674. this.get('isStepDisabled').findProperty('step', i).set('value', i > this.get('currentStep'));
  675. }
  676. }.observes('currentStep'),
  677. setLowerStepsDisable: function (stepNo) {
  678. for (var i = 0; i < stepNo; i++) {
  679. var step = this.get('isStepDisabled').findProperty('step', i);
  680. step.set('value', true);
  681. }
  682. },
  683. /**
  684. * Compare jdk versions used for ambari and selected stack.
  685. * Validation check will fire only for non-custom jdk configuration.
  686. *
  687. * @param {Function} successCallback
  688. * @param {Function} failCallback
  689. */
  690. validateJDKVersion: function (successCallback, failCallback) {
  691. var selectedStack = App.Stack.find().findProperty('isSelected', true),
  692. currentJDKVersion = App.router.get('clusterController.ambariProperties')['java.version'],
  693. // use min as max, or max as min version, in case when some of them missed
  694. minJDKVersion = selectedStack.get('minJdkVersion') || selectedStack.get('maxJdkVersion'),
  695. maxJDKVersion = selectedStack.get('maxJdkVersion') || selectedStack.get('minJdkVersion'),
  696. t = Em.I18n.t,
  697. fCallback = failCallback || function() {},
  698. sCallback = successCallback || function() {};
  699. // Skip jdk check if min and max required version not set in stack definition.
  700. if (!minJDKVersion && !maxJDKVersion) {
  701. sCallback();
  702. return;
  703. }
  704. if (currentJDKVersion) {
  705. if (stringUtils.compareVersions(currentJDKVersion, minJDKVersion) < 0 ||
  706. stringUtils.compareVersions(maxJDKVersion, currentJDKVersion) < 0) {
  707. // checks and process only minor part for now
  708. var versionDistance = parseInt(maxJDKVersion.split('.')[1]) - parseInt(minJDKVersion.split('.')[1]);
  709. var versionsList = [minJDKVersion];
  710. for (var i = 1; i < (versionDistance + 1); i++) {
  711. versionsList.push("" + minJDKVersion.split('.')[0] + '.' + (+minJDKVersion.split('.')[1] + i));
  712. }
  713. var versionsString = stringUtils.getFormattedStringFromArray(versionsList, t('or'));
  714. var popupBody = t('popup.jdkValidation.body').format(selectedStack.get('stackName') + ' ' + selectedStack.get('stackVersion'), versionsString, currentJDKVersion);
  715. App.showConfirmationPopup(sCallback, popupBody, fCallback, t('popup.jdkValidation.header'), t('common.proceedAnyway'), true);
  716. return;
  717. }
  718. }
  719. sCallback();
  720. }
  721. });