wizard.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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 services = this.getDBProperty('service');
  437. var apiService = this.loadServiceComponents();
  438. this.set('content.services', apiService);
  439. this.setDBProperty('service',apiService);
  440. },
  441. /**
  442. * Load config groups from local DB
  443. */
  444. loadServiceConfigGroups: function () {
  445. var serviceConfigGroups = this.getDBProperty('serviceConfigGroups') || [];
  446. this.set('content.configGroups', serviceConfigGroups);
  447. console.log("InstallerController.configGroups: loaded config ", serviceConfigGroups);
  448. },
  449. registerErrPopup: function (header, message) {
  450. App.ModalPopup.show({
  451. header: header,
  452. secondary: false,
  453. bodyClass: Ember.View.extend({
  454. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  455. message: message
  456. })
  457. });
  458. },
  459. /**
  460. * Save hosts that the user confirmed to proceed with from step 3
  461. * @param stepController App.WizardStep3Controller
  462. */
  463. saveConfirmedHosts: function (stepController) {
  464. var hostInfo = {};
  465. stepController.get('content.hosts').forEach(function (_host) {
  466. if (_host.bootStatus == 'REGISTERED') {
  467. hostInfo[_host.name] = {
  468. name: _host.name,
  469. cpu: _host.cpu,
  470. memory: _host.memory,
  471. disk_info: _host.disk_info,
  472. os_type: _host.os_type,
  473. os_arch: _host.os_arch,
  474. ip: _host.ip,
  475. bootStatus: _host.bootStatus,
  476. isInstalled: false
  477. };
  478. }
  479. });
  480. console.log('wizardController:saveConfirmedHosts: save hosts ', hostInfo);
  481. this.setDBProperty('hosts', hostInfo);
  482. this.set('content.hosts', hostInfo);
  483. },
  484. /**
  485. * Save data after installation to main controller
  486. * @param stepController App.WizardStep9Controller
  487. */
  488. saveInstalledHosts: function (stepController) {
  489. var hosts = stepController.get('hosts');
  490. var hostInfo = this.getDBProperty('hosts');
  491. for (var index in hostInfo) {
  492. hostInfo[index].status = "pending";
  493. var host = hosts.findProperty('name', hostInfo[index].name);
  494. if (host) {
  495. hostInfo[index].status = host.status;
  496. hostInfo[index].message = host.message;
  497. hostInfo[index].progress = host.progress;
  498. }
  499. }
  500. this.set('content.hosts', hostInfo);
  501. this.setDBProperty('hosts', hostInfo);
  502. console.log('wizardController:saveInstalledHosts: save hosts ', hostInfo);
  503. },
  504. /**
  505. * Save slaveHostComponents to main controller
  506. * @param stepController
  507. */
  508. saveSlaveComponentHosts: function (stepController) {
  509. var hosts = stepController.get('hosts');
  510. var headers = stepController.get('headers');
  511. var formattedHosts = Ember.Object.create();
  512. headers.forEach(function (header) {
  513. formattedHosts.set(header.get('name'), []);
  514. });
  515. hosts.forEach(function (host) {
  516. var checkboxes = host.get('checkboxes');
  517. headers.forEach(function (header) {
  518. var cb = checkboxes.findProperty('title', header.get('label'));
  519. if (cb.get('checked')) {
  520. formattedHosts.get(header.get('name')).push({
  521. hostName: host.hostName,
  522. group: 'Default',
  523. isInstalled: cb.get('isInstalled')
  524. });
  525. }
  526. });
  527. });
  528. var slaveComponentHosts = [];
  529. headers.forEach(function (header) {
  530. slaveComponentHosts.push({
  531. componentName: header.get('name'),
  532. displayName: header.get('label').replace(/\s/g, ''),
  533. hosts: formattedHosts.get(header.get('name'))
  534. });
  535. });
  536. this.setDBProperty('slaveComponentHosts', slaveComponentHosts);
  537. console.log('wizardController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  538. this.set('content.slaveComponentHosts', slaveComponentHosts);
  539. },
  540. /**
  541. * Return true if cluster data is loaded and false otherwise.
  542. * This is used for all wizard controllers except for installer wizard.
  543. */
  544. dataLoading: function () {
  545. var dfd = $.Deferred();
  546. this.connectOutlet('loading');
  547. if (App.router.get('clusterController.isLoaded')) {
  548. dfd.resolve();
  549. } else {
  550. var interval = setInterval(function () {
  551. if (App.router.get('clusterController.isLoaded')) {
  552. dfd.resolve();
  553. clearInterval(interval);
  554. }
  555. }, 50);
  556. }
  557. return dfd.promise();
  558. },
  559. /**
  560. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  561. * This function is used in reassign master wizard right now.
  562. */
  563. usersLoading: function () {
  564. var self = this;
  565. var dfd = $.Deferred();
  566. var miscController = App.MainAdminMiscController.create({content: self.get('content')});
  567. miscController.loadUsers();
  568. var interval = setInterval(function () {
  569. if (miscController.get('dataIsLoaded')) {
  570. if (self.get("content.hdfsUser")) {
  571. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  572. }
  573. dfd.resolve();
  574. clearInterval(interval);
  575. }
  576. }, 10);
  577. return dfd.promise();
  578. },
  579. /**
  580. * Save cluster status before going to deploy step
  581. * @param name cluster state. Unique for every wizard
  582. */
  583. saveClusterState: function (name) {
  584. App.clusterStatus.setClusterStatus({
  585. clusterName: this.get('content.cluster.name'),
  586. clusterState: name,
  587. wizardControllerName: this.get('content.controllerName'),
  588. localdb: App.db.data
  589. });
  590. },
  591. /**
  592. * load advanced configs from server
  593. */
  594. loadAdvancedConfigs: function (dependentController) {
  595. var self = this;
  596. var counter = this.get('content.services').filterProperty('isSelected').length;
  597. var loadAdvancedConfigResult = [];
  598. dependentController.set('isAdvancedConfigLoaded', false);
  599. this.get('content.services').filterProperty('isSelected').mapProperty('serviceName').forEach(function (_serviceName) {
  600. App.config.loadAdvancedConfig(_serviceName, function (properties) {
  601. loadAdvancedConfigResult.pushObjects(properties);
  602. counter--;
  603. //pass configs to controller after last call is completed
  604. if (counter === 0) {
  605. self.set('content.advancedServiceConfig', loadAdvancedConfigResult);
  606. self.setDBProperty('advancedServiceConfig', loadAdvancedConfigResult);
  607. dependentController.set('isAdvancedConfigLoaded', true);
  608. }
  609. });
  610. }, this);
  611. },
  612. /**
  613. * Load serviceConfigProperties to model
  614. */
  615. loadServiceConfigProperties: function () {
  616. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  617. this.set('content.serviceConfigProperties', serviceConfigProperties);
  618. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  619. },
  620. /**
  621. * Save config properties
  622. * @param stepController Step7WizardController
  623. */
  624. saveServiceConfigProperties: function (stepController) {
  625. var serviceConfigProperties = [];
  626. var updateServiceConfigProperties = [];
  627. stepController.get('stepConfigs').forEach(function (_content) {
  628. if (_content.serviceName === 'YARN' && !App.supports.capacitySchedulerUi) {
  629. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  630. }
  631. _content.get('configs').forEach(function (_configProperties) {
  632. var configProperty = {
  633. id: _configProperties.get('id'),
  634. name: _configProperties.get('name'),
  635. value: _configProperties.get('value'),
  636. defaultValue: _configProperties.get('defaultValue'),
  637. description: _configProperties.get('description'),
  638. serviceName: _configProperties.get('serviceName'),
  639. domain: _configProperties.get('domain'),
  640. filename: _configProperties.get('filename'),
  641. displayType: _configProperties.get('displayType'),
  642. isRequiredByAgent: _configProperties.get('isRequiredByAgent')
  643. };
  644. serviceConfigProperties.push(configProperty);
  645. }, this);
  646. // check for configs that need to update for installed services
  647. if (stepController.get('installedServiceNames') && stepController.get('installedServiceNames').contains(_content.get('serviceName'))) {
  648. // get only modified configs
  649. var configs = _content.get('configs').filterProperty('isNotDefaultValue').filter(function(config) {
  650. var notAllowed = ['masterHost', 'masterHosts', 'slaveHosts', 'slaveHost'];
  651. return !notAllowed.contains(config.get('displayType'));
  652. });
  653. // if modified configs detected push all service's configs for update
  654. if (configs.length)
  655. updateServiceConfigProperties = updateServiceConfigProperties.concat(serviceConfigProperties.filterProperty('serviceName',_content.get('serviceName')));
  656. // watch for properties that are not modified but have to be updated
  657. if (_content.get('configs').someProperty('forceUpdate')) {
  658. // check for already added modified properties
  659. if (!updateServiceConfigProperties.findProperty('serviceName', _content.get('serviceName'))) {
  660. updateServiceConfigProperties = updateServiceConfigProperties.concat(serviceConfigProperties.filterProperty('serviceName',_content.get('serviceName')));
  661. }
  662. }
  663. }
  664. }, this);
  665. this.setDBProperty('serviceConfigProperties', serviceConfigProperties);
  666. this.set('content.serviceConfigProperties', serviceConfigProperties);
  667. this.setDBProperty('configsToUpdate', updateServiceConfigProperties);
  668. },
  669. /**
  670. * save Config groups
  671. * @param stepController
  672. */
  673. saveServiceConfigGroups: function (stepController) {
  674. var serviceConfigGroups = [];
  675. var isForUpdate = false;
  676. stepController.get('stepConfigs').forEach(function (service) {
  677. // mark group of installed service
  678. if (service.get('selected') === false) isForUpdate = true;
  679. service.get('configGroups').forEach(function (configGroup) {
  680. var properties = [];
  681. configGroup.get('properties').forEach(function (property) {
  682. properties.push({
  683. isRequiredByAgent: property.get('isRequiredByAgent'),
  684. name: property.get('name'),
  685. value: property.get('value'),
  686. filename: property.get('filename')
  687. })
  688. });
  689. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  690. serviceConfigGroups.push({
  691. id: configGroup.get('id'),
  692. name: configGroup.get('name'),
  693. description: configGroup.get('description'),
  694. hosts: configGroup.get('hosts'),
  695. properties: properties,
  696. isDefault: configGroup.get('isDefault'),
  697. isForUpdate: isForUpdate,
  698. service: {id: configGroup.get('service.id')}
  699. });
  700. }, this)
  701. }, this);
  702. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  703. this.set('content.configGroups', serviceConfigGroups);
  704. },
  705. /**
  706. * return slaveComponents bound to hosts
  707. * @return {Array}
  708. */
  709. getSlaveComponentHosts: function () {
  710. var components = this.get('slaveComponents');
  711. var result = [];
  712. var installedServices = App.Service.find().mapProperty('serviceName');
  713. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  714. var installedComponentsMap = {};
  715. var uninstalledComponents = [];
  716. components.forEach(function (component) {
  717. if (installedServices.contains(component.service_name)) {
  718. installedComponentsMap[component.component_name] = [];
  719. } else if (selectedServices.contains(component.service_name)) {
  720. uninstalledComponents.push(component);
  721. }
  722. }, this);
  723. installedComponentsMap['HDFS_CLIENT'] = [];
  724. App.HostComponent.find().forEach(function (hostComponent) {
  725. if (installedComponentsMap[hostComponent.get('componentName')]) {
  726. installedComponentsMap[hostComponent.get('componentName')].push(hostComponent.get('host.id'));
  727. }
  728. }, this);
  729. for (var componentName in installedComponentsMap) {
  730. var name = (componentName === 'HDFS_CLIENT') ? 'CLIENT' : componentName;
  731. var component = {
  732. componentName: name,
  733. displayName: App.format.role(name),
  734. hosts: [],
  735. isInstalled: true
  736. };
  737. installedComponentsMap[componentName].forEach(function (hostName) {
  738. component.hosts.push({
  739. group: "Default",
  740. hostName: hostName,
  741. isInstalled: true
  742. });
  743. }, this);
  744. result.push(component);
  745. }
  746. uninstalledComponents.forEach(function (component) {
  747. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  748. hosts.setEach('isInstalled', false);
  749. result.push({
  750. componentName: component.component_name,
  751. displayName: App.format.role(component.component_name),
  752. hosts: hosts,
  753. isInstalled: false
  754. })
  755. });
  756. return result;
  757. }
  758. });