wizard.js 29 KB

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