wizard.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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"
  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. {
  841. value: _configProperties.get('value'),
  842. isRequired: _configProperties.get('isRequired')
  843. }
  844. );
  845. configProperty = App.config.mergeStaticProperties(configProperty, _configProperties, [], ['name', 'filename', 'isUserProperty', 'value']);
  846. if (this.isExcludedConfig(configProperty)) {
  847. configProperty.value = '';
  848. }
  849. serviceConfigProperties.push(configProperty);
  850. }, this);
  851. // check for configs that need to update for installed services
  852. if (installedServiceNamesMap[_content.get('serviceName')]) {
  853. // get only modified configs
  854. var configs = _content.get('configs').filter(function (config) {
  855. if (config.get('isNotDefaultValue') || config.get('savedValue') === null) {
  856. return config.isRequiredByAgent!== false;
  857. }
  858. return false;
  859. });
  860. // if modified configs detected push all service's configs for update
  861. if (configs.length) {
  862. fileNamesToUpdate = fileNamesToUpdate.concat(configs.mapProperty('filename').uniq());
  863. }
  864. }
  865. }, this);
  866. this.setDBProperties({
  867. fileNamesToUpdate: fileNamesToUpdate,
  868. serviceConfigProperties: serviceConfigProperties
  869. });
  870. this.set('content.serviceConfigProperties', serviceConfigProperties);
  871. },
  872. isExcludedConfig: function (configProperty) {
  873. return this.get('sensibleConfigs').mapProperty('name').indexOf(configProperty.name) > -1
  874. && this.get('sensibleConfigs').mapProperty('filename').indexOf(configProperty.filename) > -1;
  875. },
  876. /**
  877. * save Config groups
  878. * @param stepController
  879. * @param isAddService
  880. */
  881. saveServiceConfigGroups: function (stepController, isAddService) {
  882. var serviceConfigGroups = [],
  883. hosts = isAddService ? App.router.get('addServiceController').getDBProperty('hosts') : this.getDBProperty('hosts');
  884. stepController.get('stepConfigs').forEach(function (service) {
  885. // mark group of installed service
  886. var isForInstalledService = service.get('selected') === false;
  887. service.get('configGroups').forEach(function (configGroup) {
  888. var properties = [];
  889. configGroup.get('properties').forEach(function (property) {
  890. properties.push({
  891. name: property.get('name'),
  892. value: property.get('value'),
  893. isFinal: property.get('isFinal'),
  894. filename: property.get('filename')
  895. })
  896. });
  897. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  898. var hostNames = configGroup.get('hosts').map(function(host_name) {return hosts[host_name].id;});
  899. serviceConfigGroups.push({
  900. id: configGroup.get('id'),
  901. name: configGroup.get('name'),
  902. description: configGroup.get('description'),
  903. hosts: hostNames.slice(),
  904. properties: properties.slice(),
  905. is_default: configGroup.get('isDefault'),
  906. is_for_installed_service: isForInstalledService,
  907. is_for_update: configGroup.isForUpdate || configGroup.get('hash') != this.getConfigGroupHash(configGroup, hostNames),
  908. service_name: configGroup.get('serviceName'),
  909. service_id: configGroup.get('serviceName'),
  910. desired_configs: configGroup.get('desiredConfigs'),
  911. child_config_groups: configGroup.get('childConfigGroups') ? configGroup.get('childConfigGroups').mapProperty('id') : [],
  912. parent_config_group_id: configGroup.get('parentConfigGroup.id'),
  913. is_temporary: configGroup.get('isTemporary')
  914. });
  915. }, this)
  916. }, this);
  917. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  918. this.set('content.configGroups', serviceConfigGroups);
  919. },
  920. /**
  921. * generate string hash for config group
  922. * @param {Object} configGroup
  923. * @param {Array|undefined} hosts
  924. * @returns {String|null}
  925. * @method getConfigGroupHash
  926. */
  927. getConfigGroupHash: function(configGroup, hosts) {
  928. if (!Em.get(configGroup, 'properties.length') && !Em.get(configGroup, 'hosts.length') && !hosts) {
  929. return null;
  930. }
  931. var hash = {};
  932. Em.get(configGroup, 'properties').forEach(function (config) {
  933. hash[Em.get(config, 'name')] = {value: Em.get(config, 'value'), isFinal: Em.get(config, 'isFinal')};
  934. });
  935. hash.hosts = hosts || Em.get(configGroup, 'hosts');
  936. return JSON.stringify(hash);
  937. },
  938. /**
  939. * return slaveComponents bound to hosts
  940. * @return {Array}
  941. */
  942. getSlaveComponentHosts: function () {
  943. var components = this.get('slaveComponents');
  944. var result = [];
  945. var installedServices = App.Service.find().mapProperty('serviceName');
  946. var selectedServices = App.StackService.find().filterProperty('isSelected', true).mapProperty('serviceName');
  947. var installedComponentsMap = {};
  948. var uninstalledComponents = [];
  949. components.forEach(function (component) {
  950. if (installedServices.contains(component.get('serviceName'))) {
  951. installedComponentsMap[component.get('componentName')] = [];
  952. } else if (selectedServices.contains(component.get('serviceName'))) {
  953. uninstalledComponents.push(component);
  954. }
  955. }, this);
  956. installedComponentsMap.HDFS_CLIENT = [];
  957. App.HostComponent.find().forEach(function (hostComponent) {
  958. if (installedComponentsMap[hostComponent.get('componentName')]) {
  959. installedComponentsMap[hostComponent.get('componentName')].push(hostComponent.get('hostName'));
  960. }
  961. }, this);
  962. for (var componentName in installedComponentsMap) {
  963. var name = componentName === 'HDFS_CLIENT' ? 'CLIENT' : componentName;
  964. var component = {
  965. componentName: name,
  966. displayName: App.format.role(name, false),
  967. hosts: [],
  968. isInstalled: true
  969. };
  970. installedComponentsMap[componentName].forEach(function (hostName) {
  971. component.hosts.push({
  972. group: "Default",
  973. hostName: hostName,
  974. isInstalled: true
  975. });
  976. }, this);
  977. result.push(component);
  978. }
  979. uninstalledComponents.forEach(function (component) {
  980. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  981. hosts.setEach('isInstalled', false);
  982. result.push({
  983. componentName: component.get('componentName'),
  984. displayName: App.format.role(component.get('componentName'), false),
  985. hosts: hosts,
  986. isInstalled: false
  987. })
  988. });
  989. return result;
  990. },
  991. /**
  992. * Load master component hosts data for using in required step controllers
  993. */
  994. loadMasterComponentHosts: function () {
  995. var masterComponentHosts = this.getDBProperty('masterComponentHosts'),
  996. self = this,
  997. observerContext = {
  998. setMasterComponentHosts: function () {
  999. if (App.get('router.clusterController.isServiceMetricsLoaded')) {
  1000. var stackMasterComponents = App.get('components.masters').uniq();
  1001. App.HostComponent.find().filter(function(component) {
  1002. return stackMasterComponents.contains(component.get('componentName'));
  1003. }).forEach(function (item) {
  1004. masterComponentHosts.push({
  1005. component: item.get('componentName'),
  1006. hostName: item.get('hostName'),
  1007. isInstalled: true,
  1008. serviceId: item.get('service.id'),
  1009. display_name: item.get('displayName')
  1010. })
  1011. });
  1012. self.setDBProperty('masterComponentHosts', masterComponentHosts);
  1013. self.set('content.masterComponentHosts', masterComponentHosts);
  1014. self.removeObserver('App.router.clusterController.isServiceMetricsLoaded', this, 'setMasterComponentHosts');
  1015. dfd.resolve();
  1016. }
  1017. }
  1018. },
  1019. dfd = $.Deferred();
  1020. if (Em.isNone(masterComponentHosts)) {
  1021. masterComponentHosts = [];
  1022. if (App.get('router.clusterController.isServiceMetricsLoaded')) {
  1023. observerContext.setMasterComponentHosts();
  1024. } else {
  1025. this.addObserver('App.router.clusterController.isServiceMetricsLoaded', observerContext, 'setMasterComponentHosts');
  1026. }
  1027. } else {
  1028. this.set('content.masterComponentHosts', masterComponentHosts);
  1029. dfd.resolve();
  1030. }
  1031. return dfd.promise();
  1032. },
  1033. /**
  1034. * Save Master Component Hosts data to Main Controller
  1035. * @param stepController App.WizardStep5Controller
  1036. */
  1037. saveMasterComponentHosts: function (stepController) {
  1038. var obj = stepController.get('selectedServicesMasters');
  1039. var masterComponentHosts = [];
  1040. obj.forEach(function (_component) {
  1041. masterComponentHosts.push({
  1042. display_name: _component.get('display_name'),
  1043. component: _component.get('component_name'),
  1044. hostName: _component.get('selectedHost'),
  1045. serviceId: _component.get('serviceId'),
  1046. isInstalled: _component.get('isInstalled')
  1047. });
  1048. });
  1049. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  1050. this.set('content.masterComponentHosts', masterComponentHosts);
  1051. },
  1052. clearMasterComponentHosts: function() {
  1053. this.set('content.masterComponentHosts', null);
  1054. this.setDBProperty('masterComponentHosts', null);
  1055. },
  1056. /**
  1057. * Load information about hosts with clients components
  1058. */
  1059. loadClients: function () {
  1060. var clients = this.getDBProperty('clientInfo');
  1061. this.set('content.clients', clients);
  1062. },
  1063. /**
  1064. * load methods assigned to each step
  1065. * methods executed in exact order as they described in map
  1066. * @return {object}
  1067. */
  1068. loadAllPriorSteps: function () {
  1069. var currentStep = this.get('currentStep');
  1070. var loadMap = this.get('loadMap');
  1071. var operationStack = [];
  1072. var dfd = $.Deferred();
  1073. for (var s in loadMap) {
  1074. if (parseInt(s, 10) <= parseInt(currentStep, 10)) {
  1075. operationStack.pushObjects(loadMap[s]);
  1076. }
  1077. }
  1078. var sequence = App.actionSequence.create({context: this});
  1079. sequence.setSequence(operationStack).onFinish(function () {
  1080. dfd.resolve();
  1081. }).start();
  1082. return dfd.promise();
  1083. },
  1084. /**
  1085. * return new object extended from clusterStatusTemplate
  1086. * @return Object
  1087. */
  1088. getCluster: function () {
  1089. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  1090. },
  1091. /**
  1092. * Load services data from server.
  1093. */
  1094. loadServicesFromServer: function () {
  1095. var services = this.getDBProperty('services');
  1096. if (!services) {
  1097. services = {
  1098. selectedServices: [],
  1099. installedServices: []
  1100. };
  1101. App.StackService.find().forEach(function(item){
  1102. var isInstalled = App.Service.find().someProperty('id', item.get('serviceName'));
  1103. item.set('isSelected', isInstalled);
  1104. item.set('isInstalled', isInstalled);
  1105. if (isInstalled) {
  1106. services.selectedServices.push(item.get('serviceName'));
  1107. services.installedServices.push(item.get('serviceName'));
  1108. }
  1109. },this);
  1110. this.setDBProperty('services',services);
  1111. } else {
  1112. App.StackService.find().forEach(function(item) {
  1113. var isSelected = services.selectedServices.contains(item.get('serviceName'));
  1114. var isInstalled = services.installedServices.contains(item.get('serviceName'));
  1115. item.set('isSelected', isSelected);
  1116. item.set('isInstalled', isInstalled);
  1117. },this);
  1118. }
  1119. this.set('content.services', App.StackService.find());
  1120. },
  1121. /**
  1122. * Load confirmed hosts.
  1123. * Will be used at <code>Assign Masters(step5)</code> step
  1124. */
  1125. loadConfirmedHosts: function () {
  1126. var hosts = App.db.getHosts();
  1127. if (hosts) {
  1128. this.set('content.hosts', hosts);
  1129. }
  1130. },
  1131. loadHosts: function () {
  1132. var dfd;
  1133. var hostsInDb = this.getDBProperty('hosts');
  1134. if (hostsInDb) {
  1135. this.set('content.hosts', hostsInDb);
  1136. dfd = $.Deferred();
  1137. dfd.resolve();
  1138. } else {
  1139. dfd = App.ajax.send({
  1140. name: 'hosts.confirmed',
  1141. sender: this,
  1142. data: {},
  1143. success: 'loadHostsSuccessCallback',
  1144. error: 'loadHostsErrorCallback'
  1145. });
  1146. }
  1147. return dfd.promise();
  1148. },
  1149. loadHostsSuccessCallback: function (response) {
  1150. var installedHosts = {};
  1151. response.items.forEach(function (item, indx) {
  1152. installedHosts[item.Hosts.host_name] = {
  1153. name: item.Hosts.host_name,
  1154. cpu: item.Hosts.cpu_count,
  1155. memory: item.Hosts.total_mem,
  1156. disk_info: item.Hosts.disk_info,
  1157. osType: item.Hosts.os_type,
  1158. osArch: item.Hosts.os_arch,
  1159. ip: item.Hosts.ip,
  1160. maintenance_state: item.Hosts.maintenance_state,
  1161. bootStatus: "REGISTERED",
  1162. isInstalled: true,
  1163. hostComponents: item.host_components,
  1164. id: indx++
  1165. };
  1166. });
  1167. this.setDBProperty('hosts', installedHosts);
  1168. this.set('content.hosts', installedHosts);
  1169. },
  1170. loadHostsErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  1171. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
  1172. },
  1173. /**
  1174. * Determine if <code>Assign Slaves and Clients</code> step should be skipped
  1175. * @method setSkipSlavesStep
  1176. * @param services
  1177. * @param step
  1178. */
  1179. setSkipSlavesStep: function (services, step) {
  1180. var hasServicesWithSlave = services.someProperty('hasSlave');
  1181. var hasServicesWithClient = services.someProperty('hasClient');
  1182. var hasServicesWithCustomAssignedNonMasters = services.someProperty('hasNonMastersWithCustomAssignment');
  1183. this.set('content.skipSlavesStep', !hasServicesWithSlave && !hasServicesWithClient || !hasServicesWithCustomAssignedNonMasters);
  1184. if (this.get('content.skipSlavesStep')) {
  1185. this.get('isStepDisabled').findProperty('step', step).set('value', this.get('content.skipSlavesStep'));
  1186. }
  1187. },
  1188. /**
  1189. * Load config themes for enhanced config layout.
  1190. *
  1191. * @method loadConfigThemes
  1192. * @return {$.Deferred}
  1193. */
  1194. loadConfigThemes: function () {
  1195. var self = this;
  1196. var dfd = $.Deferred();
  1197. if (!this.get('stackConfigsLoaded')) {
  1198. var serviceNames = App.StackService.find().filter(function (s) {
  1199. return s.get('isSelected') || s.get('isInstalled');
  1200. }).mapProperty('serviceName');
  1201. // Load stack configs before loading themes
  1202. App.config.loadClusterConfigsFromStack().always(function() {
  1203. App.config.loadConfigsFromStack(serviceNames).done(function () {
  1204. self.loadConfigThemeForServices(serviceNames).always(function () {
  1205. self.set('stackConfigsLoaded', true);
  1206. dfd.resolve();
  1207. });
  1208. });
  1209. });
  1210. } else {
  1211. dfd.resolve();
  1212. }
  1213. return dfd.promise();
  1214. },
  1215. /**
  1216. * Clear all config static data
  1217. * and theme info
  1218. *
  1219. * @method clearEnhancedConfigs
  1220. */
  1221. clearEnhancedConfigs: function() {
  1222. App.configsCollection.clearAll();
  1223. App.Section.find().clear();
  1224. App.SubSection.find().clear();
  1225. App.SubSectionTab.find().clear();
  1226. App.Tab.find().clear();
  1227. this.set('stackConfigsLoaded', false);
  1228. },
  1229. /**
  1230. * Cache "stepConfigs" to local storage in name value pairs
  1231. * @param stepController
  1232. */
  1233. cacheStepConfigValues: function(stepController) {
  1234. var self = this;
  1235. var stepConfigs = [];
  1236. stepController.get("stepConfigs").forEach(function (category) {
  1237. var configs = category.configs.map(function(config) {
  1238. if (self.isExcludedConfig(config)) {
  1239. config.set('value', '');
  1240. }
  1241. return {
  1242. name: config.name,
  1243. filename: config.filename,
  1244. value: config.value
  1245. };
  1246. });
  1247. stepConfigs = stepConfigs.concat(configs);
  1248. });
  1249. if (stepConfigs.length > 0 ) {
  1250. this.setDBProperty(stepController.name + "-sc", stepConfigs);
  1251. }
  1252. },
  1253. loadCachedStepConfigValues: function(stepController) {
  1254. return this.getDBProperty(stepController.name + "-sc");
  1255. },
  1256. clearCachedStepConfigValues: function(stepController) {
  1257. this.setDBProperty(stepController.name + "-sc", null);
  1258. },
  1259. saveTasksStatuses: function (tasksStatuses) {
  1260. this.set('content.tasksStatuses', tasksStatuses);
  1261. this.setDBProperty('tasksStatuses', tasksStatuses);
  1262. },
  1263. loadTasksStatuses: function() {
  1264. var tasksStatuses = this.getDBProperty('tasksStatuses');
  1265. this.set('content.tasksStatuses', tasksStatuses);
  1266. },
  1267. saveTasksRequestIds: function (tasksRequestIds) {
  1268. this.set('content.tasksRequestIds', tasksRequestIds);
  1269. this.setDBProperty('tasksRequestIds', tasksRequestIds);
  1270. },
  1271. loadTasksRequestIds: function() {
  1272. var tasksRequestIds = this.getDBProperty('tasksRequestIds');
  1273. this.set('content.tasksRequestIds', tasksRequestIds);
  1274. },
  1275. saveRequestIds: function (requestIds) {
  1276. this.set('content.requestIds', requestIds);
  1277. this.setDBProperty('requestIds', requestIds);
  1278. },
  1279. loadRequestIds: function() {
  1280. var requestIds = this.getDBProperty('requestIds');
  1281. this.set('content.requestIds', requestIds);
  1282. },
  1283. loadRecommendations: function () {
  1284. this.set("content.recommendations", this.getDBProperty('recommendations'));
  1285. },
  1286. /**
  1287. * reset stored wizard data and reload App
  1288. * @param {App.WizardController} controller - wizard controller
  1289. * @param {string} route - preferable path to go after wizard finished
  1290. */
  1291. resetOnClose: function(controller, route) {
  1292. App.router.get('wizardWatcherController').resetUser();
  1293. controller.finish();
  1294. App.router.get('updateController').set('isWorking', true);
  1295. App.clusterStatus.setClusterStatus({
  1296. clusterName: App.get('clusterName'),
  1297. clusterState: 'DEFAULT',
  1298. localdb: App.db.data
  1299. },
  1300. {
  1301. alwaysCallback: function () {
  1302. controller.get('popup').hide();
  1303. App.router.transitionTo(route);
  1304. Em.run.next(function() {
  1305. location.reload();
  1306. });
  1307. }
  1308. });
  1309. }
  1310. });