wizard.js 47 KB

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