wizard.js 36 KB

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