wizard.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  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. require('models/host');
  20. App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingMixin, {
  21. isStepDisabled: null,
  22. previousStep: 0,
  23. /**
  24. * map of actions which load data required by which step
  25. * used by <code>loadAllPriorSteps</code>
  26. */
  27. loadMap: {},
  28. /**
  29. * Wizard properties in local storage, which should be cleaned right after wizard has been finished
  30. */
  31. dbPropertiesToClean: [
  32. 'service',
  33. 'hosts',
  34. 'masterComponentHosts',
  35. 'slaveComponentHosts',
  36. 'cluster',
  37. 'allHostNames',
  38. 'installOptions',
  39. 'allHostNamesPattern',
  40. 'serviceComponents',
  41. 'fileNamesToUpdate',
  42. 'componentsFromConfigs'
  43. ],
  44. sensibleConfigs: [
  45. { name: 'admin_principal', filename: 'krb5-conf.xml'},
  46. { name: 'admin_password', filename: 'krb5-conf.xml' }
  47. ],
  48. init: function () {
  49. this.clusters = App.Cluster.find();
  50. this.setIsStepDisabled();
  51. },
  52. connectOutlet:function(name) {
  53. if (name !== 'loading') this.set('isStepDisabled.isLocked', false);
  54. App.router.setProperties({
  55. backBtnClickInProgress: false,
  56. nextBtnClickInProgress: false
  57. });
  58. return this._super.apply(this,arguments);
  59. },
  60. /**
  61. * Set <code>isStepDisabled</code> with list of available steps (basing on <code>totalSteps</code>)
  62. * @method setIsStepDisabled
  63. */
  64. setIsStepDisabled: function () {
  65. this.set('isStepDisabled', Ember.ArrayProxy.create({
  66. content:[],
  67. isLocked:true,
  68. objectAtContent: function(idx) {
  69. var obj = this.get('content').objectAt(idx);
  70. if (obj && !obj.hasOwnProperty('isLocked')) {
  71. obj.reopen({
  72. isLocked:true,
  73. get:function (key) {
  74. return key === 'value' && this.get('isLocked') || this._super.apply(this,arguments);
  75. },
  76. notifyValues:function () {
  77. this.notifyPropertyChange('value');
  78. }.observes('isLocked')
  79. });
  80. }
  81. return obj;
  82. },
  83. toggleLock:function () {
  84. this.setEach('isLocked',this.get('isLocked'));
  85. }.observes('isLocked')
  86. }));
  87. this.get('isStepDisabled').pushObject(Em.Object.create({
  88. step: 1,
  89. value: false
  90. }));
  91. for (var i = 2; i <= this.get('totalSteps'); i++) {
  92. this.get('isStepDisabled').pushObject(Em.Object.create({
  93. step: i,
  94. value: true
  95. }));
  96. }
  97. },
  98. slaveComponents: function () {
  99. return App.StackServiceComponent.find().filterProperty('isSlave', true);
  100. }.property('App.router.clusterController.isLoaded'),
  101. allHosts: function () {
  102. var dbHosts = this.get('content.hosts');
  103. var hosts = [];
  104. var hostComponents = [];
  105. for (var hostName in dbHosts) {
  106. hostComponents = [];
  107. var disksOverallCapacity = 0;
  108. var diskFree = 0;
  109. dbHosts[hostName].hostComponents.forEach(function (componentName) {
  110. hostComponents.push(Em.Object.create({
  111. componentName: componentName,
  112. displayName: App.format.role(componentName, false)
  113. }));
  114. });
  115. dbHosts[hostName].disk_info.forEach(function (disk) {
  116. disksOverallCapacity += parseFloat(disk.size);
  117. diskFree += parseFloat(disk.available);
  118. });
  119. hosts.push(Em.Object.create({
  120. id: hostName,
  121. hostName: hostName,
  122. publicHostName: hostName,
  123. diskInfo: dbHosts[hostName].disk_info,
  124. diskTotal: disksOverallCapacity / (1024 * 1024),
  125. diskFree: diskFree / (1024 * 1024),
  126. disksMounted: dbHosts[hostName].disk_info.length,
  127. cpu: dbHosts[hostName].cpu,
  128. memory: dbHosts[hostName].memory,
  129. osType: dbHosts[hostName].osType ? dbHosts[hostName].osType: 0,
  130. osArch: dbHosts[hostName].osArch ? dbHosts[hostName].osArch : 0,
  131. ip: dbHosts[hostName].ip ? dbHosts[hostName].ip: 0,
  132. hostComponents: hostComponents,
  133. maintenanceState: dbHosts[hostName].maintenance_state
  134. }))
  135. }
  136. return hosts;
  137. }.property('content.hosts'),
  138. setStepsEnable: function () {
  139. for (var i = 1; i <= this.totalSteps; i++) {
  140. var step = this.get('isStepDisabled').findProperty('step', i);
  141. if (i <= this.get('currentStep')) {
  142. step.set('value', false);
  143. } else {
  144. step.set('value', true);
  145. }
  146. }
  147. }.observes('currentStep'),
  148. /**
  149. * Enable step link in left nav menu
  150. * @param step - step number
  151. */
  152. enableStep: function (step) {
  153. this.get('isStepDisabled').findProperty('step', step).set('value', false);
  154. },
  155. setLowerStepsDisable: function (stepNo) {
  156. for (var i = 1; i < stepNo; i++) {
  157. var step = this.get('isStepDisabled').findProperty('step', i);
  158. step.set('value', true);
  159. }
  160. },
  161. /**
  162. * Set current step to new value.
  163. * Method moved from App.router.setInstallerCurrentStep
  164. * @param currentStep
  165. * @param completed
  166. */
  167. currentStep: function () {
  168. return App.get('router').getWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10));
  169. }.property(),
  170. /**
  171. * Set current step to new value.
  172. * Method moved from App.router.setInstallerCurrentStep
  173. * @param currentStep
  174. * @param completed
  175. */
  176. setCurrentStep: function (currentStep, completed) {
  177. this.set('previousStep', this.get('currentStep'));
  178. App.db.setWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10), currentStep, completed);
  179. this.set('currentStep', currentStep);
  180. },
  181. clusters: null,
  182. isStep0: function () {
  183. return this.get('currentStep') == 0;
  184. }.property('currentStep'),
  185. isStep1: function () {
  186. return this.get('currentStep') == 1;
  187. }.property('currentStep'),
  188. isStep2: function () {
  189. return this.get('currentStep') == 2;
  190. }.property('currentStep'),
  191. isStep3: function () {
  192. return this.get('currentStep') == 3;
  193. }.property('currentStep'),
  194. isStep4: function () {
  195. return this.get('currentStep') == 4;
  196. }.property('currentStep'),
  197. isStep5: function () {
  198. return this.get('currentStep') == 5;
  199. }.property('currentStep'),
  200. isStep6: function () {
  201. return this.get('currentStep') == 6;
  202. }.property('currentStep'),
  203. isStep7: function () {
  204. return this.get('currentStep') == 7;
  205. }.property('currentStep'),
  206. isStep8: function () {
  207. return this.get('currentStep') == 8;
  208. }.property('currentStep'),
  209. isStep9: function () {
  210. return this.get('currentStep') == 9;
  211. }.property('currentStep'),
  212. isStep10: function () {
  213. return this.get('currentStep') == 10;
  214. }.property('currentStep'),
  215. /**
  216. * Move user to the selected step
  217. *
  218. * @param {number} step number of the step, where user is moved
  219. * @param {boolean} disableNaviWarning true - don't show warning about moving more than 1 step back
  220. * @returns {boolean}
  221. */
  222. gotoStep: function (step, disableNaviWarning) {
  223. if (this.get('isStepDisabled').findProperty('step', step).get('value') !== false) {
  224. return false;
  225. }
  226. // if going back from Step 9 in Install Wizard, delete the checkpoint so that the user is not redirected
  227. // to Step 9
  228. if (this.get('content.controllerName') === 'installerController' && this.get('currentStep') === '9' && step < 9) {
  229. App.clusterStatus.setClusterStatus({
  230. clusterName: this.get('clusterName'),
  231. clusterState: 'CLUSTER_NOT_CREATED_1',
  232. wizardControllerName: 'installerController',
  233. localdb: {}
  234. });
  235. }
  236. if ((this.get('currentStep') - step) > 1 && !disableNaviWarning) {
  237. App.ModalPopup.show({
  238. header: Em.I18n.t('installer.navigation.warning.header'),
  239. onPrimary: function () {
  240. App.router.send('gotoStep' + step);
  241. this.hide();
  242. },
  243. body: "If you proceed to go back to Step " + step + ", you will lose any changes you have made beyond this step"
  244. });
  245. } else {
  246. App.router.send('gotoStep' + step);
  247. }
  248. return true;
  249. },
  250. gotoStep0: function () {
  251. this.gotoStep(0);
  252. },
  253. gotoStep1: function () {
  254. this.gotoStep(1);
  255. },
  256. gotoStep2: function () {
  257. this.gotoStep(2);
  258. },
  259. gotoStep3: function () {
  260. this.gotoStep(3);
  261. },
  262. gotoStep4: function () {
  263. this.gotoStep(4);
  264. },
  265. gotoStep5: function () {
  266. this.gotoStep(5);
  267. },
  268. gotoStep6: function () {
  269. this.gotoStep(6);
  270. },
  271. gotoStep7: function () {
  272. this.gotoStep(7);
  273. },
  274. gotoStep8: function () {
  275. this.gotoStep(8);
  276. },
  277. gotoStep9: function () {
  278. this.gotoStep(9);
  279. },
  280. gotoStep10: function () {
  281. this.gotoStep(10);
  282. },
  283. /**
  284. * Initialize host status info for step9
  285. */
  286. setInfoForStep9: function () {
  287. var hostInfo = this.getDBProperty('hosts');
  288. for (var index in hostInfo) {
  289. hostInfo[index].status = "pending";
  290. hostInfo[index].message = 'Waiting';
  291. hostInfo[index].logTasks = [];
  292. hostInfo[index].tasks = [];
  293. hostInfo[index].progress = '0';
  294. }
  295. this.setDBProperty('hosts', hostInfo);
  296. },
  297. /**
  298. * Remove all data for installOptions step
  299. */
  300. clearInstallOptions: function () {
  301. var installOptions = this.getInstallOptions();
  302. this.set('content.installOptions', installOptions);
  303. this.set('content.hosts', {});
  304. this.setDBProperties({
  305. installOptions: installOptions,
  306. hosts: {}
  307. });
  308. },
  309. toObject: function (object) {
  310. var result = {};
  311. for (var i in object) {
  312. if (object.hasOwnProperty(i)) {
  313. result[i] = object[i];
  314. }
  315. }
  316. return result;
  317. },
  318. /**
  319. * Convert any object or array to pure JS instance without inherit properties
  320. * It is used to convert Ember.Object to pure JS Object and Ember.Array to pure JS Array
  321. * @param originalInstance
  322. * @returns {*}
  323. */
  324. toJSInstance: function (originalInstance) {
  325. var convertedInstance = originalInstance;
  326. if (Em.isArray(originalInstance)) {
  327. convertedInstance = [];
  328. originalInstance.forEach(function (element) {
  329. convertedInstance.push(this.toJSInstance(element));
  330. }, this)
  331. } else if (originalInstance && typeof originalInstance === 'object') {
  332. convertedInstance = {};
  333. for (var property in originalInstance) {
  334. if (originalInstance.hasOwnProperty(property)) {
  335. convertedInstance[property] = this.toJSInstance(originalInstance[property]);
  336. }
  337. }
  338. }
  339. return convertedInstance
  340. },
  341. /**
  342. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  343. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  344. */
  345. saveClusterStatus: function (clusterStatus) {
  346. var oldStatus = this.toObject(this.get('content.cluster'));
  347. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  348. if (clusterStatus.requestId &&
  349. clusterStatus.oldRequestsId.indexOf(clusterStatus.requestId) === -1) {
  350. clusterStatus.oldRequestsId.push(clusterStatus.requestId);
  351. }
  352. this.set('content.cluster', clusterStatus);
  353. this.setDBProperty('cluster', clusterStatus);
  354. },
  355. /**
  356. * Invoke installation of selected services to the server and saves the request id returned by the server.
  357. * @param isRetry
  358. */
  359. installServices: function (isRetry, callback) {
  360. // clear requests since we are installing services
  361. // and we don't want to get tasks for previous install attempts
  362. this.set('content.cluster.oldRequestsId', []);
  363. var data;
  364. callback = callback || Em.K;
  365. if (isRetry) {
  366. data = {
  367. context: Em.I18n.t('requestInfo.installComponents'),
  368. HostRoles: {"state": "INSTALLED"},
  369. urlParams: "HostRoles/desired_state=INSTALLED&HostRoles/state!=INSTALLED"
  370. };
  371. } else {
  372. data = {
  373. context: Em.I18n.t('requestInfo.installServices'),
  374. ServiceInfo: {"state": "INSTALLED"},
  375. urlParams: "ServiceInfo/state=INIT"
  376. };
  377. }
  378. var clusterStatus = {
  379. status: 'PENDING'
  380. };
  381. this.saveClusterStatus(clusterStatus);
  382. App.ajax.send({
  383. name: isRetry ? 'common.host_components.update' : 'common.services.update',
  384. sender: this,
  385. data: data,
  386. success: 'installServicesSuccessCallback',
  387. error: 'installServicesErrorCallback'
  388. }).then(callback, callback);
  389. },
  390. installServicesSuccessCallback: function (jsonData) {
  391. var installStartTime = App.dateTime();
  392. if (jsonData) {
  393. var requestId = jsonData.Requests.id;
  394. var clusterStatus = {
  395. status: 'PENDING',
  396. requestId: requestId,
  397. isInstallError: false,
  398. isCompleted: false,
  399. installStartTime: installStartTime
  400. };
  401. this.saveClusterStatus(clusterStatus);
  402. }
  403. },
  404. installServicesErrorCallback: function (request, ajaxOptions, error) {
  405. var clusterStatus = {
  406. status: 'PENDING',
  407. requestId: this.get('content.cluster.requestId'),
  408. isInstallError: true,
  409. isCompleted: false
  410. };
  411. this.saveClusterStatus(clusterStatus);
  412. App.showAlertPopup(Em.I18n.t('common.errorPopup.header'), request.responseText);
  413. },
  414. /**
  415. * show popup, that display status of bootstrap launching
  416. * @param callback
  417. * @return {Object}
  418. */
  419. showLaunchBootstrapPopup: function (callback) {
  420. return App.ModalPopup.show({
  421. header: Em.I18n.t('installer.step2.bootStrap.header'),
  422. isError: false,
  423. serverError: null,
  424. bodyClass: Em.View.extend({
  425. templateName: require('templates/wizard/bootstrap_call_popup')
  426. }),
  427. showFooter: false,
  428. showCloseButton: false,
  429. secondary: null,
  430. /**
  431. * handle requestId when call is completed,
  432. * if it's correct call callback and hide popup
  433. * otherwise notify error and enable buttons to close popup
  434. * @param requestId
  435. * @param serverError
  436. * @param status
  437. * @param log
  438. */
  439. finishLoading: function (requestId, serverError, status, log) {
  440. if (Em.isNone(requestId) || status === 'ERROR') {
  441. var stepController = App.get('router.wizardStep3Controller');
  442. this.setProperties({
  443. isError: true,
  444. showFooter: true,
  445. showCloseButton: true,
  446. serverError: status === 'ERROR' ? log : serverError
  447. });
  448. stepController.setProperties({
  449. isRegistrationInProgress: false,
  450. isBootstrapFailed: true
  451. });
  452. stepController.get('hosts').setEach('bootStatus', 'FAILED');
  453. } else {
  454. callback(requestId);
  455. this.hide();
  456. }
  457. }
  458. });
  459. },
  460. /**
  461. * Bootstrap selected hosts.
  462. * @param bootStrapData
  463. * @param callback
  464. * @return {Object}
  465. */
  466. launchBootstrap: function (bootStrapData, callback) {
  467. var popup = this.showLaunchBootstrapPopup(callback);
  468. App.ajax.send({
  469. name: 'wizard.launch_bootstrap',
  470. sender: this,
  471. data: {
  472. bootStrapData: bootStrapData,
  473. popup: popup
  474. },
  475. success: 'launchBootstrapSuccessCallback',
  476. error: 'launchBootstrapErrorCallback'
  477. });
  478. return popup;
  479. },
  480. launchBootstrapSuccessCallback: function (data, opt, params) {
  481. params.popup.finishLoading(data.requestId, null, data.status, data.log);
  482. },
  483. launchBootstrapErrorCallback: function (request, ajaxOptions, error, opt, params) {
  484. params.popup.finishLoading(null, error);
  485. },
  486. /**
  487. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  488. * If you specify <code>reload</code> to true - it will reload it.
  489. * @param name
  490. * @param reload
  491. * @return {Boolean}
  492. */
  493. load: function (name, reload) {
  494. if (this.get('content.' + name) && !reload) {
  495. return false;
  496. }
  497. var result = this.getDBProperty(name);
  498. if (!result) {
  499. if (this['get' + name.capitalize()]) {
  500. result = this['get' + name.capitalize()]();
  501. this.setDBProperty(name, result);
  502. }
  503. else {
  504. console.debug('get' + name.capitalize(), ' not defined in the ' + this.get('name'));
  505. }
  506. }
  507. this.set('content.' + name, result);
  508. },
  509. save: function (name) {
  510. var convertedValue = this.toJSInstance(this.get('content.' + name));
  511. this.setDBProperty(name, convertedValue);
  512. },
  513. clear: function () {
  514. this.set('content', Ember.Object.create({
  515. 'controllerName': this.get('content.controllerName')
  516. }));
  517. this.set('currentStep', 0);
  518. this.clearStorageData();
  519. },
  520. clusterStatusTemplate: {
  521. name: "",
  522. status: "PENDING",
  523. isCompleted: false,
  524. requestId: null,
  525. installStartTime: null,
  526. installTime: null,
  527. isInstallError: false,
  528. isStartError: false,
  529. oldRequestsId: []
  530. },
  531. clearStorageData: function () {
  532. var hash = {};
  533. this.get('dbPropertiesToClean').forEach(function (key) {
  534. hash[key] = undefined;
  535. }, this);
  536. this.setDBProperties(hash);
  537. },
  538. getInstallOptions: function() {
  539. return jQuery.extend({}, App.get('isHadoopWindowsStack') ? this.get('installWindowsOptionsTemplate') : this.get('installOptionsTemplate'));
  540. },
  541. installOptionsTemplate: {
  542. hostNames: "", //string
  543. manualInstall: false, //true, false
  544. useSsh: true, //bool
  545. javaHome: App.defaultJavaHome, //string
  546. localRepo: false, //true, false
  547. sshKey: "", //string
  548. bootRequestId: null, //string
  549. sshUser: "root", //string
  550. sshPort: "22",
  551. agentUser: "root" //string
  552. },
  553. installWindowsOptionsTemplate: {
  554. hostNames: "", //string
  555. manualInstall: false, //true, false
  556. useSsh: true, //bool
  557. javaHome: App.defaultJavaHome, //string
  558. localRepo: false, //true, false
  559. sshKey: "", //string
  560. bootRequestId: null, //string
  561. sshUser: "", //string
  562. sshPort: "22",
  563. agentUser: "" //string
  564. },
  565. loadedServiceComponents: null,
  566. /**
  567. * Generate serviceComponents as pr the stack definition and save it to localdata
  568. * called form stepController step4WizardController
  569. */
  570. loadServiceComponents: function () {
  571. return App.ajax.send({
  572. name: 'wizard.service_components',
  573. sender: this,
  574. data: {
  575. stackUrl: App.get('stackVersionURL'),
  576. stackVersion: App.get('currentStackVersionNumber')
  577. },
  578. success: 'loadServiceComponentsSuccessCallback',
  579. error: 'loadServiceComponentsErrorCallback'
  580. });
  581. },
  582. loadServiceComponentsSuccessCallback: function (jsonData) {
  583. var props = this.getDBProperties(['selectedServiceNames', 'installedServiceNames']);
  584. var savedSelectedServices = props.selectedServiceNames;
  585. var savedInstalledServices = props.installedServiceNames;
  586. this.set('content.selectedServiceNames', savedSelectedServices);
  587. this.set('content.installedServiceNames', savedInstalledServices);
  588. if (!savedSelectedServices) {
  589. jsonData.items.forEach(function (service) {
  590. service.StackServices.is_selected = true;
  591. }, this);
  592. } else {
  593. jsonData.items.forEach(function (service) {
  594. service.StackServices.is_selected = savedSelectedServices.contains(service.StackServices.service_name);
  595. }, this);
  596. }
  597. if (!savedInstalledServices) {
  598. jsonData.items.forEach(function (service) {
  599. service.StackServices.is_installed = false;
  600. }, this);
  601. } else {
  602. jsonData.items.forEach(function (service) {
  603. service.StackServices.is_installed = savedInstalledServices.contains(service.StackServices.service_name);
  604. }, this);
  605. }
  606. App.stackServiceMapper.mapStackServices(jsonData);
  607. },
  608. loadServiceComponentsErrorCallback: function (request, ajaxOptions, error) {
  609. },
  610. /**
  611. * load version for services to display on Choose Servoces page
  612. * should load from VersionDefinition endpoint
  613. */
  614. loadServiceVersionFromVersionDefinitions: function () {
  615. return App.ajax.send({
  616. name: 'cluster.load_current_repo_stack_services',
  617. sender: this,
  618. data: {
  619. clusterName: App.clusterName
  620. },
  621. success: 'loadServiceVersionFromVersionDefinitionsSuccessCallback',
  622. error: 'loadServiceVersionFromVersionDefinitionsErrorCallback'
  623. });
  624. },
  625. serviceVersionsMap: {},
  626. loadServiceVersionFromVersionDefinitionsSuccessCallback: function (jsonData) {
  627. var rv = Em.getWithDefault(jsonData, 'items', []).filter(function(i) {
  628. return Em.getWithDefault(i, 'ClusterStackVersions.stack', null) === App.get('currentStackName') &&
  629. Em.getWithDefault(i, 'ClusterStackVersions.version', null) === App.get('currentStackVersionNumber');
  630. })[0];
  631. var map = this.get('serviceVersionsMap');
  632. var stackServices = Em.getWithDefault(rv || {}, 'repository_versions.0.RepositoryVersions.stack_services', false);
  633. if (stackServices) {
  634. stackServices.forEach(function (item) {
  635. map[item.name] = item.versions[0];
  636. });
  637. }
  638. },
  639. loadServiceVersionFromVersionDefinitionsErrorCallback: function (request, ajaxOptions, error) {
  640. },
  641. /**
  642. * Load config groups from local DB
  643. */
  644. loadServiceConfigGroups: function () {
  645. var props = this.getDBProperties(['serviceConfigGroups', 'hosts']);
  646. var serviceConfigGroups = props.serviceConfigGroups,
  647. hosts = props.hosts || {},
  648. host_names = Em.keys(hosts);
  649. if (Em.isNone(serviceConfigGroups)) {
  650. serviceConfigGroups = [];
  651. }
  652. else {
  653. serviceConfigGroups.forEach(function(group) {
  654. var hostNames = group.hosts.map(function(host_id) {
  655. for (var i = 0; i < host_names.length; i++) {
  656. if (hosts[host_names[i]].id === host_id) {
  657. return host_names[i];
  658. }
  659. }
  660. Em.assert('host is missing!!!!', false);
  661. });
  662. Em.set(group, 'hosts', hostNames);
  663. });
  664. }
  665. this.set('content.configGroups', serviceConfigGroups);
  666. },
  667. registerErrPopup: function (header, message) {
  668. App.ModalPopup.show({
  669. header: header,
  670. secondary: false,
  671. bodyClass: Ember.View.extend({
  672. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  673. message: message
  674. })
  675. });
  676. },
  677. /**
  678. * Save hosts that the user confirmed to proceed with from step 3
  679. * @param stepController App.WizardStep3Controller
  680. */
  681. saveConfirmedHosts: function (stepController) {
  682. var hosts = this.get('content.hosts'),
  683. indx = 1;
  684. //add previously installed hosts
  685. for (var hostName in hosts) {
  686. if (!hosts[hostName].isInstalled) {
  687. delete hosts[hostName];
  688. }
  689. }
  690. stepController.get('confirmedHosts').forEach(function (_host) {
  691. if (_host.bootStatus === 'REGISTERED') {
  692. hosts[_host.name] = {
  693. name: _host.name,
  694. cpu: _host.cpu,
  695. memory: _host.memory,
  696. disk_info: _host.disk_info,
  697. os_type: _host.os_type,
  698. os_arch: _host.os_arch,
  699. ip: _host.ip,
  700. maintenance_state: _host.maintenance_state,
  701. bootStatus: _host.bootStatus,
  702. isInstalled: false,
  703. id: indx++
  704. };
  705. }
  706. });
  707. this.setDBProperty('hosts', hosts);
  708. this.set('content.hosts', hosts);
  709. },
  710. /**
  711. * Save data after installation to main controller
  712. * @param stepController App.WizardStep9Controller
  713. */
  714. saveInstalledHosts: function (stepController) {
  715. var hosts = stepController.get('hosts');
  716. var hostInfo = this.getDBProperty('hosts');
  717. for (var index in hostInfo) {
  718. hostInfo[index].status = "pending";
  719. var host = hosts.findProperty('name', hostInfo[index].name);
  720. if (host) {
  721. hostInfo[index].status = host.status;
  722. hostInfo[index].message = host.message;
  723. hostInfo[index].progress = host.progress;
  724. }
  725. }
  726. this.set('content.hosts', hostInfo);
  727. this.setDBProperty('hosts', hostInfo);
  728. },
  729. /**
  730. * Save slaveHostComponents to main controller
  731. * @param stepController
  732. */
  733. saveSlaveComponentHosts: function (stepController) {
  734. var hosts = stepController.get('hosts'),
  735. dbHosts = this.getDBProperty('hosts'),
  736. headers = stepController.get('headers');
  737. var formattedHosts = Ember.Object.create();
  738. headers.forEach(function (header) {
  739. formattedHosts.set(header.get('name'), []);
  740. });
  741. hosts.forEach(function (host) {
  742. var checkboxes = host.checkboxes;
  743. headers.forEach(function (header) {
  744. var cb = checkboxes.findProperty('title', header.get('label'));
  745. if (cb.checked) {
  746. formattedHosts.get(header.get('name')).push({
  747. group: 'Default',
  748. isInstalled: cb.isInstalled,
  749. host_id: dbHosts[host.hostName].id
  750. });
  751. }
  752. });
  753. });
  754. var slaveComponentHosts = [];
  755. headers.forEach(function (header) {
  756. slaveComponentHosts.push({
  757. componentName: header.get('name'),
  758. displayName: header.get('label').replace(/\s/g, ''),
  759. hosts: formattedHosts.get(header.get('name'))
  760. });
  761. });
  762. this.setDBProperty('slaveComponentHosts', slaveComponentHosts);
  763. this.set('content.slaveComponentHosts', slaveComponentHosts);
  764. },
  765. /**
  766. * Return true if cluster data is loaded and false otherwise.
  767. * This is used for all wizard controllers except for installer wizard.
  768. */
  769. dataLoading: function () {
  770. var dfd = $.Deferred();
  771. this.connectOutlet('loading');
  772. if (App.router.get('clusterController.isLoaded')) {
  773. dfd.resolve();
  774. } else {
  775. var interval = setInterval(function () {
  776. if (App.router.get('clusterController.isLoaded')) {
  777. dfd.resolve();
  778. clearInterval(interval);
  779. }
  780. }, 50);
  781. }
  782. return dfd.promise();
  783. },
  784. /**
  785. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  786. * This function is used in reassign master wizard right now.
  787. */
  788. usersLoading: function () {
  789. var self = this;
  790. var dfd = $.Deferred();
  791. var miscController = App.MainAdminServiceAccountsController.create({content: self.get('content')});
  792. miscController.loadUsers();
  793. var interval = setInterval(function () {
  794. if (miscController.get('dataIsLoaded')) {
  795. if (self.get("content.hdfsUser")) {
  796. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  797. }
  798. dfd.resolve();
  799. clearInterval(interval);
  800. }
  801. }, 10);
  802. return dfd.promise();
  803. },
  804. /**
  805. * Save cluster status before going to deploy step
  806. * @param name cluster state. Unique for every wizard
  807. */
  808. saveClusterState: function (name) {
  809. App.clusterStatus.setClusterStatus({
  810. clusterName: this.get('content.cluster.name'),
  811. clusterState: name,
  812. wizardControllerName: this.get('content.controllerName'),
  813. localdb: App.db.data
  814. });
  815. },
  816. /**
  817. * Load serviceConfigProperties to model
  818. */
  819. loadServiceConfigProperties: function () {
  820. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  821. this.set('content.serviceConfigProperties', serviceConfigProperties);
  822. },
  823. /**
  824. * Save config properties
  825. * @param stepController Step7WizardController
  826. */
  827. saveServiceConfigProperties: function (stepController) {
  828. var serviceConfigProperties = [];
  829. var fileNamesToUpdate = this.getDBProperty('fileNamesToUpdate') || [];
  830. var installedServiceNames = stepController.get('installedServiceNames') || [];
  831. var installedServiceNamesMap = installedServiceNames.toWickMap();
  832. stepController.get('stepConfigs').forEach(function (_content) {
  833. if (_content.serviceName === 'YARN') {
  834. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  835. }
  836. _content.get('configs').forEach(function (_configProperty) {
  837. if (!Em.isNone(_configProperty.get('group'))) {
  838. return false;
  839. }
  840. var configProperty = App.config.createMinifiedConfig(_configProperty);
  841. if (this.isExcludedConfig(configProperty)) {
  842. configProperty.value = '';
  843. }
  844. serviceConfigProperties.push(configProperty);
  845. }, this);
  846. // check for configs that need to update for installed services
  847. if (installedServiceNamesMap[_content.get('serviceName')]) {
  848. // get only modified configs
  849. var configs = _content.get('configs').filter(function (config) {
  850. if (config.get('isNotDefaultValue') || config.get('savedValue') === null) {
  851. return config.isRequiredByAgent!== false;
  852. }
  853. return false;
  854. });
  855. // if modified configs detected push all service's configs for update
  856. if (configs.length) {
  857. fileNamesToUpdate = fileNamesToUpdate.concat(configs.mapProperty('filename').uniq());
  858. }
  859. }
  860. }, this);
  861. this.setDBProperties({
  862. fileNamesToUpdate: fileNamesToUpdate,
  863. serviceConfigProperties: serviceConfigProperties
  864. });
  865. this.set('content.serviceConfigProperties', serviceConfigProperties);
  866. },
  867. isExcludedConfig: function (configProperty) {
  868. return this.get('sensibleConfigs').mapProperty('name').indexOf(configProperty.name) > -1
  869. && this.get('sensibleConfigs').mapProperty('filename').indexOf(configProperty.filename) > -1;
  870. },
  871. /**
  872. * save Config groups
  873. * @param stepController
  874. * @param isAddService
  875. */
  876. saveServiceConfigGroups: function (stepController, isAddService) {
  877. var serviceConfigGroups = [],
  878. hosts = isAddService ? App.router.get('addServiceController').getDBProperty('hosts') : this.getDBProperty('hosts');
  879. stepController.get('stepConfigs').forEach(function (service) {
  880. // mark group of installed service
  881. var isForInstalledService = service.get('selected') === false;
  882. service.get('configGroups').forEach(function (configGroup) {
  883. var properties = [];
  884. configGroup.get('properties').forEach(function (property) {
  885. properties.push({
  886. name: property.get('name'),
  887. value: property.get('value'),
  888. isFinal: property.get('isFinal'),
  889. filename: property.get('filename')
  890. })
  891. });
  892. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  893. var hostNames = configGroup.get('hosts').map(function(host_name) {return hosts[host_name].id;});
  894. serviceConfigGroups.push({
  895. id: configGroup.get('id'),
  896. name: configGroup.get('name'),
  897. description: configGroup.get('description'),
  898. hosts: hostNames.slice(),
  899. properties: properties.slice(),
  900. is_default: configGroup.get('isDefault'),
  901. is_for_installed_service: isForInstalledService,
  902. is_for_update: configGroup.isForUpdate || configGroup.get('hash') != this.getConfigGroupHash(configGroup, hostNames),
  903. service_name: configGroup.get('serviceName'),
  904. service_id: configGroup.get('serviceName'),
  905. desired_configs: configGroup.get('desiredConfigs'),
  906. child_config_groups: configGroup.get('childConfigGroups') ? configGroup.get('childConfigGroups').mapProperty('id') : [],
  907. parent_config_group_id: configGroup.get('parentConfigGroup.id'),
  908. is_temporary: configGroup.get('isTemporary')
  909. });
  910. }, this)
  911. }, this);
  912. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  913. this.set('content.configGroups', serviceConfigGroups);
  914. },
  915. /**
  916. * generate string hash for config group
  917. * @param {Object} configGroup
  918. * @param {Array|undefined} hosts
  919. * @returns {String|null}
  920. * @method getConfigGroupHash
  921. */
  922. getConfigGroupHash: function(configGroup, hosts) {
  923. if (!Em.get(configGroup, 'properties.length') && !Em.get(configGroup, 'hosts.length') && !hosts) {
  924. return null;
  925. }
  926. var hash = {};
  927. Em.get(configGroup, 'properties').forEach(function (config) {
  928. hash[Em.get(config, 'name')] = {value: Em.get(config, 'value'), isFinal: Em.get(config, 'isFinal')};
  929. });
  930. hash.hosts = hosts || Em.get(configGroup, 'hosts');
  931. return JSON.stringify(hash);
  932. },
  933. /**
  934. * return slaveComponents bound to hosts
  935. * @return {Array}
  936. */
  937. getSlaveComponentHosts: function () {
  938. var components = this.get('slaveComponents');
  939. var result = [];
  940. var installedServices = App.Service.find().mapProperty('serviceName');
  941. var selectedServices = App.StackService.find().filterProperty('isSelected', true).mapProperty('serviceName');
  942. var installedComponentsMap = {};
  943. var uninstalledComponents = [];
  944. components.forEach(function (component) {
  945. if (installedServices.contains(component.get('serviceName'))) {
  946. installedComponentsMap[component.get('componentName')] = [];
  947. } else if (selectedServices.contains(component.get('serviceName'))) {
  948. uninstalledComponents.push(component);
  949. }
  950. }, this);
  951. installedComponentsMap.HDFS_CLIENT = [];
  952. App.HostComponent.find().forEach(function (hostComponent) {
  953. if (installedComponentsMap[hostComponent.get('componentName')]) {
  954. installedComponentsMap[hostComponent.get('componentName')].push(hostComponent.get('hostName'));
  955. }
  956. }, this);
  957. for (var componentName in installedComponentsMap) {
  958. var name = componentName === 'HDFS_CLIENT' ? 'CLIENT' : componentName;
  959. var component = {
  960. componentName: name,
  961. displayName: App.format.role(name, false),
  962. hosts: [],
  963. isInstalled: true
  964. };
  965. installedComponentsMap[componentName].forEach(function (hostName) {
  966. component.hosts.push({
  967. group: "Default",
  968. hostName: hostName,
  969. isInstalled: true
  970. });
  971. }, this);
  972. result.push(component);
  973. }
  974. uninstalledComponents.forEach(function (component) {
  975. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  976. hosts.setEach('isInstalled', false);
  977. result.push({
  978. componentName: component.get('componentName'),
  979. displayName: App.format.role(component.get('componentName'), false),
  980. hosts: hosts,
  981. isInstalled: false
  982. })
  983. });
  984. return result;
  985. },
  986. /**
  987. * Load master component hosts data for using in required step controllers
  988. */
  989. loadMasterComponentHosts: function () {
  990. var masterComponentHosts = this.getDBProperty('masterComponentHosts'),
  991. self = this,
  992. observerContext = {
  993. setMasterComponentHosts: function () {
  994. if (App.get('router.clusterController.isServiceMetricsLoaded')) {
  995. var stackMasterComponents = App.get('components.masters').uniq();
  996. App.HostComponent.find().filter(function(component) {
  997. return stackMasterComponents.contains(component.get('componentName'));
  998. }).forEach(function (item) {
  999. masterComponentHosts.push({
  1000. component: item.get('componentName'),
  1001. hostName: item.get('hostName'),
  1002. isInstalled: true,
  1003. serviceId: item.get('service.id'),
  1004. display_name: item.get('displayName')
  1005. })
  1006. });
  1007. self.setDBProperty('masterComponentHosts', masterComponentHosts);
  1008. self.set('content.masterComponentHosts', masterComponentHosts);
  1009. self.removeObserver('App.router.clusterController.isServiceMetricsLoaded', this, 'setMasterComponentHosts');
  1010. dfd.resolve();
  1011. }
  1012. }
  1013. },
  1014. dfd = $.Deferred();
  1015. if (Em.isNone(masterComponentHosts)) {
  1016. masterComponentHosts = [];
  1017. if (App.get('router.clusterController.isServiceMetricsLoaded')) {
  1018. observerContext.setMasterComponentHosts();
  1019. } else {
  1020. this.addObserver('App.router.clusterController.isServiceMetricsLoaded', observerContext, 'setMasterComponentHosts');
  1021. }
  1022. } else {
  1023. this.set('content.masterComponentHosts', masterComponentHosts);
  1024. dfd.resolve();
  1025. }
  1026. return dfd.promise();
  1027. },
  1028. /**
  1029. * Save Master Component Hosts data to Main Controller
  1030. * @param stepController App.WizardStep5Controller
  1031. */
  1032. saveMasterComponentHosts: function (stepController) {
  1033. var obj = stepController.get('selectedServicesMasters');
  1034. var masterComponentHosts = [];
  1035. obj.forEach(function (_component) {
  1036. masterComponentHosts.push({
  1037. display_name: _component.get('display_name'),
  1038. component: _component.get('component_name'),
  1039. hostName: _component.get('selectedHost'),
  1040. serviceId: _component.get('serviceId'),
  1041. isInstalled: _component.get('isInstalled')
  1042. });
  1043. });
  1044. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  1045. this.set('content.masterComponentHosts', masterComponentHosts);
  1046. },
  1047. clearMasterComponentHosts: function() {
  1048. this.set('content.masterComponentHosts', null);
  1049. this.setDBProperty('masterComponentHosts', null);
  1050. },
  1051. /**
  1052. * Load information about hosts with clients components
  1053. */
  1054. loadClients: function () {
  1055. var clients = this.getDBProperty('clientInfo');
  1056. this.set('content.clients', clients);
  1057. },
  1058. /**
  1059. * load methods assigned to each step
  1060. * methods executed in exact order as they described in map
  1061. * @return {object}
  1062. */
  1063. loadAllPriorSteps: function () {
  1064. var currentStep = this.get('currentStep');
  1065. var loadMap = this.get('loadMap');
  1066. var operationStack = [];
  1067. var dfd = $.Deferred();
  1068. for (var s in loadMap) {
  1069. if (parseInt(s, 10) <= parseInt(currentStep, 10)) {
  1070. operationStack.pushObjects(loadMap[s]);
  1071. }
  1072. }
  1073. var sequence = App.actionSequence.create({context: this});
  1074. sequence.setSequence(operationStack).onFinish(function () {
  1075. dfd.resolve();
  1076. }).start();
  1077. return dfd.promise();
  1078. },
  1079. /**
  1080. * return new object extended from clusterStatusTemplate
  1081. * @return Object
  1082. */
  1083. getCluster: function () {
  1084. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  1085. },
  1086. /**
  1087. * Load services data from server.
  1088. */
  1089. loadServicesFromServer: function () {
  1090. var services = this.getDBProperty('services');
  1091. if (!services) {
  1092. services = {
  1093. selectedServices: [],
  1094. installedServices: []
  1095. };
  1096. App.StackService.find().forEach(function(item){
  1097. var isInstalled = App.Service.find().someProperty('id', item.get('serviceName'));
  1098. item.set('isSelected', isInstalled);
  1099. item.set('isInstalled', isInstalled);
  1100. if (isInstalled) {
  1101. services.selectedServices.push(item.get('serviceName'));
  1102. services.installedServices.push(item.get('serviceName'));
  1103. }
  1104. },this);
  1105. this.setDBProperty('services',services);
  1106. } else {
  1107. App.StackService.find().forEach(function(item) {
  1108. var isSelected = services.selectedServices.contains(item.get('serviceName'));
  1109. var isInstalled = services.installedServices.contains(item.get('serviceName'));
  1110. item.set('isSelected', isSelected);
  1111. item.set('isInstalled', isInstalled);
  1112. },this);
  1113. }
  1114. this.set('content.services', App.StackService.find());
  1115. },
  1116. /**
  1117. * Load confirmed hosts.
  1118. * Will be used at <code>Assign Masters(step5)</code> step
  1119. */
  1120. loadConfirmedHosts: function () {
  1121. var hosts = App.db.getHosts();
  1122. if (hosts) {
  1123. this.set('content.hosts', hosts);
  1124. }
  1125. },
  1126. loadHosts: function () {
  1127. var dfd;
  1128. var hostsInDb = this.getDBProperty('hosts');
  1129. if (hostsInDb) {
  1130. this.set('content.hosts', hostsInDb);
  1131. dfd = $.Deferred();
  1132. dfd.resolve();
  1133. } else {
  1134. dfd = App.ajax.send({
  1135. name: 'hosts.confirmed',
  1136. sender: this,
  1137. data: {},
  1138. success: 'loadHostsSuccessCallback',
  1139. error: 'loadHostsErrorCallback'
  1140. });
  1141. }
  1142. return dfd.promise();
  1143. },
  1144. loadHostsSuccessCallback: function (response) {
  1145. var installedHosts = {};
  1146. response.items.forEach(function (item, indx) {
  1147. installedHosts[item.Hosts.host_name] = {
  1148. name: item.Hosts.host_name,
  1149. cpu: item.Hosts.cpu_count,
  1150. memory: item.Hosts.total_mem,
  1151. disk_info: item.Hosts.disk_info,
  1152. osType: item.Hosts.os_type,
  1153. osArch: item.Hosts.os_arch,
  1154. ip: item.Hosts.ip,
  1155. maintenance_state: item.Hosts.maintenance_state,
  1156. bootStatus: "REGISTERED",
  1157. isInstalled: true,
  1158. hostComponents: item.host_components,
  1159. id: indx++
  1160. };
  1161. });
  1162. this.setDBProperty('hosts', installedHosts);
  1163. this.set('content.hosts', installedHosts);
  1164. },
  1165. loadHostsErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  1166. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
  1167. },
  1168. /**
  1169. * Determine if <code>Assign Slaves and Clients</code> step should be skipped
  1170. * @method setSkipSlavesStep
  1171. * @param services
  1172. * @param step
  1173. */
  1174. setSkipSlavesStep: function (services, step) {
  1175. var hasServicesWithSlave = services.someProperty('hasSlave');
  1176. var hasServicesWithClient = services.someProperty('hasClient');
  1177. var hasServicesWithCustomAssignedNonMasters = services.someProperty('hasNonMastersWithCustomAssignment');
  1178. this.set('content.skipSlavesStep', !hasServicesWithSlave && !hasServicesWithClient || !hasServicesWithCustomAssignedNonMasters);
  1179. if (this.get('content.skipSlavesStep')) {
  1180. this.get('isStepDisabled').findProperty('step', step).set('value', this.get('content.skipSlavesStep'));
  1181. }
  1182. },
  1183. /**
  1184. * Load config themes for enhanced config layout.
  1185. *
  1186. * @method loadConfigThemes
  1187. * @return {$.Deferred}
  1188. */
  1189. loadConfigThemes: function () {
  1190. var self = this;
  1191. var dfd = $.Deferred();
  1192. if (!this.get('stackConfigsLoaded')) {
  1193. var serviceNames = App.StackService.find().filter(function (s) {
  1194. return s.get('isSelected') || s.get('isInstalled');
  1195. }).mapProperty('serviceName');
  1196. // Load stack configs before loading themes
  1197. App.config.loadClusterConfigsFromStack().always(function() {
  1198. App.config.loadConfigsFromStack(serviceNames).done(function () {
  1199. self.loadConfigThemeForServices(serviceNames).always(function () {
  1200. self.set('stackConfigsLoaded', true);
  1201. dfd.resolve();
  1202. });
  1203. });
  1204. });
  1205. } else {
  1206. dfd.resolve();
  1207. }
  1208. return dfd.promise();
  1209. },
  1210. /**
  1211. * Clear all config static data
  1212. * and theme info
  1213. *
  1214. * @method clearEnhancedConfigs
  1215. */
  1216. clearEnhancedConfigs: function() {
  1217. App.configsCollection.clearAll();
  1218. App.Section.find().clear();
  1219. App.SubSection.find().clear();
  1220. App.SubSectionTab.find().clear();
  1221. App.Tab.find().clear();
  1222. this.set('stackConfigsLoaded', false);
  1223. },
  1224. /**
  1225. * Cache "stepConfigs" to local storage in name value pairs
  1226. * @param stepController
  1227. */
  1228. cacheStepConfigValues: function(stepController) {
  1229. var self = this;
  1230. var stepConfigs = [];
  1231. stepController.get("stepConfigs").forEach(function (category) {
  1232. var configs = category.configs.map(function(config) {
  1233. if (self.isExcludedConfig(config)) {
  1234. config.set('value', '');
  1235. }
  1236. return {
  1237. name: config.name,
  1238. filename: config.filename,
  1239. value: config.value
  1240. };
  1241. });
  1242. stepConfigs = stepConfigs.concat(configs);
  1243. });
  1244. if (stepConfigs.length > 0 ) {
  1245. this.setDBProperty(stepController.name + "-sc", stepConfigs);
  1246. }
  1247. },
  1248. loadCachedStepConfigValues: function(stepController) {
  1249. return this.getDBProperty(stepController.name + "-sc");
  1250. },
  1251. clearCachedStepConfigValues: function(stepController) {
  1252. this.setDBProperty(stepController.name + "-sc", null);
  1253. },
  1254. saveTasksStatuses: function (tasksStatuses) {
  1255. this.set('content.tasksStatuses', tasksStatuses);
  1256. this.setDBProperty('tasksStatuses', tasksStatuses);
  1257. },
  1258. loadTasksStatuses: function() {
  1259. var tasksStatuses = this.getDBProperty('tasksStatuses');
  1260. this.set('content.tasksStatuses', tasksStatuses);
  1261. },
  1262. saveTasksRequestIds: function (tasksRequestIds) {
  1263. this.set('content.tasksRequestIds', tasksRequestIds);
  1264. this.setDBProperty('tasksRequestIds', tasksRequestIds);
  1265. },
  1266. loadTasksRequestIds: function() {
  1267. var tasksRequestIds = this.getDBProperty('tasksRequestIds');
  1268. this.set('content.tasksRequestIds', tasksRequestIds);
  1269. },
  1270. saveRequestIds: function (requestIds) {
  1271. this.set('content.requestIds', requestIds);
  1272. this.setDBProperty('requestIds', requestIds);
  1273. },
  1274. loadRequestIds: function() {
  1275. var requestIds = this.getDBProperty('requestIds');
  1276. this.set('content.requestIds', requestIds);
  1277. },
  1278. saveComponentsFromConfigs: function (componentsFromConfigs) {
  1279. this.set('content.componentsFromConfigs', componentsFromConfigs);
  1280. this.setDBProperty('componentsFromConfigs', componentsFromConfigs);
  1281. },
  1282. loadComponentsFromConfigs: function() {
  1283. var componentsFromConfigs = this.getDBProperty('componentsFromConfigs');
  1284. this.set('content.componentsFromConfigs', componentsFromConfigs);
  1285. },
  1286. loadRecommendations: function () {
  1287. this.set("content.recommendations", this.getDBProperty('recommendations'));
  1288. },
  1289. /**
  1290. * reset stored wizard data and reload App
  1291. * @param {App.WizardController} controller - wizard controller
  1292. * @param {string} route - preferable path to go after wizard finished
  1293. */
  1294. resetOnClose: function(controller, route) {
  1295. App.router.get('wizardWatcherController').resetUser();
  1296. controller.finish();
  1297. App.router.get('updateController').set('isWorking', true);
  1298. App.clusterStatus.setClusterStatus({
  1299. clusterName: App.get('clusterName'),
  1300. clusterState: 'DEFAULT',
  1301. localdb: App.db.data
  1302. },
  1303. {
  1304. alwaysCallback: function () {
  1305. controller.get('popup').hide();
  1306. App.router.transitionTo(route);
  1307. Em.run.next(function() {
  1308. location.reload();
  1309. });
  1310. }
  1311. });
  1312. }
  1313. });