wizard.js 28 KB

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