wizard.js 32 KB

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