wizard.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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, {
  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. setLowerStepsDisable: function (stepNo) {
  105. for (var i = 1; i < stepNo; i++) {
  106. var step = this.get('isStepDisabled').findProperty('step', i);
  107. step.set('value', true);
  108. }
  109. },
  110. /**
  111. * Set current step to new value.
  112. * Method moved from App.router.setInstallerCurrentStep
  113. * @param currentStep
  114. * @param completed
  115. */
  116. currentStep: function () {
  117. return App.get('router').getWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10));
  118. }.property(),
  119. /**
  120. * Set current step to new value.
  121. * Method moved from App.router.setInstallerCurrentStep
  122. * @param currentStep
  123. * @param completed
  124. */
  125. setCurrentStep: function (currentStep, completed) {
  126. App.db.setWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10), currentStep, completed);
  127. this.set('currentStep', currentStep);
  128. },
  129. clusters: null,
  130. isStep0: function () {
  131. return this.get('currentStep') == 0;
  132. }.property('currentStep'),
  133. isStep1: function () {
  134. return this.get('currentStep') == 1;
  135. }.property('currentStep'),
  136. isStep2: function () {
  137. return this.get('currentStep') == 2;
  138. }.property('currentStep'),
  139. isStep3: function () {
  140. return this.get('currentStep') == 3;
  141. }.property('currentStep'),
  142. isStep4: function () {
  143. return this.get('currentStep') == 4;
  144. }.property('currentStep'),
  145. isStep5: function () {
  146. return this.get('currentStep') == 5;
  147. }.property('currentStep'),
  148. isStep6: function () {
  149. return this.get('currentStep') == 6;
  150. }.property('currentStep'),
  151. isStep7: function () {
  152. return this.get('currentStep') == 7;
  153. }.property('currentStep'),
  154. isStep8: function () {
  155. return this.get('currentStep') == 8;
  156. }.property('currentStep'),
  157. isStep9: function () {
  158. return this.get('currentStep') == 9;
  159. }.property('currentStep'),
  160. isStep10: function () {
  161. return this.get('currentStep') == 10;
  162. }.property('currentStep'),
  163. gotoStep: function (step, disableNaviWarning) {
  164. if (this.get('isStepDisabled').findProperty('step', step).get('value') !== false) {
  165. return false;
  166. }
  167. // if going back from Step 9 in Install Wizard, delete the checkpoint so that the user is not redirected
  168. // to Step 9
  169. if (this.get('content.controllerName') == 'installerController' && this.get('currentStep') === '9' && step < 9) {
  170. App.clusterStatus.setClusterStatus({
  171. clusterName: this.get('clusterName'),
  172. clusterState: 'CLUSTER_NOT_CREATED_1',
  173. wizardControllerName: 'installerController',
  174. localdb: App.db.data
  175. });
  176. }
  177. if ((this.get('currentStep') - step) > 1 && !disableNaviWarning) {
  178. App.ModalPopup.show({
  179. header: Em.I18n.t('installer.navigation.warning.header'),
  180. onPrimary: function () {
  181. App.router.send('gotoStep' + step);
  182. this.hide();
  183. },
  184. body: "If you proceed to go back to Step " + step + ", you will lose any changes you have made beyond this step"
  185. });
  186. } else {
  187. App.router.send('gotoStep' + step);
  188. }
  189. return true;
  190. },
  191. gotoStep0: function () {
  192. this.gotoStep(0);
  193. },
  194. gotoStep1: function () {
  195. this.gotoStep(1);
  196. },
  197. gotoStep2: function () {
  198. this.gotoStep(2);
  199. },
  200. gotoStep3: function () {
  201. this.gotoStep(3);
  202. },
  203. gotoStep4: function () {
  204. this.gotoStep(4);
  205. },
  206. gotoStep5: function () {
  207. this.gotoStep(5);
  208. },
  209. gotoStep6: function () {
  210. this.gotoStep(6);
  211. },
  212. gotoStep7: function () {
  213. this.gotoStep(7);
  214. },
  215. gotoStep8: function () {
  216. this.gotoStep(8);
  217. },
  218. gotoStep9: function () {
  219. this.gotoStep(9);
  220. },
  221. gotoStep10: function () {
  222. this.gotoStep(10);
  223. },
  224. /**
  225. * Initialize host status info for step9
  226. */
  227. setInfoForStep9: function () {
  228. var hostInfo = this.getDBProperty('hosts');
  229. for (var index in hostInfo) {
  230. hostInfo[index].status = "pending";
  231. hostInfo[index].message = 'Waiting';
  232. hostInfo[index].logTasks = [];
  233. hostInfo[index].tasks = [];
  234. hostInfo[index].progress = '0';
  235. }
  236. this.setDBProperty('hosts', hostInfo);
  237. },
  238. /**
  239. * Remove all data for installOptions step
  240. */
  241. clearInstallOptions: function () {
  242. var installOptions = jQuery.extend({}, this.get('installOptionsTemplate'));
  243. this.set('content.installOptions', installOptions);
  244. this.setDBProperty('installOptions', installOptions);
  245. this.set('content.hosts', {});
  246. this.setDBProperty('hosts', {});
  247. },
  248. toObject: function (object) {
  249. var result = {};
  250. for (var i in object) {
  251. if (object.hasOwnProperty(i)) {
  252. result[i] = object[i];
  253. }
  254. }
  255. return result;
  256. },
  257. /**
  258. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  259. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  260. */
  261. saveClusterStatus: function (clusterStatus) {
  262. var oldStatus = this.toObject(this.get('content.cluster'));
  263. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  264. if (clusterStatus.requestId &&
  265. clusterStatus.oldRequestsId.indexOf(clusterStatus.requestId) === -1) {
  266. clusterStatus.oldRequestsId.push(clusterStatus.requestId);
  267. }
  268. this.set('content.cluster', clusterStatus);
  269. this.setDBProperty('cluster', clusterStatus);
  270. },
  271. /**
  272. * Invoke installation of selected services to the server and saves the request id returned by the server.
  273. * @param isRetry
  274. */
  275. installServices: function (isRetry, callback) {
  276. // clear requests since we are installing services
  277. // and we don't want to get tasks for previous install attempts
  278. this.set('content.cluster.oldRequestsId', []);
  279. var data;
  280. callback = callback || Em.K;
  281. if (isRetry) {
  282. data = {
  283. context: Em.I18n.t('requestInfo.installComponents'),
  284. HostRoles: {"state": "INSTALLED"},
  285. urlParams: "HostRoles/state=INSTALLED"
  286. }
  287. } else {
  288. data = {
  289. context: Em.I18n.t('requestInfo.installServices'),
  290. ServiceInfo: {"state": "INSTALLED"},
  291. urlParams: "ServiceInfo/state=INIT"
  292. }
  293. }
  294. App.ajax.send({
  295. name: isRetry ? 'common.host_components.update' : 'common.services.update',
  296. sender: this,
  297. data: data,
  298. success: 'installServicesSuccessCallback',
  299. error: 'installServicesErrorCallback'
  300. }).then(callback, callback);
  301. },
  302. installServicesSuccessCallback: function (jsonData) {
  303. var installStartTime = App.dateTime();
  304. console.log("TRACE: In success function for the installService call");
  305. if (jsonData) {
  306. var requestId = jsonData.Requests.id;
  307. console.log('requestId is: ' + requestId);
  308. var clusterStatus = {
  309. status: 'PENDING',
  310. requestId: requestId,
  311. isInstallError: false,
  312. isCompleted: false,
  313. installStartTime: installStartTime
  314. };
  315. this.saveClusterStatus(clusterStatus);
  316. } else {
  317. console.log('ERROR: Error occurred in parsing JSON data');
  318. }
  319. },
  320. installServicesErrorCallback: function (request, ajaxOptions, error) {
  321. console.log("TRACE: In error function for the installService call");
  322. console.log("TRACE: error code status is: " + request.status);
  323. console.log('Error message is: ' + request.responseText);
  324. var clusterStatus = {
  325. status: 'PENDING',
  326. requestId: this.get('content.cluster.requestId'),
  327. isInstallError: true,
  328. isCompleted: false
  329. };
  330. this.saveClusterStatus(clusterStatus);
  331. App.showAlertPopup(Em.I18n.t('common.errorPopup.header'), request.responseText);
  332. },
  333. /**
  334. * show popup, that display status of bootstrap launching
  335. * @param callback
  336. * @return {Object}
  337. */
  338. showLaunchBootstrapPopup: function (callback) {
  339. return App.ModalPopup.show({
  340. header: Em.I18n.t('installer.step2.bootStrap.header'),
  341. isError: false,
  342. serverError: null,
  343. bodyClass: Em.View.extend({
  344. templateName: require('templates/wizard/bootstrap_call_popup')
  345. }),
  346. showFooter: false,
  347. showCloseButton: false,
  348. secondary: null,
  349. /**
  350. * handle requestId when call is completed,
  351. * if it's correct call callback and hide popup
  352. * otherwise notify error and enable buttons to close popup
  353. * @param requestId
  354. * @param serverError
  355. */
  356. finishLoading: function (requestId, serverError) {
  357. if (Em.isNone(requestId)) {
  358. this.set('isError', true);
  359. this.set('showFooter', true);
  360. this.set('showCloseButton', true);
  361. this.set('serverError', serverError);
  362. } else {
  363. callback(requestId);
  364. this.hide();
  365. }
  366. }
  367. });
  368. },
  369. /**
  370. * Bootstrap selected hosts.
  371. * @param bootStrapData
  372. * @param callback
  373. * @return {Object}
  374. */
  375. launchBootstrap: function (bootStrapData, callback) {
  376. var popup = this.showLaunchBootstrapPopup(callback);
  377. App.ajax.send({
  378. name: 'wizard.launch_bootstrap',
  379. sender: this,
  380. data: {
  381. bootStrapData: bootStrapData,
  382. popup: popup
  383. },
  384. success: 'launchBootstrapSuccessCallback',
  385. error: 'launchBootstrapErrorCallback'
  386. });
  387. return popup;
  388. },
  389. launchBootstrapSuccessCallback: function (data, opt, params) {
  390. console.log("TRACE: POST bootstrap succeeded");
  391. params.popup.finishLoading(data.requestId, null);
  392. },
  393. launchBootstrapErrorCallback: function (request, ajaxOptions, error, opt, params) {
  394. console.log("ERROR: POST bootstrap failed");
  395. params.popup.finishLoading(null, error);
  396. },
  397. /**
  398. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  399. * If you specify <code>reload</code> to true - it will reload it.
  400. * @param name
  401. * @param reload
  402. * @return {Boolean}
  403. */
  404. load: function (name, reload) {
  405. if (this.get('content.' + name) && !reload) {
  406. return false;
  407. }
  408. var result = this.getDBProperty(name);
  409. if (!result) {
  410. if (this['get' + name.capitalize()]) {
  411. result = this['get' + name.capitalize()]();
  412. this.setDBProperty(name, result);
  413. console.log(this.get('name') + ": created " + name, result);
  414. }
  415. else {
  416. console.debug('get' + name.capitalize(), ' not defined in the ' + this.get('name'));
  417. }
  418. }
  419. this.set('content.' + name, result);
  420. console.log(this.get('name') + ": loaded " + name, result);
  421. },
  422. save: function (name) {
  423. var value = this.toObject(this.get('content.' + name));
  424. this.setDBProperty(name, value);
  425. console.log(this.get('name') + ": saved " + name, value);
  426. },
  427. clear: function () {
  428. this.set('content', Ember.Object.create({
  429. 'controllerName': this.get('content.controllerName')
  430. }));
  431. this.set('currentStep', 0);
  432. this.clearStorageData();
  433. },
  434. clusterStatusTemplate: {
  435. name: "",
  436. status: "PENDING",
  437. isCompleted: false,
  438. requestId: null,
  439. installStartTime: null,
  440. installTime: null,
  441. isInstallError: false,
  442. isStartError: false,
  443. oldRequestsId: []
  444. },
  445. clearStorageData: function () {
  446. this.get('dbPropertiesToClean').forEach(function (key) {
  447. this.setDBProperty(key, undefined);
  448. }, this);
  449. },
  450. installOptionsTemplate: {
  451. hostNames: "", //string
  452. manualInstall: false, //true, false
  453. useSsh: true, //bool
  454. javaHome: App.defaultJavaHome, //string
  455. localRepo: false, //true, false
  456. sshKey: "", //string
  457. bootRequestId: null, //string
  458. sshUser: "root" //string
  459. },
  460. loadedServiceComponents: null,
  461. /**
  462. * Clean store from already loaded data.
  463. **/
  464. clearStackModels: function () {
  465. if (App.StackService.find().get('content').length) {
  466. App.StackServiceComponent.find().set('content', []);
  467. App.StackService.find().set('content', []);
  468. }
  469. },
  470. /**
  471. * Generate serviceComponents as pr the stack definition and save it to localdata
  472. * called form stepController step4WizardController
  473. */
  474. loadServiceComponents: function () {
  475. this.clearStackModels();
  476. return App.ajax.send({
  477. name: 'wizard.service_components',
  478. sender: this,
  479. data: {
  480. stackUrl: App.get('stackVersionURL'),
  481. stackVersion: App.get('currentStackVersionNumber'),
  482. async: false
  483. },
  484. success: 'loadServiceComponentsSuccessCallback',
  485. error: 'loadServiceComponentsErrorCallback'
  486. });
  487. },
  488. loadServiceComponentsSuccessCallback: function (jsonData) {
  489. var savedSelectedServices = this.getDBProperty('selectedServiceNames');
  490. var savedInstalledServices = this.getDBProperty('installedServiceNames');
  491. this.set('content.selectedServiceNames', savedSelectedServices);
  492. this.set('content.installedServiceNames', savedInstalledServices);
  493. if (!savedSelectedServices) {
  494. jsonData.items.forEach(function (service) {
  495. service.StackServices.is_selected = true;
  496. }, this);
  497. } else {
  498. jsonData.items.forEach(function (service) {
  499. if (savedSelectedServices.contains(service.StackServices.service_name))
  500. service.StackServices.is_selected = true;
  501. else
  502. service.StackServices.is_selected = false;
  503. }, this);
  504. }
  505. if (!savedInstalledServices) {
  506. jsonData.items.forEach(function (service) {
  507. service.StackServices.is_installed = false;
  508. }, this);
  509. } else {
  510. jsonData.items.forEach(function (service) {
  511. if (savedInstalledServices.contains(service.StackServices.service_name))
  512. service.StackServices.is_installed = true;
  513. else
  514. service.StackServices.is_installed = false;
  515. }, this);
  516. }
  517. App.stackServiceMapper.map(jsonData);
  518. },
  519. loadServiceComponentsErrorCallback: function (request, ajaxOptions, error) {
  520. console.log("TRACE: STep5 -> In error function for the getServiceComponents call");
  521. console.log("TRACE: STep5 -> error code status is: " + request.status);
  522. console.log('Step8: Error message is: ' + request.responseText);
  523. },
  524. /**
  525. * Load config groups from local DB
  526. */
  527. loadServiceConfigGroups: function () {
  528. var serviceConfigGroups = this.getDBProperty('serviceConfigGroups'),
  529. hosts = this.getDBProperty('hosts'),
  530. host_names = Em.keys(hosts);
  531. if (Em.isNone(serviceConfigGroups)) {
  532. serviceConfigGroups = [];
  533. }
  534. else {
  535. serviceConfigGroups.forEach(function(group) {
  536. var hostNames = group.hosts.map(function(host_id) {
  537. for (var i = 0; i < host_names.length; i++) {
  538. if (hosts[host_names[i]].id === host_id) {
  539. return host_names[i];
  540. }
  541. }
  542. Em.assert('host is missing!!!!', false);
  543. });
  544. Em.set(group, 'hosts', hostNames);
  545. });
  546. }
  547. this.set('content.configGroups', serviceConfigGroups);
  548. console.log("InstallerController.configGroups: loaded config ", serviceConfigGroups);
  549. },
  550. registerErrPopup: function (header, message) {
  551. App.ModalPopup.show({
  552. header: header,
  553. secondary: false,
  554. bodyClass: Ember.View.extend({
  555. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  556. message: message
  557. })
  558. });
  559. },
  560. /**
  561. * Save hosts that the user confirmed to proceed with from step 3
  562. * @param stepController App.WizardStep3Controller
  563. */
  564. saveConfirmedHosts: function (stepController) {
  565. var hosts = this.get('content.hosts'),
  566. indx = 1;
  567. //add previously installed hosts
  568. for (var hostName in hosts) {
  569. if (!hosts[hostName].isInstalled) {
  570. delete hosts[hostName];
  571. }
  572. }
  573. stepController.get('confirmedHosts').forEach(function (_host) {
  574. if (_host.bootStatus == 'REGISTERED') {
  575. hosts[_host.name] = {
  576. name: _host.name,
  577. cpu: _host.cpu,
  578. memory: _host.memory,
  579. disk_info: _host.disk_info,
  580. os_type: _host.os_type,
  581. os_arch: _host.os_arch,
  582. ip: _host.ip,
  583. bootStatus: _host.bootStatus,
  584. isInstalled: false,
  585. id: indx++
  586. };
  587. }
  588. });
  589. console.log('wizardController:saveConfirmedHosts: save hosts ', hosts);
  590. this.setDBProperty('hosts', hosts);
  591. this.set('content.hosts', hosts);
  592. },
  593. /**
  594. * Save data after installation to main controller
  595. * @param stepController App.WizardStep9Controller
  596. */
  597. saveInstalledHosts: function (stepController) {
  598. var hosts = stepController.get('hosts');
  599. var hostInfo = this.getDBProperty('hosts');
  600. for (var index in hostInfo) {
  601. hostInfo[index].status = "pending";
  602. var host = hosts.findProperty('name', hostInfo[index].name);
  603. if (host) {
  604. hostInfo[index].status = host.status;
  605. hostInfo[index].message = host.message;
  606. hostInfo[index].progress = host.progress;
  607. }
  608. }
  609. this.set('content.hosts', hostInfo);
  610. this.setDBProperty('hosts', hostInfo);
  611. console.log('wizardController:saveInstalledHosts: save hosts ', hostInfo);
  612. },
  613. /**
  614. * Save slaveHostComponents to main controller
  615. * @param stepController
  616. */
  617. saveSlaveComponentHosts: function (stepController) {
  618. var hosts = stepController.get('hosts'),
  619. dbHosts = this.getDBProperty('hosts'),
  620. headers = stepController.get('headers');
  621. var formattedHosts = Ember.Object.create();
  622. headers.forEach(function (header) {
  623. formattedHosts.set(header.get('name'), []);
  624. });
  625. hosts.forEach(function (host) {
  626. var checkboxes = host.get('checkboxes');
  627. headers.forEach(function (header) {
  628. var cb = checkboxes.findProperty('title', header.get('label'));
  629. if (cb.get('checked')) {
  630. formattedHosts.get(header.get('name')).push({
  631. group: 'Default',
  632. isInstalled: cb.get('isInstalled'),
  633. host_id: dbHosts[host.hostName].id
  634. });
  635. }
  636. });
  637. });
  638. var slaveComponentHosts = [];
  639. headers.forEach(function (header) {
  640. slaveComponentHosts.push({
  641. componentName: header.get('name'),
  642. displayName: header.get('label').replace(/\s/g, ''),
  643. hosts: formattedHosts.get(header.get('name'))
  644. });
  645. });
  646. this.setDBProperty('slaveComponentHosts', slaveComponentHosts);
  647. console.log('wizardController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  648. this.set('content.slaveComponentHosts', slaveComponentHosts);
  649. },
  650. /**
  651. * Return true if cluster data is loaded and false otherwise.
  652. * This is used for all wizard controllers except for installer wizard.
  653. */
  654. dataLoading: function () {
  655. var dfd = $.Deferred();
  656. this.connectOutlet('loading');
  657. if (App.router.get('clusterController.isLoaded')) {
  658. dfd.resolve();
  659. } else {
  660. var interval = setInterval(function () {
  661. if (App.router.get('clusterController.isLoaded')) {
  662. dfd.resolve();
  663. clearInterval(interval);
  664. }
  665. }, 50);
  666. }
  667. return dfd.promise();
  668. },
  669. /**
  670. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  671. * This function is used in reassign master wizard right now.
  672. */
  673. usersLoading: function () {
  674. var self = this;
  675. var dfd = $.Deferred();
  676. var miscController = App.MainAdminMiscController.create({content: self.get('content')});
  677. miscController.loadUsers();
  678. var interval = setInterval(function () {
  679. if (miscController.get('dataIsLoaded')) {
  680. if (self.get("content.hdfsUser")) {
  681. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  682. }
  683. dfd.resolve();
  684. clearInterval(interval);
  685. }
  686. }, 10);
  687. return dfd.promise();
  688. },
  689. /**
  690. * Save cluster status before going to deploy step
  691. * @param name cluster state. Unique for every wizard
  692. */
  693. saveClusterState: function (name) {
  694. App.clusterStatus.setClusterStatus({
  695. clusterName: this.get('content.cluster.name'),
  696. clusterState: name,
  697. wizardControllerName: this.get('content.controllerName'),
  698. localdb: App.db.data
  699. });
  700. },
  701. /**
  702. * load advanced configs from server
  703. */
  704. loadAdvancedConfigs: function (dependentController) {
  705. var self = this;
  706. var stackServices = this.get('content.services').filter(function(service){
  707. return service.get('isInstalled') || service.get('isSelected');
  708. }).mapProperty('serviceName');
  709. var counter = stackServices.length;
  710. var loadAdvancedConfigResult = [];
  711. dependentController.set('isAdvancedConfigLoaded', false);
  712. stackServices.forEach(function (_serviceName) {
  713. App.config.loadAdvancedConfig(_serviceName, function (properties) {
  714. loadAdvancedConfigResult.pushObjects(properties);
  715. counter--;
  716. //pass configs to controller after last call is completed
  717. if (counter === 0) {
  718. self.set('content.advancedServiceConfig', loadAdvancedConfigResult);
  719. self.setDBProperty('advancedServiceConfig', loadAdvancedConfigResult);
  720. dependentController.set('isAdvancedConfigLoaded', true);
  721. }
  722. });
  723. }, this);
  724. },
  725. /**
  726. * Load serviceConfigProperties to model
  727. */
  728. loadServiceConfigProperties: function () {
  729. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  730. this.set('content.serviceConfigProperties', serviceConfigProperties);
  731. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  732. },
  733. /**
  734. * Save config properties
  735. * @param stepController Step7WizardController
  736. */
  737. saveServiceConfigProperties: function (stepController) {
  738. var serviceConfigProperties = [];
  739. var updateServiceConfigProperties = [];
  740. stepController.get('stepConfigs').forEach(function (_content) {
  741. if (_content.serviceName === 'YARN' && !App.supports.capacitySchedulerUi) {
  742. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  743. }
  744. _content.get('configs').forEach(function (_configProperties) {
  745. var configProperty = {
  746. id: _configProperties.get('id'),
  747. name: _configProperties.get('name'),
  748. value: _configProperties.get('value'),
  749. defaultValue: _configProperties.get('defaultValue'),
  750. description: _configProperties.get('description'),
  751. serviceName: _configProperties.get('serviceName'),
  752. domain: _configProperties.get('domain'),
  753. isVisible: _configProperties.get('isVisible'),
  754. filename: _configProperties.get('filename'),
  755. displayType: _configProperties.get('displayType'),
  756. isRequiredByAgent: _configProperties.get('isRequiredByAgent'),
  757. isRequired: _configProperties.get('isRequired') // flag that allow saving property with empty value
  758. };
  759. serviceConfigProperties.push(configProperty);
  760. }, this);
  761. // check for configs that need to update for installed services
  762. if (stepController.get('installedServiceNames') && stepController.get('installedServiceNames').contains(_content.get('serviceName'))) {
  763. // get only modified configs
  764. var configs = _content.get('configs').filterProperty('isNotDefaultValue').filter(function (config) {
  765. var notAllowed = ['masterHost', 'masterHosts', 'slaveHosts', 'slaveHost'];
  766. return !notAllowed.contains(config.get('displayType'));
  767. });
  768. // if modified configs detected push all service's configs for update
  769. if (configs.length)
  770. updateServiceConfigProperties = updateServiceConfigProperties.concat(serviceConfigProperties.filterProperty('serviceName', _content.get('serviceName')));
  771. // watch for properties that are not modified but have to be updated
  772. if (_content.get('configs').someProperty('forceUpdate')) {
  773. // check for already added modified properties
  774. if (!updateServiceConfigProperties.findProperty('serviceName', _content.get('serviceName'))) {
  775. updateServiceConfigProperties = updateServiceConfigProperties.concat(serviceConfigProperties.filterProperty('serviceName', _content.get('serviceName')));
  776. }
  777. }
  778. }
  779. }, this);
  780. this.setDBProperty('serviceConfigProperties', serviceConfigProperties);
  781. this.set('content.serviceConfigProperties', serviceConfigProperties);
  782. this.setDBProperty('configsToUpdate', updateServiceConfigProperties);
  783. },
  784. /**
  785. * save Config groups
  786. * @param stepController
  787. * @param isAddService
  788. */
  789. saveServiceConfigGroups: function (stepController, isAddService) {
  790. var serviceConfigGroups = [],
  791. isForUpdate = false,
  792. hosts = isAddService ? App.router.get('addServiceController').getDBProperty('hosts') : this.getDBProperty('hosts');
  793. stepController.get('stepConfigs').forEach(function (service) {
  794. // mark group of installed service
  795. if (service.get('selected') === false) isForUpdate = true;
  796. service.get('configGroups').forEach(function (configGroup) {
  797. var properties = [];
  798. configGroup.get('properties').forEach(function (property) {
  799. properties.push({
  800. isRequiredByAgent: property.get('isRequiredByAgent'),
  801. name: property.get('name'),
  802. value: property.get('value'),
  803. filename: property.get('filename')
  804. })
  805. });
  806. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  807. serviceConfigGroups.push({
  808. id: configGroup.get('id'),
  809. name: configGroup.get('name'),
  810. description: configGroup.get('description'),
  811. hosts: configGroup.get('hosts').map(function(host_name) {return hosts[host_name].id;}),
  812. properties: properties,
  813. isDefault: configGroup.get('isDefault'),
  814. isForUpdate: isForUpdate,
  815. service: {id: configGroup.get('service.id')}
  816. });
  817. }, this)
  818. }, this);
  819. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  820. this.set('content.configGroups', serviceConfigGroups);
  821. },
  822. /**
  823. * return slaveComponents bound to hosts
  824. * @return {Array}
  825. */
  826. getSlaveComponentHosts: function () {
  827. var components = this.get('slaveComponents');
  828. var result = [];
  829. var installedServices = App.Service.find().mapProperty('serviceName');
  830. var selectedServices = App.StackService.find().filterProperty('isSelected', true).mapProperty('serviceName');
  831. var installedComponentsMap = {};
  832. var uninstalledComponents = [];
  833. components.forEach(function (component) {
  834. if (installedServices.contains(component.get('serviceName'))) {
  835. installedComponentsMap[component.get('componentName')] = [];
  836. } else if (selectedServices.contains(component.get('serviceName'))) {
  837. uninstalledComponents.push(component);
  838. }
  839. }, this);
  840. installedComponentsMap['HDFS_CLIENT'] = [];
  841. App.HostComponent.find().forEach(function (hostComponent) {
  842. if (installedComponentsMap[hostComponent.get('componentName')]) {
  843. installedComponentsMap[hostComponent.get('componentName')].push(hostComponent.get('hostName'));
  844. }
  845. }, this);
  846. for (var componentName in installedComponentsMap) {
  847. var name = (componentName === 'HDFS_CLIENT') ? 'CLIENT' : componentName;
  848. var component = {
  849. componentName: name,
  850. displayName: App.format.role(name),
  851. hosts: [],
  852. isInstalled: true
  853. };
  854. installedComponentsMap[componentName].forEach(function (hostName) {
  855. component.hosts.push({
  856. group: "Default",
  857. hostName: hostName,
  858. isInstalled: true
  859. });
  860. }, this);
  861. result.push(component);
  862. }
  863. uninstalledComponents.forEach(function (component) {
  864. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  865. hosts.setEach('isInstalled', false);
  866. result.push({
  867. componentName: component.get('componentName'),
  868. displayName: App.format.role(component.get('componentName')),
  869. hosts: hosts,
  870. isInstalled: false
  871. })
  872. });
  873. return result;
  874. },
  875. /**
  876. * Load master component hosts data for using in required step controllers
  877. */
  878. loadMasterComponentHosts: function () {
  879. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  880. if (!masterComponentHosts) {
  881. masterComponentHosts = [];
  882. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  883. masterComponentHosts.push({
  884. component: item.get('componentName'),
  885. hostName: item.get('hostName'),
  886. isInstalled: true,
  887. serviceId: item.get('service.id'),
  888. display_name: item.get('displayName')
  889. })
  890. });
  891. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  892. }
  893. this.set("content.masterComponentHosts", masterComponentHosts);
  894. },
  895. /**
  896. * Load information about hosts with clients components
  897. */
  898. loadClients: function () {
  899. var clients = this.getDBProperty('clientInfo');
  900. this.set('content.clients', clients);
  901. console.log(this.get('content.controllerName') + ".loadClients: loaded list ", clients);
  902. },
  903. /**
  904. * load methods assigned to each step
  905. * methods executed in exact order as they described in map
  906. * @return {object}
  907. */
  908. loadAllPriorSteps: function () {
  909. var currentStep = this.get('currentStep');
  910. var loadMap = this.get('loadMap');
  911. var operationStack = [];
  912. var dfd = $.Deferred();
  913. for (var s in loadMap) {
  914. if (parseInt(s) <= parseInt(currentStep)) {
  915. operationStack.pushObjects(loadMap[s]);
  916. }
  917. }
  918. var sequence = App.actionSequence.create({context: this});
  919. sequence.setSequence(operationStack).onFinish(function () {
  920. dfd.resolve();
  921. }).start();
  922. return dfd.promise();
  923. }
  924. });