wizard.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. App.WizardController = Em.Controller.extend({
  20. isStepDisabled: null,
  21. init: function () {
  22. this.set('isStepDisabled', []);
  23. this.clusters = App.Cluster.find();
  24. this.get('isStepDisabled').pushObject(Ember.Object.create({
  25. step: 1,
  26. value: false
  27. }));
  28. for (var i = 2; i <= this.get('totalSteps'); i++) {
  29. this.get('isStepDisabled').pushObject(Ember.Object.create({
  30. step: i,
  31. value: true
  32. }));
  33. }
  34. },
  35. setStepsEnable: function () {
  36. for (var i = 1; i <= this.totalSteps; i++) {
  37. var step = this.get('isStepDisabled').findProperty('step', i);
  38. if (i <= this.get('currentStep')) {
  39. step.set('value', false);
  40. } else {
  41. step.set('value', true);
  42. }
  43. }
  44. }.observes('currentStep'),
  45. setLowerStepsDisable: function (stepNo) {
  46. for (var i = 1; i < stepNo; i++) {
  47. var step = this.get('isStepDisabled').findProperty('step', i);
  48. step.set('value', true);
  49. }
  50. },
  51. /**
  52. * Set current step to new value.
  53. * Method moved from App.router.setInstallerCurrentStep
  54. * @param currentStep
  55. * @param completed
  56. */
  57. currentStep: function () {
  58. return App.get('router').getWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10));
  59. }.property(),
  60. /**
  61. * Set current step to new value.
  62. * Method moved from App.router.setInstallerCurrentStep
  63. * @param currentStep
  64. * @param completed
  65. */
  66. setCurrentStep: function (currentStep, completed) {
  67. App.db.setWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10), currentStep, completed);
  68. this.set('currentStep', currentStep);
  69. },
  70. clusters: null,
  71. isStep0: function () {
  72. return this.get('currentStep') == 0;
  73. }.property('currentStep'),
  74. isStep1: function () {
  75. return this.get('currentStep') == 1;
  76. }.property('currentStep'),
  77. isStep2: function () {
  78. return this.get('currentStep') == 2;
  79. }.property('currentStep'),
  80. isStep3: function () {
  81. return this.get('currentStep') == 3;
  82. }.property('currentStep'),
  83. isStep4: function () {
  84. return this.get('currentStep') == 4;
  85. }.property('currentStep'),
  86. isStep5: function () {
  87. return this.get('currentStep') == 5;
  88. }.property('currentStep'),
  89. isStep6: function () {
  90. return this.get('currentStep') == 6;
  91. }.property('currentStep'),
  92. isStep7: function () {
  93. return this.get('currentStep') == 7;
  94. }.property('currentStep'),
  95. isStep8: function () {
  96. return this.get('currentStep') == 8;
  97. }.property('currentStep'),
  98. isStep9: function () {
  99. return this.get('currentStep') == 9;
  100. }.property('currentStep'),
  101. isStep10: function () {
  102. return this.get('currentStep') == 10;
  103. }.property('currentStep'),
  104. gotoStep: function (step) {
  105. if (this.get('isStepDisabled').findProperty('step', step).get('value') !== false) {
  106. return false;
  107. }
  108. // if going back from Step 9 in Install Wizard, delete the checkpoint so that the user is not redirected
  109. // to Step 9
  110. if (this.get('content.controllerName') == 'installerController' && this.get('currentStep') === '9' && step < 9) {
  111. App.clusterStatus.setClusterStatus({
  112. clusterName: this.get('clusterName'),
  113. clusterState: 'CLUSTER_NOT_CREATED_1',
  114. wizardControllerName: 'installerController',
  115. localdb: App.db.data
  116. });
  117. }
  118. if ((this.get('currentStep') - step) > 1) {
  119. App.ModalPopup.show({
  120. header: Em.I18n.t('installer.navigation.warning.header'),
  121. onPrimary: function () {
  122. App.router.send('gotoStep' + step);
  123. this.hide();
  124. },
  125. body: "If you proceed to go back to Step " + step + ", you will lose any changes you have made beyond this step"
  126. });
  127. } else {
  128. App.router.send('gotoStep' + step);
  129. }
  130. return true;
  131. },
  132. gotoStep0: function () {
  133. this.gotoStep(0);
  134. },
  135. gotoStep1: function () {
  136. this.gotoStep(1);
  137. },
  138. gotoStep2: function () {
  139. this.gotoStep(2);
  140. },
  141. gotoStep3: function () {
  142. this.gotoStep(3);
  143. },
  144. gotoStep4: function () {
  145. this.gotoStep(4);
  146. },
  147. gotoStep5: function () {
  148. this.gotoStep(5);
  149. },
  150. gotoStep6: function () {
  151. this.gotoStep(6);
  152. },
  153. gotoStep7: function () {
  154. this.gotoStep(7);
  155. },
  156. gotoStep8: function () {
  157. this.gotoStep(8);
  158. },
  159. gotoStep9: function () {
  160. this.gotoStep(9);
  161. },
  162. gotoStep10: function () {
  163. this.gotoStep(10);
  164. },
  165. /**
  166. * Initialize host status info for step9
  167. */
  168. setInfoForStep9: function () {
  169. var hostInfo = App.db.getHosts();
  170. for (var index in hostInfo) {
  171. hostInfo[index].status = "pending";
  172. hostInfo[index].message = 'Waiting';
  173. hostInfo[index].logTasks = [];
  174. hostInfo[index].tasks = [];
  175. hostInfo[index].progress = '0';
  176. }
  177. App.db.setHosts(hostInfo);
  178. },
  179. /**
  180. * Remove all data for installOptions step
  181. */
  182. clearInstallOptions: function () {
  183. var installOptions = jQuery.extend({}, this.get('installOptionsTemplate'));
  184. this.set('content.installOptions', installOptions);
  185. this.save('installOptions');
  186. this.set('content.hosts', []);
  187. this.save('hosts');
  188. },
  189. toObject: function (object) {
  190. var result = {};
  191. for (var i in object) {
  192. if (object.hasOwnProperty(i)) {
  193. result[i] = object[i];
  194. }
  195. }
  196. return result;
  197. },
  198. /**
  199. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  200. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  201. */
  202. saveClusterStatus: function (clusterStatus) {
  203. var oldStatus = this.toObject(this.get('content.cluster'));
  204. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  205. if (clusterStatus.requestId &&
  206. clusterStatus.oldRequestsId.indexOf(clusterStatus.requestId) === -1) {
  207. clusterStatus.oldRequestsId.push(clusterStatus.requestId);
  208. }
  209. this.set('content.cluster', clusterStatus);
  210. this.save('cluster');
  211. },
  212. /**
  213. * Invoke installation of selected services to the server and saves the request id returned by the server.
  214. * @param isRetry
  215. */
  216. installServices: function (isRetry) {
  217. // clear requests since we are installing services
  218. // and we don't want to get tasks for previous install attempts
  219. this.set('content.cluster.oldRequestsId', []);
  220. var clusterName = this.get('content.cluster.name');
  221. var data;
  222. var name;
  223. switch (this.get('content.controllerName')) {
  224. case 'addHostController':
  225. var hostnames = [];
  226. for (var hostname in App.db.getHosts()) {
  227. hostnames.push(hostname);
  228. }
  229. if (isRetry) {
  230. name = 'wizard.install_services.add_host_controller.is_retry';
  231. }
  232. else {
  233. name = 'wizard.install_services.add_host_controller.not_is_retry';
  234. }
  235. data = {
  236. "RequestInfo": {
  237. "context": Em.I18n.t('requestInfo.installComponents'),
  238. "query": "HostRoles/host_name.in(" + hostnames.join(',') + ")"
  239. },
  240. "Body": {
  241. "HostRoles": {"state": "INSTALLED"}
  242. }
  243. };
  244. data = JSON.stringify(data);
  245. break;
  246. case 'addServiceController':
  247. if (isRetry) {
  248. this.getFailedHostComponents();
  249. console.log('failedHostComponents', this.get('failedHostComponents'));
  250. name = 'wizard.install_services.installer_controller.is_retry';
  251. data = {
  252. "RequestInfo": {
  253. "context" : Em.I18n.t('requestInfo.installComponents'),
  254. "query": "HostRoles/component_name.in(" + this.get('failedHostComponents').join(',') + ")"
  255. },
  256. "Body": {
  257. "HostRoles": {
  258. "state": "INSTALLED"
  259. }
  260. }
  261. };
  262. data = JSON.stringify(data);
  263. }
  264. else {
  265. name = 'wizard.install_services.installer_controller.not_is_retry';
  266. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  267. }
  268. break;
  269. case 'installerController':
  270. default:
  271. if (isRetry) {
  272. name = 'wizard.install_services.installer_controller.is_retry';
  273. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installComponents') + '"}, "Body": {"HostRoles": {"state": "INSTALLED"}}}';
  274. }
  275. else {
  276. name = 'wizard.install_services.installer_controller.not_is_retry';
  277. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  278. }
  279. break;
  280. }
  281. App.ajax.send({
  282. name: name,
  283. sender: this,
  284. data: {
  285. data: data,
  286. cluster: clusterName
  287. },
  288. success: 'installServicesSuccessCallback',
  289. error: 'installServicesErrorCallback'
  290. });
  291. },
  292. /**
  293. * List of failed to install HostComponents while adding Service
  294. */
  295. failedHostComponents: [],
  296. getFailedHostComponents: function() {
  297. App.ajax.send({
  298. name: 'wizard.install_services.add_service_controller.get_failed_host_components',
  299. sender: this,
  300. success: 'getFailedHostComponentsSuccessCallback',
  301. error: 'getFailedHostComponentsErrorCallback'
  302. });
  303. },
  304. /**
  305. * Parse all failed components and filter out installed earlier components (based on selected to install services)
  306. * @param {Object} json
  307. */
  308. getFailedHostComponentsSuccessCallback: function(json) {
  309. var allFailed = json.items.filterProperty('HostRoles.state', 'INSTALL_FAILED');
  310. var currentFailed = [];
  311. var selectedServices = App.db.getService().filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
  312. allFailed.forEach(function(failed) {
  313. if (selectedServices.contains(failed.component[0].ServiceComponentInfo.service_name)) {
  314. currentFailed.push(failed.HostRoles.component_name);
  315. }
  316. });
  317. this.set('failedHostComponents', currentFailed);
  318. },
  319. getFailedHostComponentsErrorCallback: function(request, ajaxOptions, error) {
  320. console.warn(error);
  321. },
  322. installServicesSuccessCallback: function (jsonData) {
  323. var installStartTime = new Date().getTime();
  324. console.log("TRACE: In success function for the installService call");
  325. if (jsonData) {
  326. var requestId = jsonData.Requests.id;
  327. console.log('requestId is: ' + requestId);
  328. var clusterStatus = {
  329. status: 'PENDING',
  330. requestId: requestId,
  331. isInstallError: false,
  332. isCompleted: false,
  333. installStartTime: installStartTime
  334. };
  335. this.saveClusterStatus(clusterStatus);
  336. } else {
  337. console.log('ERROR: Error occurred in parsing JSON data');
  338. }
  339. },
  340. installServicesErrorCallback: function (request, ajaxOptions, error) {
  341. console.log("TRACE: In error function for the installService call");
  342. console.log("TRACE: error code status is: " + request.status);
  343. console.log('Error message is: ' + request.responseText);
  344. var clusterStatus = {
  345. status: 'PENDING',
  346. requestId: this.get('content.cluster.requestId'),
  347. isInstallError: true,
  348. isCompleted: false
  349. };
  350. this.saveClusterStatus(clusterStatus);
  351. App.showAlertPopup(Em.I18n.t('common.errorPopup.header'), request.responseText);
  352. },
  353. bootstrapRequestId: null,
  354. /*
  355. Bootstrap selected hosts.
  356. */
  357. launchBootstrap: function (bootStrapData) {
  358. App.ajax.send({
  359. name: 'wizard.launch_bootstrap',
  360. sender: this,
  361. data: {
  362. bootStrapData: bootStrapData
  363. },
  364. success: 'launchBootstrapSuccessCallback',
  365. error: 'launchBootstrapErrorCallback'
  366. });
  367. return this.get('bootstrapRequestId');
  368. },
  369. launchBootstrapSuccessCallback: function (data) {
  370. console.log("TRACE: POST bootstrap succeeded");
  371. this.set('bootstrapRequestId', data.requestId);
  372. },
  373. launchBootstrapErrorCallback: function () {
  374. console.log("ERROR: POST bootstrap failed");
  375. alert('Bootstrap call failed. Please try again.');
  376. },
  377. /**
  378. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  379. * If you specify <code>reload</code> to true - it will reload it.
  380. * @param name
  381. * @param reload
  382. * @return {Boolean}
  383. */
  384. load: function (name, reload) {
  385. if (this.get('content.' + name) && !reload) {
  386. return false;
  387. }
  388. var result = App.db['get' + name.capitalize()]();
  389. if (!result) {
  390. result = this['get' + name.capitalize()]();
  391. App.db['set' + name.capitalize()](result);
  392. console.log(this.get('name') + ": created " + name, result);
  393. }
  394. this.set('content.' + name, result);
  395. console.log(this.get('name') + ": loaded " + name, result);
  396. },
  397. save: function (name) {
  398. var value = this.toObject(this.get('content.' + name));
  399. App.db['set' + name.capitalize()](value);
  400. console.log(this.get('name') + ": saved " + name, value);
  401. },
  402. clear: function () {
  403. this.set('content', Ember.Object.create({
  404. 'controllerName': this.get('content.controllerName')
  405. }));
  406. this.set('currentStep', 0);
  407. this.clearStorageData();
  408. },
  409. clusterStatusTemplate: {
  410. name: "",
  411. status: "PENDING",
  412. isCompleted: false,
  413. requestId: null,
  414. installStartTime: null,
  415. installTime: null,
  416. isInstallError: false,
  417. isStartError: false,
  418. oldRequestsId: []
  419. },
  420. clearStorageData: function () {
  421. App.db.setService(undefined); //not to use this data at AddService page
  422. App.db.setHosts(undefined);
  423. App.db.setMasterComponentHosts(undefined);
  424. App.db.setSlaveComponentHosts(undefined);
  425. App.db.setCluster(undefined);
  426. App.db.setAllHostNames(undefined);
  427. App.db.setInstallOptions(undefined);
  428. App.db.setAllHostNamesPattern(undefined);
  429. },
  430. installOptionsTemplate: {
  431. hostNames: "", //string
  432. manualInstall: false, //true, false
  433. useSsh: true, //bool
  434. javaHome: App.defaultJavaHome, //string
  435. localRepo: false, //true, false
  436. sshKey: "", //string
  437. bootRequestId: null, //string
  438. sshUser: "root" //string
  439. },
  440. loadedServiceComponents: null,
  441. /**
  442. * Generate serviceComponents as pr the stack definition and save it to localdata
  443. * called form stepController step4WizardController
  444. */
  445. loadServiceComponents: function () {
  446. App.ajax.send({
  447. name: 'wizard.service_components',
  448. sender: this,
  449. data: {
  450. stackUrl: App.get('stack2VersionURL'),
  451. stackVersion: App.get('currentStackVersionNumber')
  452. },
  453. success: 'loadServiceComponentsSuccessCallback',
  454. error: 'loadServiceComponentsErrorCallback'
  455. });
  456. return this.get('loadedServiceComponents');
  457. },
  458. loadServiceComponentsSuccessCallback: function (jsonData) {
  459. var displayOrderConfig = require('data/services');
  460. console.log("TRACE: getService ajax call -> In success function for the getServiceComponents call");
  461. console.log("TRACE: jsonData.services : " + jsonData.items);
  462. // Creating Model
  463. var Service = Ember.Object.extend({
  464. serviceName: null,
  465. displayName: null,
  466. isDisabled: true,
  467. isSelected: true,
  468. isInstalled: false,
  469. description: null,
  470. version: null
  471. });
  472. var data = [];
  473. // loop through all the service components
  474. for (var i = 0; i < displayOrderConfig.length; i++) {
  475. var entry = jsonData.items.findProperty("StackServices.service_name", displayOrderConfig[i].serviceName);
  476. if (entry) {
  477. var myService = Service.create({
  478. serviceName: entry.StackServices.service_name,
  479. displayName: displayOrderConfig[i].displayName,
  480. isDisabled: displayOrderConfig[i].isDisabled,
  481. isSelected: displayOrderConfig[i].isSelected,
  482. canBeSelected: displayOrderConfig[i].canBeSelected,
  483. isInstalled: false,
  484. isHidden: displayOrderConfig[i].isHidden,
  485. description: entry.StackServices.comments,
  486. version: entry.StackServices.service_version
  487. });
  488. data.push(myService);
  489. }
  490. else {
  491. console.warn('Service not found - ', displayOrderConfig[i].serviceName);
  492. }
  493. }
  494. this.set('loadedServiceComponents', data);
  495. console.log('TRACE: service components: ' + JSON.stringify(data));
  496. },
  497. loadServiceComponentsErrorCallback: function (request, ajaxOptions, error) {
  498. console.log("TRACE: STep5 -> In error function for the getServiceComponents call");
  499. console.log("TRACE: STep5 -> error code status is: " + request.status);
  500. console.log('Step8: Error message is: ' + request.responseText);
  501. },
  502. loadServicesFromServer: function () {
  503. var services = App.db.getService();
  504. if (services) {
  505. return;
  506. }
  507. var apiService = this.loadServiceComponents();
  508. this.set('content.services', apiService);
  509. App.db.setService(apiService);
  510. },
  511. registerErrPopup: function (header, message) {
  512. App.ModalPopup.show({
  513. header: header,
  514. secondary: false,
  515. onPrimary: function () {
  516. this.hide();
  517. },
  518. bodyClass: Ember.View.extend({
  519. template: Ember.Handlebars.compile(['<p>{{view.message}}</p>'].join('\n')),
  520. message: message
  521. })
  522. });
  523. },
  524. /**
  525. * Save hosts that the user confirmed to proceed with from step 3
  526. * @param stepController App.WizardStep3Controller
  527. */
  528. saveConfirmedHosts: function (stepController) {
  529. var hostInfo = {};
  530. stepController.get('content.hosts').forEach(function (_host) {
  531. hostInfo[_host.name] = {
  532. name: _host.name,
  533. cpu: _host.cpu,
  534. memory: _host.memory,
  535. disk_info: _host.disk_info,
  536. bootStatus: _host.bootStatus,
  537. isInstalled: false
  538. };
  539. });
  540. console.log('wizardController:saveConfirmedHosts: save hosts ', hostInfo);
  541. App.db.setHosts(hostInfo);
  542. this.set('content.hosts', hostInfo);
  543. },
  544. /**
  545. * Save data after installation to main controller
  546. * @param stepController App.WizardStep9Controller
  547. */
  548. saveInstalledHosts: function (stepController) {
  549. var hosts = stepController.get('hosts');
  550. var hostInfo = App.db.getHosts();
  551. for (var index in hostInfo) {
  552. hostInfo[index].status = "pending";
  553. var host = hosts.findProperty('name', hostInfo[index].name);
  554. if (host) {
  555. hostInfo[index].status = host.status;
  556. hostInfo[index].message = host.message;
  557. hostInfo[index].progress = host.progress;
  558. }
  559. }
  560. this.set('content.hosts', hostInfo);
  561. this.save('hosts');
  562. console.log('wizardController:saveInstalledHosts: save hosts ', hostInfo);
  563. },
  564. /**
  565. * Save slaveHostComponents to main controller
  566. * @param stepController
  567. */
  568. saveSlaveComponentHosts: function (stepController) {
  569. var hosts = stepController.get('hosts');
  570. var headers = stepController.get('headers');
  571. var formattedHosts = Ember.Object.create();
  572. headers.forEach(function (header) {
  573. formattedHosts.set(header.get('name'), []);
  574. });
  575. hosts.forEach(function (host) {
  576. var checkboxes = host.get('checkboxes');
  577. headers.forEach(function (header) {
  578. var cb = checkboxes.findProperty('title', header.get('label'));
  579. if (cb.get('checked')) {
  580. formattedHosts.get(header.get('name')).push({
  581. hostName: host.hostName,
  582. group: 'Default',
  583. isInstalled: cb.get('isInstalled')
  584. });
  585. }
  586. });
  587. });
  588. var slaveComponentHosts = [];
  589. headers.forEach(function (header) {
  590. slaveComponentHosts.push({
  591. componentName: header.get('name'),
  592. displayName: header.get('label').replace(/\s/g, ''),
  593. hosts: formattedHosts.get(header.get('name'))
  594. });
  595. });
  596. App.db.setSlaveComponentHosts(slaveComponentHosts);
  597. console.log('wizardController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  598. this.set('content.slaveComponentHosts', slaveComponentHosts);
  599. },
  600. /**
  601. * Return true if cluster data is loaded and false otherwise.
  602. * This is used for all wizard controllers except for installer wizard.
  603. */
  604. dataLoading: function () {
  605. var dfd = $.Deferred();
  606. this.connectOutlet('loading');
  607. if (App.router.get('clusterController.isLoaded')) {
  608. dfd.resolve();
  609. } else {
  610. var interval = setInterval(function () {
  611. if (App.router.get('clusterController.isLoaded')) {
  612. dfd.resolve();
  613. clearInterval(interval);
  614. }
  615. }, 50);
  616. }
  617. return dfd.promise();
  618. },
  619. /**
  620. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  621. * This function is used in reassign master wizard right now.
  622. */
  623. usersLoading: function () {
  624. var self = this;
  625. var dfd = $.Deferred();
  626. var miscController = App.MainAdminMiscController.create({content: self.get('content')});
  627. miscController.loadUsers();
  628. var interval = setInterval(function () {
  629. if (miscController.get('dataIsLoaded')) {
  630. if (self.get("content.hdfsUser")) {
  631. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  632. }
  633. dfd.resolve();
  634. clearInterval(interval);
  635. }
  636. }, 10);
  637. return dfd.promise();
  638. },
  639. /**
  640. * Save cluster status before going to deploy step
  641. * @param name cluster state. Unique for every wizard
  642. */
  643. saveClusterState: function (name) {
  644. App.clusterStatus.setClusterStatus({
  645. clusterName: this.get('content.cluster.name'),
  646. clusterState: name,
  647. wizardControllerName: this.get('content.controllerName'),
  648. localdb: App.db.data
  649. });
  650. },
  651. /**
  652. * load advanced configs from server
  653. */
  654. loadAdvancedConfigs: function () {
  655. var configs = (App.db.getAdvancedServiceConfig()) ? App.db.getAdvancedServiceConfig() : [];
  656. this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName').forEach(function (_serviceName) {
  657. var serviceComponents = App.config.loadAdvancedConfig(_serviceName);
  658. if (serviceComponents) {
  659. configs = configs.concat(serviceComponents);
  660. }
  661. }, this);
  662. this.set('content.advancedServiceConfig', configs);
  663. App.db.setAdvancedServiceConfig(configs);
  664. },
  665. /**
  666. * Load serviceConfigProperties to model
  667. */
  668. loadServiceConfigProperties: function () {
  669. var serviceConfigProperties = App.db.getServiceConfigProperties();
  670. this.set('content.serviceConfigProperties', serviceConfigProperties);
  671. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  672. },
  673. /**
  674. * Save config properties
  675. * @param stepController Step7WizardController
  676. */
  677. saveServiceConfigProperties: function (stepController) {
  678. var serviceConfigProperties = [];
  679. stepController.get('stepConfigs').forEach(function (_content) {
  680. if (_content.serviceName === 'YARN' && !App.supports.capacitySchedulerUi) {
  681. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  682. }
  683. _content.get('configs').forEach(function (_configProperties) {
  684. var overrides = _configProperties.get('overrides');
  685. var overridesArray = [];
  686. if (overrides != null) {
  687. overrides.forEach(function (override) {
  688. var overrideEntry = {
  689. value: override.get('value'),
  690. hosts: []
  691. };
  692. override.get('selectedHostOptions').forEach(function (host) {
  693. overrideEntry.hosts.push(host);
  694. });
  695. overridesArray.push(overrideEntry);
  696. });
  697. }
  698. overridesArray = (overridesArray.length) ? overridesArray : null;
  699. var configProperty = {
  700. id: _configProperties.get('id'),
  701. name: _configProperties.get('name'),
  702. value: _configProperties.get('value'),
  703. defaultValue: _configProperties.get('defaultValue'),
  704. description: _configProperties.get('description'),
  705. serviceName: _configProperties.get('serviceName'),
  706. domain: _configProperties.get('domain'),
  707. filename: _configProperties.get('filename'),
  708. displayType: _configProperties.get('displayType'),
  709. overrides: overridesArray
  710. };
  711. serviceConfigProperties.push(configProperty);
  712. }, this);
  713. }, this);
  714. App.db.setServiceConfigProperties(serviceConfigProperties);
  715. this.set('content.serviceConfigProperties', serviceConfigProperties);
  716. }
  717. })