wizard.js 41 KB

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