wizard.js 28 KB

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