wizard.js 33 KB

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