wizard.js 29 KB

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