wizard.js 28 KB

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