wizard.js 45 KB

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