wizard.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  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 = jsonData.items[0].repository_versions[0].RepositoryVersions;
  628. var map = this.get('serviceVersionsMap');
  629. if (rv) {
  630. rv.stack_services.forEach(function (item) {
  631. map[item.name] = item.versions[0];
  632. });
  633. }
  634. },
  635. loadServiceVersionFromVersionDefinitionsErrorCallback: function (request, ajaxOptions, error) {
  636. },
  637. /**
  638. * Load config groups from local DB
  639. */
  640. loadServiceConfigGroups: function () {
  641. var props = this.getDBProperties(['serviceConfigGroups', 'hosts']);
  642. var serviceConfigGroups = props.serviceConfigGroups,
  643. hosts = props.hosts || {},
  644. host_names = Em.keys(hosts);
  645. if (Em.isNone(serviceConfigGroups)) {
  646. serviceConfigGroups = [];
  647. }
  648. else {
  649. serviceConfigGroups.forEach(function(group) {
  650. var hostNames = group.hosts.map(function(host_id) {
  651. for (var i = 0; i < host_names.length; i++) {
  652. if (hosts[host_names[i]].id === host_id) {
  653. return host_names[i];
  654. }
  655. }
  656. Em.assert('host is missing!!!!', false);
  657. });
  658. Em.set(group, 'hosts', hostNames);
  659. });
  660. }
  661. this.set('content.configGroups', serviceConfigGroups);
  662. },
  663. registerErrPopup: function (header, message) {
  664. App.ModalPopup.show({
  665. header: header,
  666. secondary: false,
  667. bodyClass: Ember.View.extend({
  668. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  669. message: message
  670. })
  671. });
  672. },
  673. /**
  674. * Save hosts that the user confirmed to proceed with from step 3
  675. * @param stepController App.WizardStep3Controller
  676. */
  677. saveConfirmedHosts: function (stepController) {
  678. var hosts = this.get('content.hosts'),
  679. indx = 1;
  680. //add previously installed hosts
  681. for (var hostName in hosts) {
  682. if (!hosts[hostName].isInstalled) {
  683. delete hosts[hostName];
  684. }
  685. }
  686. stepController.get('confirmedHosts').forEach(function (_host) {
  687. if (_host.bootStatus === 'REGISTERED') {
  688. hosts[_host.name] = {
  689. name: _host.name,
  690. cpu: _host.cpu,
  691. memory: _host.memory,
  692. disk_info: _host.disk_info,
  693. os_type: _host.os_type,
  694. os_arch: _host.os_arch,
  695. ip: _host.ip,
  696. maintenance_state: _host.maintenance_state,
  697. bootStatus: _host.bootStatus,
  698. isInstalled: false,
  699. id: indx++
  700. };
  701. }
  702. });
  703. this.setDBProperty('hosts', hosts);
  704. this.set('content.hosts', hosts);
  705. },
  706. /**
  707. * Save data after installation to main controller
  708. * @param stepController App.WizardStep9Controller
  709. */
  710. saveInstalledHosts: function (stepController) {
  711. var hosts = stepController.get('hosts');
  712. var hostInfo = this.getDBProperty('hosts');
  713. for (var index in hostInfo) {
  714. hostInfo[index].status = "pending";
  715. var host = hosts.findProperty('name', hostInfo[index].name);
  716. if (host) {
  717. hostInfo[index].status = host.status;
  718. hostInfo[index].message = host.message;
  719. hostInfo[index].progress = host.progress;
  720. }
  721. }
  722. this.set('content.hosts', hostInfo);
  723. this.setDBProperty('hosts', hostInfo);
  724. },
  725. /**
  726. * Save slaveHostComponents to main controller
  727. * @param stepController
  728. */
  729. saveSlaveComponentHosts: function (stepController) {
  730. var hosts = stepController.get('hosts'),
  731. dbHosts = this.getDBProperty('hosts'),
  732. headers = stepController.get('headers');
  733. var formattedHosts = Ember.Object.create();
  734. headers.forEach(function (header) {
  735. formattedHosts.set(header.get('name'), []);
  736. });
  737. hosts.forEach(function (host) {
  738. var checkboxes = host.checkboxes;
  739. headers.forEach(function (header) {
  740. var cb = checkboxes.findProperty('title', header.get('label'));
  741. if (cb.checked) {
  742. formattedHosts.get(header.get('name')).push({
  743. group: 'Default',
  744. isInstalled: cb.isInstalled,
  745. host_id: dbHosts[host.hostName].id
  746. });
  747. }
  748. });
  749. });
  750. var slaveComponentHosts = [];
  751. headers.forEach(function (header) {
  752. slaveComponentHosts.push({
  753. componentName: header.get('name'),
  754. displayName: header.get('label').replace(/\s/g, ''),
  755. hosts: formattedHosts.get(header.get('name'))
  756. });
  757. });
  758. this.setDBProperty('slaveComponentHosts', slaveComponentHosts);
  759. this.set('content.slaveComponentHosts', slaveComponentHosts);
  760. },
  761. /**
  762. * Return true if cluster data is loaded and false otherwise.
  763. * This is used for all wizard controllers except for installer wizard.
  764. */
  765. dataLoading: function () {
  766. var dfd = $.Deferred();
  767. this.connectOutlet('loading');
  768. if (App.router.get('clusterController.isLoaded')) {
  769. dfd.resolve();
  770. } else {
  771. var interval = setInterval(function () {
  772. if (App.router.get('clusterController.isLoaded')) {
  773. dfd.resolve();
  774. clearInterval(interval);
  775. }
  776. }, 50);
  777. }
  778. return dfd.promise();
  779. },
  780. /**
  781. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  782. * This function is used in reassign master wizard right now.
  783. */
  784. usersLoading: function () {
  785. var self = this;
  786. var dfd = $.Deferred();
  787. var miscController = App.MainAdminServiceAccountsController.create({content: self.get('content')});
  788. miscController.loadUsers();
  789. var interval = setInterval(function () {
  790. if (miscController.get('dataIsLoaded')) {
  791. if (self.get("content.hdfsUser")) {
  792. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  793. }
  794. dfd.resolve();
  795. clearInterval(interval);
  796. }
  797. }, 10);
  798. return dfd.promise();
  799. },
  800. /**
  801. * Save cluster status before going to deploy step
  802. * @param name cluster state. Unique for every wizard
  803. */
  804. saveClusterState: function (name) {
  805. App.clusterStatus.setClusterStatus({
  806. clusterName: this.get('content.cluster.name'),
  807. clusterState: name,
  808. wizardControllerName: this.get('content.controllerName'),
  809. localdb: App.db.data
  810. });
  811. },
  812. /**
  813. * Load serviceConfigProperties to model
  814. */
  815. loadServiceConfigProperties: function () {
  816. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  817. this.set('content.serviceConfigProperties', serviceConfigProperties);
  818. },
  819. /**
  820. * Save config properties
  821. * @param stepController Step7WizardController
  822. */
  823. saveServiceConfigProperties: function (stepController) {
  824. var serviceConfigProperties = [];
  825. var fileNamesToUpdate = this.getDBProperty('fileNamesToUpdate') || [];
  826. var installedServiceNames = stepController.get('installedServiceNames') || [];
  827. var installedServiceNamesMap = installedServiceNames.toWickMap();
  828. stepController.get('stepConfigs').forEach(function (_content) {
  829. if (_content.serviceName === 'YARN') {
  830. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  831. }
  832. _content.get('configs').forEach(function (_configProperties) {
  833. if (!Em.isNone(_configProperties.get('group'))) {
  834. return false;
  835. }
  836. var configProperty = App.config.createDefaultConfig(
  837. _configProperties.get('name'),
  838. _configProperties.get('filename'),
  839. // need to invert boolean because this argument will be inverted in method body
  840. !_configProperties.get('isUserProperty'),
  841. _configProperties.getProperties('value', 'isRequired', 'errorMessage', 'warnMessage')
  842. );
  843. configProperty = App.config.mergeStaticProperties(configProperty, _configProperties, [], ['name', 'filename', 'isUserProperty', 'value']);
  844. if (this.isExcludedConfig(configProperty)) {
  845. configProperty.value = '';
  846. }
  847. serviceConfigProperties.push(configProperty);
  848. }, this);
  849. // check for configs that need to update for installed services
  850. if (installedServiceNamesMap[_content.get('serviceName')]) {
  851. // get only modified configs
  852. var configs = _content.get('configs').filter(function (config) {
  853. if (config.get('isNotDefaultValue') || config.get('savedValue') === null) {
  854. return config.isRequiredByAgent!== false;
  855. }
  856. return false;
  857. });
  858. // if modified configs detected push all service's configs for update
  859. if (configs.length) {
  860. fileNamesToUpdate = fileNamesToUpdate.concat(configs.mapProperty('filename').uniq());
  861. }
  862. }
  863. }, this);
  864. this.setDBProperties({
  865. fileNamesToUpdate: fileNamesToUpdate,
  866. serviceConfigProperties: serviceConfigProperties
  867. });
  868. this.set('content.serviceConfigProperties', serviceConfigProperties);
  869. },
  870. isExcludedConfig: function (configProperty) {
  871. return this.get('sensibleConfigs').mapProperty('name').indexOf(configProperty.name) > -1
  872. && this.get('sensibleConfigs').mapProperty('filename').indexOf(configProperty.filename) > -1;
  873. },
  874. /**
  875. * save Config groups
  876. * @param stepController
  877. * @param isAddService
  878. */
  879. saveServiceConfigGroups: function (stepController, isAddService) {
  880. var serviceConfigGroups = [],
  881. hosts = isAddService ? App.router.get('addServiceController').getDBProperty('hosts') : this.getDBProperty('hosts');
  882. stepController.get('stepConfigs').forEach(function (service) {
  883. // mark group of installed service
  884. var isForInstalledService = service.get('selected') === false;
  885. service.get('configGroups').forEach(function (configGroup) {
  886. var properties = [];
  887. configGroup.get('properties').forEach(function (property) {
  888. properties.push({
  889. name: property.get('name'),
  890. value: property.get('value'),
  891. isFinal: property.get('isFinal'),
  892. filename: property.get('filename')
  893. })
  894. });
  895. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  896. var hostNames = configGroup.get('hosts').map(function(host_name) {return hosts[host_name].id;});
  897. serviceConfigGroups.push({
  898. id: configGroup.get('id'),
  899. name: configGroup.get('name'),
  900. description: configGroup.get('description'),
  901. hosts: hostNames.slice(),
  902. properties: properties.slice(),
  903. is_default: configGroup.get('isDefault'),
  904. is_for_installed_service: isForInstalledService,
  905. is_for_update: configGroup.isForUpdate || configGroup.get('hash') != this.getConfigGroupHash(configGroup, hostNames),
  906. service_name: configGroup.get('serviceName'),
  907. service_id: configGroup.get('serviceName'),
  908. desired_configs: configGroup.get('desiredConfigs'),
  909. child_config_groups: configGroup.get('childConfigGroups') ? configGroup.get('childConfigGroups').mapProperty('id') : [],
  910. parent_config_group_id: configGroup.get('parentConfigGroup.id'),
  911. is_temporary: configGroup.get('isTemporary')
  912. });
  913. }, this)
  914. }, this);
  915. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  916. this.set('content.configGroups', serviceConfigGroups);
  917. },
  918. /**
  919. * generate string hash for config group
  920. * @param {Object} configGroup
  921. * @param {Array|undefined} hosts
  922. * @returns {String|null}
  923. * @method getConfigGroupHash
  924. */
  925. getConfigGroupHash: function(configGroup, hosts) {
  926. if (!Em.get(configGroup, 'properties.length') && !Em.get(configGroup, 'hosts.length') && !hosts) {
  927. return null;
  928. }
  929. var hash = {};
  930. Em.get(configGroup, 'properties').forEach(function (config) {
  931. hash[Em.get(config, 'name')] = {value: Em.get(config, 'value'), isFinal: Em.get(config, 'isFinal')};
  932. });
  933. hash.hosts = hosts || Em.get(configGroup, 'hosts');
  934. return JSON.stringify(hash);
  935. },
  936. /**
  937. * return slaveComponents bound to hosts
  938. * @return {Array}
  939. */
  940. getSlaveComponentHosts: function () {
  941. var components = this.get('slaveComponents');
  942. var result = [];
  943. var installedServices = App.Service.find().mapProperty('serviceName');
  944. var selectedServices = App.StackService.find().filterProperty('isSelected', true).mapProperty('serviceName');
  945. var installedComponentsMap = {};
  946. var uninstalledComponents = [];
  947. components.forEach(function (component) {
  948. if (installedServices.contains(component.get('serviceName'))) {
  949. installedComponentsMap[component.get('componentName')] = [];
  950. } else if (selectedServices.contains(component.get('serviceName'))) {
  951. uninstalledComponents.push(component);
  952. }
  953. }, this);
  954. installedComponentsMap.HDFS_CLIENT = [];
  955. App.HostComponent.find().forEach(function (hostComponent) {
  956. if (installedComponentsMap[hostComponent.get('componentName')]) {
  957. installedComponentsMap[hostComponent.get('componentName')].push(hostComponent.get('hostName'));
  958. }
  959. }, this);
  960. for (var componentName in installedComponentsMap) {
  961. var name = componentName === 'HDFS_CLIENT' ? 'CLIENT' : componentName;
  962. var component = {
  963. componentName: name,
  964. displayName: App.format.role(name, false),
  965. hosts: [],
  966. isInstalled: true
  967. };
  968. installedComponentsMap[componentName].forEach(function (hostName) {
  969. component.hosts.push({
  970. group: "Default",
  971. hostName: hostName,
  972. isInstalled: true
  973. });
  974. }, this);
  975. result.push(component);
  976. }
  977. uninstalledComponents.forEach(function (component) {
  978. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  979. hosts.setEach('isInstalled', false);
  980. result.push({
  981. componentName: component.get('componentName'),
  982. displayName: App.format.role(component.get('componentName'), false),
  983. hosts: hosts,
  984. isInstalled: false
  985. })
  986. });
  987. return result;
  988. },
  989. /**
  990. * Load master component hosts data for using in required step controllers
  991. */
  992. loadMasterComponentHosts: function () {
  993. var masterComponentHosts = this.getDBProperty('masterComponentHosts'),
  994. self = this,
  995. observerContext = {
  996. setMasterComponentHosts: function () {
  997. if (App.get('router.clusterController.isServiceMetricsLoaded')) {
  998. var stackMasterComponents = App.get('components.masters').uniq();
  999. App.HostComponent.find().filter(function(component) {
  1000. return stackMasterComponents.contains(component.get('componentName'));
  1001. }).forEach(function (item) {
  1002. masterComponentHosts.push({
  1003. component: item.get('componentName'),
  1004. hostName: item.get('hostName'),
  1005. isInstalled: true,
  1006. serviceId: item.get('service.id'),
  1007. display_name: item.get('displayName')
  1008. })
  1009. });
  1010. self.setDBProperty('masterComponentHosts', masterComponentHosts);
  1011. self.set('content.masterComponentHosts', masterComponentHosts);
  1012. self.removeObserver('App.router.clusterController.isServiceMetricsLoaded', this, 'setMasterComponentHosts');
  1013. dfd.resolve();
  1014. }
  1015. }
  1016. },
  1017. dfd = $.Deferred();
  1018. if (Em.isNone(masterComponentHosts)) {
  1019. masterComponentHosts = [];
  1020. if (App.get('router.clusterController.isServiceMetricsLoaded')) {
  1021. observerContext.setMasterComponentHosts();
  1022. } else {
  1023. this.addObserver('App.router.clusterController.isServiceMetricsLoaded', observerContext, 'setMasterComponentHosts');
  1024. }
  1025. } else {
  1026. this.set('content.masterComponentHosts', masterComponentHosts);
  1027. dfd.resolve();
  1028. }
  1029. return dfd.promise();
  1030. },
  1031. /**
  1032. * Save Master Component Hosts data to Main Controller
  1033. * @param stepController App.WizardStep5Controller
  1034. */
  1035. saveMasterComponentHosts: function (stepController) {
  1036. var obj = stepController.get('selectedServicesMasters');
  1037. var masterComponentHosts = [];
  1038. obj.forEach(function (_component) {
  1039. masterComponentHosts.push({
  1040. display_name: _component.get('display_name'),
  1041. component: _component.get('component_name'),
  1042. hostName: _component.get('selectedHost'),
  1043. serviceId: _component.get('serviceId'),
  1044. isInstalled: _component.get('isInstalled')
  1045. });
  1046. });
  1047. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  1048. this.set('content.masterComponentHosts', masterComponentHosts);
  1049. },
  1050. clearMasterComponentHosts: function() {
  1051. this.set('content.masterComponentHosts', null);
  1052. this.setDBProperty('masterComponentHosts', null);
  1053. },
  1054. /**
  1055. * Load information about hosts with clients components
  1056. */
  1057. loadClients: function () {
  1058. var clients = this.getDBProperty('clientInfo');
  1059. this.set('content.clients', clients);
  1060. },
  1061. /**
  1062. * load methods assigned to each step
  1063. * methods executed in exact order as they described in map
  1064. * @return {object}
  1065. */
  1066. loadAllPriorSteps: function () {
  1067. var currentStep = this.get('currentStep');
  1068. var loadMap = this.get('loadMap');
  1069. var operationStack = [];
  1070. var dfd = $.Deferred();
  1071. for (var s in loadMap) {
  1072. if (parseInt(s, 10) <= parseInt(currentStep, 10)) {
  1073. operationStack.pushObjects(loadMap[s]);
  1074. }
  1075. }
  1076. var sequence = App.actionSequence.create({context: this});
  1077. sequence.setSequence(operationStack).onFinish(function () {
  1078. dfd.resolve();
  1079. }).start();
  1080. return dfd.promise();
  1081. },
  1082. /**
  1083. * return new object extended from clusterStatusTemplate
  1084. * @return Object
  1085. */
  1086. getCluster: function () {
  1087. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  1088. },
  1089. /**
  1090. * Load services data from server.
  1091. */
  1092. loadServicesFromServer: function () {
  1093. var services = this.getDBProperty('services');
  1094. if (!services) {
  1095. services = {
  1096. selectedServices: [],
  1097. installedServices: []
  1098. };
  1099. App.StackService.find().forEach(function(item){
  1100. var isInstalled = App.Service.find().someProperty('id', item.get('serviceName'));
  1101. item.set('isSelected', isInstalled);
  1102. item.set('isInstalled', isInstalled);
  1103. if (isInstalled) {
  1104. services.selectedServices.push(item.get('serviceName'));
  1105. services.installedServices.push(item.get('serviceName'));
  1106. }
  1107. },this);
  1108. this.setDBProperty('services',services);
  1109. } else {
  1110. App.StackService.find().forEach(function(item) {
  1111. var isSelected = services.selectedServices.contains(item.get('serviceName'));
  1112. var isInstalled = services.installedServices.contains(item.get('serviceName'));
  1113. item.set('isSelected', isSelected);
  1114. item.set('isInstalled', isInstalled);
  1115. },this);
  1116. }
  1117. this.set('content.services', App.StackService.find());
  1118. },
  1119. /**
  1120. * Load confirmed hosts.
  1121. * Will be used at <code>Assign Masters(step5)</code> step
  1122. */
  1123. loadConfirmedHosts: function () {
  1124. var hosts = App.db.getHosts();
  1125. if (hosts) {
  1126. this.set('content.hosts', hosts);
  1127. }
  1128. },
  1129. loadHosts: function () {
  1130. var dfd;
  1131. var hostsInDb = this.getDBProperty('hosts');
  1132. if (hostsInDb) {
  1133. this.set('content.hosts', hostsInDb);
  1134. dfd = $.Deferred();
  1135. dfd.resolve();
  1136. } else {
  1137. dfd = App.ajax.send({
  1138. name: 'hosts.confirmed',
  1139. sender: this,
  1140. data: {},
  1141. success: 'loadHostsSuccessCallback',
  1142. error: 'loadHostsErrorCallback'
  1143. });
  1144. }
  1145. return dfd.promise();
  1146. },
  1147. loadHostsSuccessCallback: function (response) {
  1148. var installedHosts = {};
  1149. response.items.forEach(function (item, indx) {
  1150. installedHosts[item.Hosts.host_name] = {
  1151. name: item.Hosts.host_name,
  1152. cpu: item.Hosts.cpu_count,
  1153. memory: item.Hosts.total_mem,
  1154. disk_info: item.Hosts.disk_info,
  1155. osType: item.Hosts.os_type,
  1156. osArch: item.Hosts.os_arch,
  1157. ip: item.Hosts.ip,
  1158. maintenance_state: item.Hosts.maintenance_state,
  1159. bootStatus: "REGISTERED",
  1160. isInstalled: true,
  1161. hostComponents: item.host_components,
  1162. id: indx++
  1163. };
  1164. });
  1165. this.setDBProperty('hosts', installedHosts);
  1166. this.set('content.hosts', installedHosts);
  1167. },
  1168. loadHostsErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  1169. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
  1170. },
  1171. /**
  1172. * Determine if <code>Assign Slaves and Clients</code> step should be skipped
  1173. * @method setSkipSlavesStep
  1174. * @param services
  1175. * @param step
  1176. */
  1177. setSkipSlavesStep: function (services, step) {
  1178. var hasServicesWithSlave = services.someProperty('hasSlave');
  1179. var hasServicesWithClient = services.someProperty('hasClient');
  1180. var hasServicesWithCustomAssignedNonMasters = services.someProperty('hasNonMastersWithCustomAssignment');
  1181. this.set('content.skipSlavesStep', !hasServicesWithSlave && !hasServicesWithClient || !hasServicesWithCustomAssignedNonMasters);
  1182. if (this.get('content.skipSlavesStep')) {
  1183. this.get('isStepDisabled').findProperty('step', step).set('value', this.get('content.skipSlavesStep'));
  1184. }
  1185. },
  1186. /**
  1187. * Load config themes for enhanced config layout.
  1188. *
  1189. * @method loadConfigThemes
  1190. * @return {$.Deferred}
  1191. */
  1192. loadConfigThemes: function () {
  1193. var self = this;
  1194. var dfd = $.Deferred();
  1195. if (!this.get('stackConfigsLoaded')) {
  1196. var serviceNames = App.StackService.find().filter(function (s) {
  1197. return s.get('isSelected') || s.get('isInstalled');
  1198. }).mapProperty('serviceName');
  1199. // Load stack configs before loading themes
  1200. App.config.loadClusterConfigsFromStack().always(function() {
  1201. App.config.loadConfigsFromStack(serviceNames).done(function () {
  1202. self.loadConfigThemeForServices(serviceNames).always(function () {
  1203. self.set('stackConfigsLoaded', true);
  1204. dfd.resolve();
  1205. });
  1206. });
  1207. });
  1208. } else {
  1209. dfd.resolve();
  1210. }
  1211. return dfd.promise();
  1212. },
  1213. /**
  1214. * Clear all config static data
  1215. * and theme info
  1216. *
  1217. * @method clearEnhancedConfigs
  1218. */
  1219. clearEnhancedConfigs: function() {
  1220. App.configsCollection.clearAll();
  1221. App.Section.find().clear();
  1222. App.SubSection.find().clear();
  1223. App.SubSectionTab.find().clear();
  1224. App.Tab.find().clear();
  1225. this.set('stackConfigsLoaded', false);
  1226. },
  1227. /**
  1228. * Cache "stepConfigs" to local storage in name value pairs
  1229. * @param stepController
  1230. */
  1231. cacheStepConfigValues: function(stepController) {
  1232. var self = this;
  1233. var stepConfigs = [];
  1234. stepController.get("stepConfigs").forEach(function (category) {
  1235. var configs = category.configs.map(function(config) {
  1236. if (self.isExcludedConfig(config)) {
  1237. config.set('value', '');
  1238. }
  1239. return {
  1240. name: config.name,
  1241. filename: config.filename,
  1242. value: config.value
  1243. };
  1244. });
  1245. stepConfigs = stepConfigs.concat(configs);
  1246. });
  1247. if (stepConfigs.length > 0 ) {
  1248. this.setDBProperty(stepController.name + "-sc", stepConfigs);
  1249. }
  1250. },
  1251. loadCachedStepConfigValues: function(stepController) {
  1252. return this.getDBProperty(stepController.name + "-sc");
  1253. },
  1254. clearCachedStepConfigValues: function(stepController) {
  1255. this.setDBProperty(stepController.name + "-sc", null);
  1256. },
  1257. saveTasksStatuses: function (tasksStatuses) {
  1258. this.set('content.tasksStatuses', tasksStatuses);
  1259. this.setDBProperty('tasksStatuses', tasksStatuses);
  1260. },
  1261. loadTasksStatuses: function() {
  1262. var tasksStatuses = this.getDBProperty('tasksStatuses');
  1263. this.set('content.tasksStatuses', tasksStatuses);
  1264. },
  1265. saveTasksRequestIds: function (tasksRequestIds) {
  1266. this.set('content.tasksRequestIds', tasksRequestIds);
  1267. this.setDBProperty('tasksRequestIds', tasksRequestIds);
  1268. },
  1269. loadTasksRequestIds: function() {
  1270. var tasksRequestIds = this.getDBProperty('tasksRequestIds');
  1271. this.set('content.tasksRequestIds', tasksRequestIds);
  1272. },
  1273. saveRequestIds: function (requestIds) {
  1274. this.set('content.requestIds', requestIds);
  1275. this.setDBProperty('requestIds', requestIds);
  1276. },
  1277. loadRequestIds: function() {
  1278. var requestIds = this.getDBProperty('requestIds');
  1279. this.set('content.requestIds', requestIds);
  1280. },
  1281. saveComponentsFromConfigs: function (componentsFromConfigs) {
  1282. this.set('content.componentsFromConfigs', componentsFromConfigs);
  1283. this.setDBProperty('componentsFromConfigs', componentsFromConfigs);
  1284. },
  1285. loadComponentsFromConfigs: function() {
  1286. var componentsFromConfigs = this.getDBProperty('componentsFromConfigs');
  1287. this.set('content.componentsFromConfigs', componentsFromConfigs);
  1288. },
  1289. loadRecommendations: function () {
  1290. this.set("content.recommendations", this.getDBProperty('recommendations'));
  1291. },
  1292. /**
  1293. * reset stored wizard data and reload App
  1294. * @param {App.WizardController} controller - wizard controller
  1295. * @param {string} route - preferable path to go after wizard finished
  1296. */
  1297. resetOnClose: function(controller, route) {
  1298. App.router.get('wizardWatcherController').resetUser();
  1299. controller.finish();
  1300. App.router.get('updateController').set('isWorking', true);
  1301. App.clusterStatus.setClusterStatus({
  1302. clusterName: App.get('clusterName'),
  1303. clusterState: 'DEFAULT',
  1304. localdb: App.db.data
  1305. },
  1306. {
  1307. alwaysCallback: function () {
  1308. controller.get('popup').hide();
  1309. App.router.transitionTo(route);
  1310. Em.run.next(function() {
  1311. location.reload();
  1312. });
  1313. }
  1314. });
  1315. }
  1316. });