wizard.js 27 KB

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