wizard.js 41 KB

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