wizard.js 32 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) {
  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. if (isRetry) {
  278. name = 'wizard.install_services.installer_controller.is_retry';
  279. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installComponents') + '"}, "Body": {"HostRoles": {"state": "INSTALLED"}}}';
  280. }
  281. else {
  282. name = 'wizard.install_services.installer_controller.not_is_retry';
  283. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  284. }
  285. App.ajax.send({
  286. name: name,
  287. sender: this,
  288. data: {
  289. data: data,
  290. cluster: clusterName
  291. },
  292. success: 'installServicesSuccessCallback',
  293. error: 'installServicesErrorCallback'
  294. });
  295. },
  296. installServicesSuccessCallback: function (jsonData) {
  297. var installStartTime = App.dateTime();
  298. console.log("TRACE: In success function for the installService call");
  299. if (jsonData) {
  300. var requestId = jsonData.Requests.id;
  301. console.log('requestId is: ' + requestId);
  302. var clusterStatus = {
  303. status: 'PENDING',
  304. requestId: requestId,
  305. isInstallError: false,
  306. isCompleted: false,
  307. installStartTime: installStartTime
  308. };
  309. this.saveClusterStatus(clusterStatus);
  310. } else {
  311. console.log('ERROR: Error occurred in parsing JSON data');
  312. }
  313. },
  314. installServicesErrorCallback: function (request, ajaxOptions, error) {
  315. console.log("TRACE: In error function for the installService call");
  316. console.log("TRACE: error code status is: " + request.status);
  317. console.log('Error message is: ' + request.responseText);
  318. var clusterStatus = {
  319. status: 'PENDING',
  320. requestId: this.get('content.cluster.requestId'),
  321. isInstallError: true,
  322. isCompleted: false
  323. };
  324. this.saveClusterStatus(clusterStatus);
  325. App.showAlertPopup(Em.I18n.t('common.errorPopup.header'), request.responseText);
  326. },
  327. /**
  328. * show popup, that display status of bootstrap launching
  329. * @param callback
  330. * @return {Object}
  331. */
  332. showLaunchBootstrapPopup: function (callback) {
  333. return App.ModalPopup.show({
  334. header: Em.I18n.t('installer.step2.bootStrap.header'),
  335. isError: false,
  336. serverError: null,
  337. bodyClass: Em.View.extend({
  338. templateName: require('templates/wizard/bootstrap_call_popup')
  339. }),
  340. showFooter: false,
  341. showCloseButton: false,
  342. secondary: null,
  343. /**
  344. * handle requestId when call is completed,
  345. * if it's correct call callback and hide popup
  346. * otherwise notify error and enable buttons to close popup
  347. * @param requestId
  348. * @param serverError
  349. */
  350. finishLoading: function (requestId, serverError) {
  351. if (Em.isNone(requestId)) {
  352. this.set('isError', true);
  353. this.set('showFooter', true);
  354. this.set('showCloseButton', true);
  355. this.set('serverError', serverError);
  356. } else {
  357. callback(requestId);
  358. this.hide();
  359. }
  360. }
  361. });
  362. },
  363. /**
  364. * Bootstrap selected hosts.
  365. * @param bootStrapData
  366. * @param callback
  367. * @return {Object}
  368. */
  369. launchBootstrap: function (bootStrapData, callback) {
  370. var popup = this.showLaunchBootstrapPopup(callback);
  371. App.ajax.send({
  372. name: 'wizard.launch_bootstrap',
  373. sender: this,
  374. data: {
  375. bootStrapData: bootStrapData,
  376. popup: popup
  377. },
  378. success: 'launchBootstrapSuccessCallback',
  379. error: 'launchBootstrapErrorCallback'
  380. });
  381. return popup;
  382. },
  383. launchBootstrapSuccessCallback: function (data, opt, params) {
  384. console.log("TRACE: POST bootstrap succeeded");
  385. params.popup.finishLoading(data.requestId, null);
  386. },
  387. launchBootstrapErrorCallback: function (request, ajaxOptions, error, opt, params) {
  388. console.log("ERROR: POST bootstrap failed");
  389. params.popup.finishLoading(null, error);
  390. },
  391. /**
  392. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  393. * If you specify <code>reload</code> to true - it will reload it.
  394. * @param name
  395. * @param reload
  396. * @return {Boolean}
  397. */
  398. load: function (name, reload) {
  399. if (this.get('content.' + name) && !reload) {
  400. return false;
  401. }
  402. var result = this.getDBProperty(name);
  403. if (!result) {
  404. if (this['get' + name.capitalize()]) {
  405. result = this['get' + name.capitalize()]();
  406. this.setDBProperty(name, result);
  407. console.log(this.get('name') + ": created " + name, result);
  408. }
  409. else {
  410. console.debug('get' + name.capitalize(), ' not defined in the ' + this.get('name'));
  411. }
  412. }
  413. this.set('content.' + name, result);
  414. console.log(this.get('name') + ": loaded " + name, result);
  415. },
  416. save: function (name) {
  417. var value = this.toObject(this.get('content.' + name));
  418. this.setDBProperty(name, value);
  419. console.log(this.get('name') + ": saved " + name, value);
  420. },
  421. clear: function () {
  422. this.set('content', Ember.Object.create({
  423. 'controllerName': this.get('content.controllerName')
  424. }));
  425. this.set('currentStep', 0);
  426. this.clearStorageData();
  427. },
  428. clusterStatusTemplate: {
  429. name: "",
  430. status: "PENDING",
  431. isCompleted: false,
  432. requestId: null,
  433. installStartTime: null,
  434. installTime: null,
  435. isInstallError: false,
  436. isStartError: false,
  437. oldRequestsId: []
  438. },
  439. clearStorageData: function () {
  440. this.get('dbPropertiesToClean').forEach(function (key) {
  441. this.setDBProperty(key, undefined);
  442. }, this);
  443. },
  444. installOptionsTemplate: {
  445. hostNames: "", //string
  446. manualInstall: false, //true, false
  447. useSsh: true, //bool
  448. javaHome: App.defaultJavaHome, //string
  449. localRepo: false, //true, false
  450. sshKey: "", //string
  451. bootRequestId: null, //string
  452. sshUser: "root" //string
  453. },
  454. loadedServiceComponents: null,
  455. /**
  456. * Generate serviceComponents as pr the stack definition and save it to localdata
  457. * called form stepController step4WizardController
  458. */
  459. loadServiceComponents: function () {
  460. App.ajax.send({
  461. name: 'wizard.service_components',
  462. sender: this,
  463. data: {
  464. stackUrl: App.get('stackVersionURL'),
  465. stackVersion: App.get('currentStackVersionNumber'),
  466. async: false
  467. },
  468. success: 'loadServiceComponentsSuccessCallback',
  469. error: 'loadServiceComponentsErrorCallback'
  470. });
  471. return this.get('loadedServiceComponents');
  472. },
  473. loadServiceComponentsSuccessCallback: function (jsonData) {
  474. this.setServices(jsonData);
  475. this.setServiceComponents(jsonData);
  476. console.log("TRACE: getService ajax call -> In success function for the getServiceComponents call");
  477. console.log("TRACE: jsonData.services : " + jsonData.items);
  478. },
  479. loadServiceComponentsErrorCallback: function (request, ajaxOptions, error) {
  480. console.log("TRACE: STep5 -> In error function for the getServiceComponents call");
  481. console.log("TRACE: STep5 -> error code status is: " + request.status);
  482. console.log('Step8: Error message is: ' + request.responseText);
  483. },
  484. /**
  485. *
  486. * @param jsonData
  487. */
  488. setServices: function(jsonData) {
  489. var displayOrderConfig = require('data/services');
  490. // Creating Model
  491. var Service = Ember.Object.extend({
  492. serviceName: null,
  493. displayName: null,
  494. isDisabled: true,
  495. isSelected: true,
  496. isInstalled: false,
  497. description: null,
  498. version: null
  499. });
  500. var data = [];
  501. // loop through all the service components
  502. for (var i = 0; i < displayOrderConfig.length; i++) {
  503. var entry = jsonData.items.findProperty("StackServices.service_name", displayOrderConfig[i].serviceName);
  504. if (entry) {
  505. var myService = Service.create({
  506. serviceName: entry.StackServices.service_name,
  507. displayName: displayOrderConfig[i].displayName,
  508. isDisabled: displayOrderConfig[i].isDisabled,
  509. isSelected: displayOrderConfig[i].isSelected,
  510. canBeSelected: displayOrderConfig[i].canBeSelected,
  511. isInstalled: false,
  512. isHidden: displayOrderConfig[i].isHidden,
  513. description: entry.StackServices.comments,
  514. version: entry.StackServices.service_version
  515. });
  516. data.push(myService);
  517. }
  518. else {
  519. console.warn('Service not found - ', displayOrderConfig[i].serviceName);
  520. }
  521. }
  522. this.set('loadedServiceComponents', data);
  523. },
  524. /**
  525. *
  526. * @param jsonData
  527. */
  528. setServiceComponents: function(jsonData) {
  529. var serviceComponents = require('utils/component').loadStackServiceComponentModel(jsonData);
  530. this.setDBProperty('serviceComponents', serviceComponents);
  531. },
  532. loadServicesFromServer: function () {
  533. var apiService = this.loadServiceComponents();
  534. this.set('content.services', apiService);
  535. this.setDBProperty('service', apiService);
  536. },
  537. /**
  538. * Load config groups from local DB
  539. */
  540. loadServiceConfigGroups: function () {
  541. var serviceConfigGroups = this.getDBProperty('serviceConfigGroups'),
  542. hosts = this.getDBProperty('hosts'),
  543. host_names = Em.keys(hosts);
  544. if (Em.isNone(serviceConfigGroups)) {
  545. serviceConfigGroups = [];
  546. }
  547. else {
  548. serviceConfigGroups.forEach(function(group) {
  549. var hostNames = group.hosts.map(function(host_id) {
  550. for (var i = 0; i < host_names.length; i++) {
  551. if (hosts[host_names[i]].id === host_id) {
  552. return host_names[i];
  553. }
  554. }
  555. Em.assert('host is missing!!!!', false);
  556. });
  557. Em.set(group, 'hosts', hostNames);
  558. });
  559. }
  560. this.set('content.configGroups', serviceConfigGroups);
  561. console.log("InstallerController.configGroups: loaded config ", serviceConfigGroups);
  562. },
  563. registerErrPopup: function (header, message) {
  564. App.ModalPopup.show({
  565. header: header,
  566. secondary: false,
  567. bodyClass: Ember.View.extend({
  568. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  569. message: message
  570. })
  571. });
  572. },
  573. /**
  574. * Save hosts that the user confirmed to proceed with from step 3
  575. * @param stepController App.WizardStep3Controller
  576. */
  577. saveConfirmedHosts: function (stepController) {
  578. var hosts = this.get('content.hosts'),
  579. indx = 1;
  580. //add previously installed hosts
  581. for (var hostName in hosts) {
  582. if (!hosts[hostName].isInstalled) {
  583. delete hosts[hostName];
  584. }
  585. }
  586. stepController.get('confirmedHosts').forEach(function (_host) {
  587. if (_host.bootStatus == 'REGISTERED') {
  588. hosts[_host.name] = {
  589. name: _host.name,
  590. cpu: _host.cpu,
  591. memory: _host.memory,
  592. disk_info: _host.disk_info,
  593. os_type: _host.os_type,
  594. os_arch: _host.os_arch,
  595. ip: _host.ip,
  596. bootStatus: _host.bootStatus,
  597. isInstalled: false,
  598. id: indx++
  599. };
  600. }
  601. });
  602. console.log('wizardController:saveConfirmedHosts: save hosts ', hosts);
  603. this.setDBProperty('hosts', hosts);
  604. this.set('content.hosts', hosts);
  605. },
  606. /**
  607. * Save data after installation to main controller
  608. * @param stepController App.WizardStep9Controller
  609. */
  610. saveInstalledHosts: function (stepController) {
  611. var hosts = stepController.get('hosts');
  612. var hostInfo = this.getDBProperty('hosts');
  613. for (var index in hostInfo) {
  614. hostInfo[index].status = "pending";
  615. var host = hosts.findProperty('name', hostInfo[index].name);
  616. if (host) {
  617. hostInfo[index].status = host.status;
  618. hostInfo[index].message = host.message;
  619. hostInfo[index].progress = host.progress;
  620. }
  621. }
  622. this.set('content.hosts', hostInfo);
  623. this.setDBProperty('hosts', hostInfo);
  624. console.log('wizardController:saveInstalledHosts: save hosts ', hostInfo);
  625. },
  626. /**
  627. * Save slaveHostComponents to main controller
  628. * @param stepController
  629. */
  630. saveSlaveComponentHosts: function (stepController) {
  631. var hosts = stepController.get('hosts'),
  632. dbHosts = this.getDBProperty('hosts'),
  633. headers = stepController.get('headers');
  634. var formattedHosts = Ember.Object.create();
  635. headers.forEach(function (header) {
  636. formattedHosts.set(header.get('name'), []);
  637. });
  638. hosts.forEach(function (host) {
  639. var checkboxes = host.get('checkboxes');
  640. headers.forEach(function (header) {
  641. var cb = checkboxes.findProperty('title', header.get('label'));
  642. if (cb.get('checked')) {
  643. formattedHosts.get(header.get('name')).push({
  644. group: 'Default',
  645. isInstalled: cb.get('isInstalled'),
  646. host_id: dbHosts[host.hostName].id
  647. });
  648. }
  649. });
  650. });
  651. var slaveComponentHosts = [];
  652. headers.forEach(function (header) {
  653. slaveComponentHosts.push({
  654. componentName: header.get('name'),
  655. displayName: header.get('label').replace(/\s/g, ''),
  656. hosts: formattedHosts.get(header.get('name'))
  657. });
  658. });
  659. this.setDBProperty('slaveComponentHosts', slaveComponentHosts);
  660. console.log('wizardController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  661. this.set('content.slaveComponentHosts', slaveComponentHosts);
  662. },
  663. /**
  664. * Return true if cluster data is loaded and false otherwise.
  665. * This is used for all wizard controllers except for installer wizard.
  666. */
  667. dataLoading: function () {
  668. var dfd = $.Deferred();
  669. this.connectOutlet('loading');
  670. if (App.router.get('clusterController.isLoaded')) {
  671. dfd.resolve();
  672. } else {
  673. var interval = setInterval(function () {
  674. if (App.router.get('clusterController.isLoaded')) {
  675. dfd.resolve();
  676. clearInterval(interval);
  677. }
  678. }, 50);
  679. }
  680. return dfd.promise();
  681. },
  682. /**
  683. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  684. * This function is used in reassign master wizard right now.
  685. */
  686. usersLoading: function () {
  687. var self = this;
  688. var dfd = $.Deferred();
  689. var miscController = App.MainAdminMiscController.create({content: self.get('content')});
  690. miscController.loadUsers();
  691. var interval = setInterval(function () {
  692. if (miscController.get('dataIsLoaded')) {
  693. if (self.get("content.hdfsUser")) {
  694. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  695. }
  696. dfd.resolve();
  697. clearInterval(interval);
  698. }
  699. }, 10);
  700. return dfd.promise();
  701. },
  702. /**
  703. * Save cluster status before going to deploy step
  704. * @param name cluster state. Unique for every wizard
  705. */
  706. saveClusterState: function (name) {
  707. App.clusterStatus.setClusterStatus({
  708. clusterName: this.get('content.cluster.name'),
  709. clusterState: name,
  710. wizardControllerName: this.get('content.controllerName'),
  711. localdb: App.db.data
  712. });
  713. },
  714. /**
  715. * load advanced configs from server
  716. */
  717. loadAdvancedConfigs: function (dependentController) {
  718. var self = this;
  719. var counter = this.get('content.services').filterProperty('isSelected').length;
  720. var loadAdvancedConfigResult = [];
  721. dependentController.set('isAdvancedConfigLoaded', false);
  722. this.get('content.services').filterProperty('isSelected').mapProperty('serviceName').forEach(function (_serviceName) {
  723. App.config.loadAdvancedConfig(_serviceName, function (properties) {
  724. loadAdvancedConfigResult.pushObjects(properties);
  725. counter--;
  726. //pass configs to controller after last call is completed
  727. if (counter === 0) {
  728. self.set('content.advancedServiceConfig', loadAdvancedConfigResult);
  729. self.setDBProperty('advancedServiceConfig', loadAdvancedConfigResult);
  730. dependentController.set('isAdvancedConfigLoaded', true);
  731. }
  732. });
  733. }, this);
  734. },
  735. /**
  736. * Load serviceConfigProperties to model
  737. */
  738. loadServiceConfigProperties: function () {
  739. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  740. this.set('content.serviceConfigProperties', serviceConfigProperties);
  741. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  742. },
  743. /**
  744. * Save config properties
  745. * @param stepController Step7WizardController
  746. */
  747. saveServiceConfigProperties: function (stepController) {
  748. var serviceConfigProperties = [];
  749. var updateServiceConfigProperties = [];
  750. stepController.get('stepConfigs').forEach(function (_content) {
  751. if (_content.serviceName === 'YARN' && !App.supports.capacitySchedulerUi) {
  752. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  753. }
  754. _content.get('configs').forEach(function (_configProperties) {
  755. var configProperty = {
  756. id: _configProperties.get('id'),
  757. name: _configProperties.get('name'),
  758. value: _configProperties.get('value'),
  759. defaultValue: _configProperties.get('defaultValue'),
  760. description: _configProperties.get('description'),
  761. serviceName: _configProperties.get('serviceName'),
  762. domain: _configProperties.get('domain'),
  763. isVisible: _configProperties.get('isVisible'),
  764. filename: _configProperties.get('filename'),
  765. displayType: _configProperties.get('displayType'),
  766. isRequiredByAgent: _configProperties.get('isRequiredByAgent'),
  767. isRequired: _configProperties.get('isRequired') // flag that allow saving property with empty value
  768. };
  769. serviceConfigProperties.push(configProperty);
  770. }, this);
  771. // check for configs that need to update for installed services
  772. if (stepController.get('installedServiceNames') && stepController.get('installedServiceNames').contains(_content.get('serviceName'))) {
  773. // get only modified configs
  774. var configs = _content.get('configs').filterProperty('isNotDefaultValue').filter(function(config) {
  775. var notAllowed = ['masterHost', 'masterHosts', 'slaveHosts', 'slaveHost'];
  776. return !notAllowed.contains(config.get('displayType'));
  777. });
  778. // if modified configs detected push all service's configs for update
  779. if (configs.length)
  780. updateServiceConfigProperties = updateServiceConfigProperties.concat(serviceConfigProperties.filterProperty('serviceName',_content.get('serviceName')));
  781. // watch for properties that are not modified but have to be updated
  782. if (_content.get('configs').someProperty('forceUpdate')) {
  783. // check for already added modified properties
  784. if (!updateServiceConfigProperties.findProperty('serviceName', _content.get('serviceName'))) {
  785. updateServiceConfigProperties = updateServiceConfigProperties.concat(serviceConfigProperties.filterProperty('serviceName',_content.get('serviceName')));
  786. }
  787. }
  788. }
  789. }, this);
  790. this.setDBProperty('serviceConfigProperties', serviceConfigProperties);
  791. this.set('content.serviceConfigProperties', serviceConfigProperties);
  792. this.setDBProperty('configsToUpdate', updateServiceConfigProperties);
  793. },
  794. /**
  795. * save Config groups
  796. * @param stepController
  797. * @param isAddService
  798. */
  799. saveServiceConfigGroups: function (stepController, isAddService) {
  800. var serviceConfigGroups = [],
  801. isForUpdate = false,
  802. hosts = isAddService ? App.router.get('addServiceController').getDBProperty('hosts') : this.getDBProperty('hosts');
  803. stepController.get('stepConfigs').forEach(function (service) {
  804. // mark group of installed service
  805. if (service.get('selected') === false) isForUpdate = true;
  806. service.get('configGroups').forEach(function (configGroup) {
  807. var properties = [];
  808. configGroup.get('properties').forEach(function (property) {
  809. properties.push({
  810. isRequiredByAgent: property.get('isRequiredByAgent'),
  811. name: property.get('name'),
  812. value: property.get('value'),
  813. filename: property.get('filename')
  814. })
  815. });
  816. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  817. serviceConfigGroups.push({
  818. id: configGroup.get('id'),
  819. name: configGroup.get('name'),
  820. description: configGroup.get('description'),
  821. hosts: configGroup.get('hosts').map(function(host_name) {return hosts[host_name].id;}),
  822. properties: properties,
  823. isDefault: configGroup.get('isDefault'),
  824. isForUpdate: isForUpdate,
  825. service: {id: configGroup.get('service.id')}
  826. });
  827. }, this)
  828. }, this);
  829. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  830. this.set('content.configGroups', serviceConfigGroups);
  831. },
  832. /**
  833. * return slaveComponents bound to hosts
  834. * @return {Array}
  835. */
  836. getSlaveComponentHosts: function () {
  837. var components = this.get('slaveComponents');
  838. var result = [];
  839. var installedServices = App.Service.find().mapProperty('serviceName');
  840. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  841. var installedComponentsMap = {};
  842. var uninstalledComponents = [];
  843. components.forEach(function (component) {
  844. if (installedServices.contains(component.get('serviceName'))) {
  845. installedComponentsMap[component.get('componentName')] = [];
  846. } else if (selectedServices.contains(component.get('serviceName'))) {
  847. uninstalledComponents.push(component);
  848. }
  849. }, this);
  850. installedComponentsMap['HDFS_CLIENT'] = [];
  851. App.HostComponent.find().forEach(function (hostComponent) {
  852. if (installedComponentsMap[hostComponent.get('componentName')]) {
  853. installedComponentsMap[hostComponent.get('componentName')].push(hostComponent.get('hostName'));
  854. }
  855. }, this);
  856. for (var componentName in installedComponentsMap) {
  857. var name = (componentName === 'HDFS_CLIENT') ? 'CLIENT' : componentName;
  858. var component = {
  859. componentName: name,
  860. displayName: App.format.role(name),
  861. hosts: [],
  862. isInstalled: true
  863. };
  864. installedComponentsMap[componentName].forEach(function (hostName) {
  865. component.hosts.push({
  866. group: "Default",
  867. hostName: hostName,
  868. isInstalled: true
  869. });
  870. }, this);
  871. result.push(component);
  872. }
  873. uninstalledComponents.forEach(function (component) {
  874. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  875. hosts.setEach('isInstalled', false);
  876. result.push({
  877. componentName: component.get('componentName'),
  878. displayName: App.format.role(component.get('componentName')),
  879. hosts: hosts,
  880. isInstalled: false
  881. })
  882. });
  883. return result;
  884. },
  885. /**
  886. * Load master component hosts data for using in required step controllers
  887. */
  888. loadMasterComponentHosts: function () {
  889. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  890. if (!masterComponentHosts) {
  891. masterComponentHosts = [];
  892. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  893. masterComponentHosts.push({
  894. component: item.get('componentName'),
  895. hostName: item.get('hostName'),
  896. isInstalled: true,
  897. serviceId: item.get('service.id'),
  898. display_name: item.get('displayName')
  899. })
  900. });
  901. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  902. }
  903. this.set("content.masterComponentHosts", masterComponentHosts);
  904. },
  905. /**
  906. * Load information about hosts with clients components
  907. */
  908. loadClients: function () {
  909. var clients = this.getDBProperty('clientInfo');
  910. this.set('content.clients', clients);
  911. console.log(this.get('content.controllerName') + ".loadClients: loaded list ", clients);
  912. }
  913. });