wizard.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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. var lazyLoading = require('utils/lazy_loading');
  20. require('models/host');
  21. App.WizardController = Em.Controller.extend(App.LocalStorage, {
  22. isStepDisabled: null,
  23. /**
  24. * Wizard properties in local storage, which should be cleaned right after wizard has been finished
  25. */
  26. dbPropertiesToClean: [
  27. 'service',
  28. 'hosts',
  29. 'masterComponentHosts',
  30. 'slaveComponentHosts',
  31. 'cluster',
  32. 'allHostNames',
  33. 'installOptions',
  34. 'allHostNamesPattern',
  35. 'serviceComponents'
  36. ],
  37. init: function () {
  38. this.set('isStepDisabled', []);
  39. this.clusters = App.Cluster.find();
  40. this.get('isStepDisabled').pushObject(Ember.Object.create({
  41. step: 1,
  42. value: false
  43. }));
  44. for (var i = 2; i <= this.get('totalSteps'); i++) {
  45. this.get('isStepDisabled').pushObject(Ember.Object.create({
  46. step: i,
  47. value: true
  48. }));
  49. }
  50. },
  51. slaveComponents: function () {
  52. return App.StackServiceComponent.find().filterProperty('isSlave',true);
  53. }.property('App.router.clusterController.isLoaded'),
  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, disableNaviWarning) {
  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 && !disableNaviWarning) {
  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. /**
  293. * show popup, that display status of bootstrap launching
  294. * @param callback
  295. * @return {Object}
  296. */
  297. showLaunchBootstrapPopup: function (callback) {
  298. return App.ModalPopup.show({
  299. header: Em.I18n.t('installer.step2.bootStrap.header'),
  300. isError: false,
  301. serverError: null,
  302. bodyClass: Em.View.extend({
  303. templateName: require('templates/wizard/bootstrap_call_popup')
  304. }),
  305. showFooter: false,
  306. showCloseButton: false,
  307. secondary: null,
  308. /**
  309. * handle requestId when call is completed,
  310. * if it's correct call callback and hide popup
  311. * otherwise notify error and enable buttons to close popup
  312. * @param requestId
  313. * @param serverError
  314. */
  315. finishLoading: function (requestId, serverError) {
  316. if (Em.isNone(requestId)) {
  317. this.set('isError', true);
  318. this.set('showFooter', true);
  319. this.set('showCloseButton', true);
  320. this.set('serverError', serverError);
  321. } else {
  322. callback(requestId);
  323. this.hide();
  324. }
  325. }
  326. });
  327. },
  328. /**
  329. * Bootstrap selected hosts.
  330. * @param bootStrapData
  331. * @param callback
  332. * @return {Object}
  333. */
  334. launchBootstrap: function (bootStrapData, callback) {
  335. var popup = this.showLaunchBootstrapPopup(callback);
  336. App.ajax.send({
  337. name: 'wizard.launch_bootstrap',
  338. sender: this,
  339. data: {
  340. bootStrapData: bootStrapData,
  341. popup: popup
  342. },
  343. success: 'launchBootstrapSuccessCallback',
  344. error: 'launchBootstrapErrorCallback'
  345. });
  346. return popup;
  347. },
  348. launchBootstrapSuccessCallback: function (data, opt, params) {
  349. console.log("TRACE: POST bootstrap succeeded");
  350. params.popup.finishLoading(data.requestId, null);
  351. },
  352. launchBootstrapErrorCallback: function (request, ajaxOptions, error, opt, params) {
  353. console.log("ERROR: POST bootstrap failed");
  354. params.popup.finishLoading(null, error);
  355. },
  356. /**
  357. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  358. * If you specify <code>reload</code> to true - it will reload it.
  359. * @param name
  360. * @param reload
  361. * @return {Boolean}
  362. */
  363. load: function (name, reload) {
  364. if (this.get('content.' + name) && !reload) {
  365. return false;
  366. }
  367. var result = this.getDBProperty(name);
  368. if (!result) {
  369. if (this['get' + name.capitalize()]) {
  370. result = this['get' + name.capitalize()]();
  371. this.setDBProperty(name, result);
  372. console.log(this.get('name') + ": created " + name, result);
  373. }
  374. else {
  375. console.debug('get' + name.capitalize(), ' not defined in the ' + this.get('name'));
  376. }
  377. }
  378. this.set('content.' + name, result);
  379. console.log(this.get('name') + ": loaded " + name, result);
  380. },
  381. save: function (name) {
  382. var value = this.toObject(this.get('content.' + name));
  383. this.setDBProperty(name, value);
  384. console.log(this.get('name') + ": saved " + name, value);
  385. },
  386. clear: function () {
  387. this.set('content', Ember.Object.create({
  388. 'controllerName': this.get('content.controllerName')
  389. }));
  390. this.set('currentStep', 0);
  391. this.clearStorageData();
  392. },
  393. clusterStatusTemplate: {
  394. name: "",
  395. status: "PENDING",
  396. isCompleted: false,
  397. requestId: null,
  398. installStartTime: null,
  399. installTime: null,
  400. isInstallError: false,
  401. isStartError: false,
  402. oldRequestsId: []
  403. },
  404. clearStorageData: function () {
  405. this.get('dbPropertiesToClean').forEach(function (key) {
  406. this.setDBProperty(key, undefined);
  407. }, this);
  408. },
  409. installOptionsTemplate: {
  410. hostNames: "", //string
  411. manualInstall: false, //true, false
  412. useSsh: true, //bool
  413. javaHome: App.defaultJavaHome, //string
  414. localRepo: false, //true, false
  415. sshKey: "", //string
  416. bootRequestId: null, //string
  417. sshUser: "root" //string
  418. },
  419. loadedServiceComponents: null,
  420. /**
  421. * Generate serviceComponents as pr the stack definition and save it to localdata
  422. * called form stepController step4WizardController
  423. */
  424. loadServiceComponents: function () {
  425. App.ajax.send({
  426. name: 'wizard.service_components',
  427. sender: this,
  428. data: {
  429. stackUrl: App.get('stack2VersionURL'),
  430. stackVersion: App.get('currentStackVersionNumber'),
  431. async: false
  432. },
  433. success: 'loadServiceComponentsSuccessCallback',
  434. error: 'loadServiceComponentsErrorCallback'
  435. });
  436. return this.get('loadedServiceComponents');
  437. },
  438. loadServiceComponentsSuccessCallback: function (jsonData) {
  439. this.setServices(jsonData);
  440. this.setServiceComponents(jsonData);
  441. console.log("TRACE: getService ajax call -> In success function for the getServiceComponents call");
  442. console.log("TRACE: jsonData.services : " + jsonData.items);
  443. },
  444. loadServiceComponentsErrorCallback: function (request, ajaxOptions, error) {
  445. console.log("TRACE: STep5 -> In error function for the getServiceComponents call");
  446. console.log("TRACE: STep5 -> error code status is: " + request.status);
  447. console.log('Step8: Error message is: ' + request.responseText);
  448. },
  449. /**
  450. *
  451. * @param jsonData
  452. */
  453. setServices: function(jsonData) {
  454. var displayOrderConfig = require('data/services');
  455. // Creating Model
  456. var Service = Ember.Object.extend({
  457. serviceName: null,
  458. displayName: null,
  459. isDisabled: true,
  460. isSelected: true,
  461. isInstalled: false,
  462. description: null,
  463. version: null
  464. });
  465. var data = [];
  466. // loop through all the service components
  467. for (var i = 0; i < displayOrderConfig.length; i++) {
  468. var entry = jsonData.items.findProperty("StackServices.service_name", displayOrderConfig[i].serviceName);
  469. if (entry) {
  470. var myService = Service.create({
  471. serviceName: entry.StackServices.service_name,
  472. displayName: displayOrderConfig[i].displayName,
  473. isDisabled: displayOrderConfig[i].isDisabled,
  474. isSelected: displayOrderConfig[i].isSelected,
  475. canBeSelected: displayOrderConfig[i].canBeSelected,
  476. isInstalled: false,
  477. isHidden: displayOrderConfig[i].isHidden,
  478. description: entry.StackServices.comments,
  479. version: entry.StackServices.service_version
  480. });
  481. data.push(myService);
  482. }
  483. else {
  484. console.warn('Service not found - ', displayOrderConfig[i].serviceName);
  485. }
  486. }
  487. this.set('loadedServiceComponents', data);
  488. },
  489. /**
  490. *
  491. * @param jsonData
  492. */
  493. setServiceComponents: function(jsonData) {
  494. var serviceComponents = require('utils/component').loadStackServiceComponentModel(jsonData);
  495. this.setDBProperty('serviceComponents', serviceComponents);
  496. },
  497. loadServicesFromServer: function () {
  498. var apiService = this.loadServiceComponents();
  499. this.set('content.services', apiService);
  500. this.setDBProperty('service', apiService);
  501. },
  502. /**
  503. * Load config groups from local DB
  504. */
  505. loadServiceConfigGroups: function () {
  506. var serviceConfigGroups = this.getDBProperty('serviceConfigGroups') || [];
  507. this.set('content.configGroups', serviceConfigGroups);
  508. console.log("InstallerController.configGroups: loaded config ", serviceConfigGroups);
  509. },
  510. registerErrPopup: function (header, message) {
  511. App.ModalPopup.show({
  512. header: header,
  513. secondary: false,
  514. bodyClass: Ember.View.extend({
  515. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  516. message: message
  517. })
  518. });
  519. },
  520. /**
  521. * Save hosts that the user confirmed to proceed with from step 3
  522. * @param stepController App.WizardStep3Controller
  523. */
  524. saveConfirmedHosts: function (stepController) {
  525. var hostInfo = {};
  526. stepController.get('content.hosts').forEach(function (_host) {
  527. if (_host.bootStatus == 'REGISTERED') {
  528. hostInfo[_host.name] = {
  529. name: _host.name,
  530. cpu: _host.cpu,
  531. memory: _host.memory,
  532. disk_info: _host.disk_info,
  533. os_type: _host.os_type,
  534. os_arch: _host.os_arch,
  535. ip: _host.ip,
  536. bootStatus: _host.bootStatus,
  537. isInstalled: false
  538. };
  539. }
  540. });
  541. console.log('wizardController:saveConfirmedHosts: save hosts ', hostInfo);
  542. this.setDBProperty('hosts', hostInfo);
  543. this.set('content.hosts', hostInfo);
  544. },
  545. /**
  546. * Save data after installation to main controller
  547. * @param stepController App.WizardStep9Controller
  548. */
  549. saveInstalledHosts: function (stepController) {
  550. var hosts = stepController.get('hosts');
  551. var hostInfo = this.getDBProperty('hosts');
  552. for (var index in hostInfo) {
  553. hostInfo[index].status = "pending";
  554. var host = hosts.findProperty('name', hostInfo[index].name);
  555. if (host) {
  556. hostInfo[index].status = host.status;
  557. hostInfo[index].message = host.message;
  558. hostInfo[index].progress = host.progress;
  559. }
  560. }
  561. this.set('content.hosts', hostInfo);
  562. this.setDBProperty('hosts', hostInfo);
  563. console.log('wizardController:saveInstalledHosts: save hosts ', hostInfo);
  564. },
  565. /**
  566. * Save slaveHostComponents to main controller
  567. * @param stepController
  568. */
  569. saveSlaveComponentHosts: function (stepController) {
  570. var hosts = stepController.get('hosts');
  571. var headers = stepController.get('headers');
  572. var formattedHosts = Ember.Object.create();
  573. headers.forEach(function (header) {
  574. formattedHosts.set(header.get('name'), []);
  575. });
  576. hosts.forEach(function (host) {
  577. var checkboxes = host.get('checkboxes');
  578. headers.forEach(function (header) {
  579. var cb = checkboxes.findProperty('title', header.get('label'));
  580. if (cb.get('checked')) {
  581. formattedHosts.get(header.get('name')).push({
  582. hostName: host.hostName,
  583. group: 'Default',
  584. isInstalled: cb.get('isInstalled')
  585. });
  586. }
  587. });
  588. });
  589. var slaveComponentHosts = [];
  590. headers.forEach(function (header) {
  591. slaveComponentHosts.push({
  592. componentName: header.get('name'),
  593. displayName: header.get('label').replace(/\s/g, ''),
  594. hosts: formattedHosts.get(header.get('name'))
  595. });
  596. });
  597. this.setDBProperty('slaveComponentHosts', slaveComponentHosts);
  598. console.log('wizardController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  599. this.set('content.slaveComponentHosts', slaveComponentHosts);
  600. },
  601. /**
  602. * Return true if cluster data is loaded and false otherwise.
  603. * This is used for all wizard controllers except for installer wizard.
  604. */
  605. dataLoading: function () {
  606. var dfd = $.Deferred();
  607. this.connectOutlet('loading');
  608. if (App.router.get('clusterController.isLoaded')) {
  609. dfd.resolve();
  610. } else {
  611. var interval = setInterval(function () {
  612. if (App.router.get('clusterController.isLoaded')) {
  613. dfd.resolve();
  614. clearInterval(interval);
  615. }
  616. }, 50);
  617. }
  618. return dfd.promise();
  619. },
  620. /**
  621. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  622. * This function is used in reassign master wizard right now.
  623. */
  624. usersLoading: function () {
  625. var self = this;
  626. var dfd = $.Deferred();
  627. var miscController = App.MainAdminMiscController.create({content: self.get('content')});
  628. miscController.loadUsers();
  629. var interval = setInterval(function () {
  630. if (miscController.get('dataIsLoaded')) {
  631. if (self.get("content.hdfsUser")) {
  632. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  633. }
  634. dfd.resolve();
  635. clearInterval(interval);
  636. }
  637. }, 10);
  638. return dfd.promise();
  639. },
  640. /**
  641. * Save cluster status before going to deploy step
  642. * @param name cluster state. Unique for every wizard
  643. */
  644. saveClusterState: function (name) {
  645. App.clusterStatus.setClusterStatus({
  646. clusterName: this.get('content.cluster.name'),
  647. clusterState: name,
  648. wizardControllerName: this.get('content.controllerName'),
  649. localdb: App.db.data
  650. });
  651. },
  652. /**
  653. * load advanced configs from server
  654. */
  655. loadAdvancedConfigs: function (dependentController) {
  656. var self = this;
  657. var counter = this.get('content.services').filterProperty('isSelected').length;
  658. var loadAdvancedConfigResult = [];
  659. dependentController.set('isAdvancedConfigLoaded', false);
  660. this.get('content.services').filterProperty('isSelected').mapProperty('serviceName').forEach(function (_serviceName) {
  661. App.config.loadAdvancedConfig(_serviceName, function (properties) {
  662. loadAdvancedConfigResult.pushObjects(properties);
  663. counter--;
  664. //pass configs to controller after last call is completed
  665. if (counter === 0) {
  666. self.set('content.advancedServiceConfig', loadAdvancedConfigResult);
  667. self.setDBProperty('advancedServiceConfig', loadAdvancedConfigResult);
  668. dependentController.set('isAdvancedConfigLoaded', true);
  669. }
  670. });
  671. }, this);
  672. },
  673. /**
  674. * Load serviceConfigProperties to model
  675. */
  676. loadServiceConfigProperties: function () {
  677. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  678. this.set('content.serviceConfigProperties', serviceConfigProperties);
  679. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  680. },
  681. /**
  682. * Save config properties
  683. * @param stepController Step7WizardController
  684. */
  685. saveServiceConfigProperties: function (stepController) {
  686. var serviceConfigProperties = [];
  687. var updateServiceConfigProperties = [];
  688. stepController.get('stepConfigs').forEach(function (_content) {
  689. if (_content.serviceName === 'YARN' && !App.supports.capacitySchedulerUi) {
  690. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  691. }
  692. _content.get('configs').forEach(function (_configProperties) {
  693. var configProperty = {
  694. id: _configProperties.get('id'),
  695. name: _configProperties.get('name'),
  696. value: _configProperties.get('value'),
  697. defaultValue: _configProperties.get('defaultValue'),
  698. description: _configProperties.get('description'),
  699. serviceName: _configProperties.get('serviceName'),
  700. domain: _configProperties.get('domain'),
  701. isVisible: _configProperties.get('isVisible'),
  702. filename: _configProperties.get('filename'),
  703. displayType: _configProperties.get('displayType'),
  704. isRequiredByAgent: _configProperties.get('isRequiredByAgent'),
  705. isCanBeEmpty: !!_configProperties.get('isCanBeEmpty') // flag that allow saving property with empty value
  706. };
  707. serviceConfigProperties.push(configProperty);
  708. }, this);
  709. // check for configs that need to update for installed services
  710. if (stepController.get('installedServiceNames') && stepController.get('installedServiceNames').contains(_content.get('serviceName'))) {
  711. // get only modified configs
  712. var configs = _content.get('configs').filterProperty('isNotDefaultValue').filter(function(config) {
  713. var notAllowed = ['masterHost', 'masterHosts', 'slaveHosts', 'slaveHost'];
  714. return !notAllowed.contains(config.get('displayType'));
  715. });
  716. // if modified configs detected push all service's configs for update
  717. if (configs.length)
  718. lazyLoading.run({
  719. initSize: 20,
  720. chunkSize: 50,
  721. delay: 50,
  722. destination: updateServiceConfigProperties,
  723. source: serviceConfigProperties.filterProperty('serviceName',_content.get('serviceName')),
  724. context: this
  725. });
  726. // watch for properties that are not modified but have to be updated
  727. if (_content.get('configs').someProperty('forceUpdate')) {
  728. // check for already added modified properties
  729. if (!updateServiceConfigProperties.findProperty('serviceName', _content.get('serviceName'))) {
  730. lazyLoading.run({
  731. initSize: 20,
  732. chunkSize: 50,
  733. delay: 50,
  734. destination: updateServiceConfigProperties,
  735. source: serviceConfigProperties.filterProperty('serviceName',_content.get('serviceName')),
  736. context: this
  737. });
  738. }
  739. }
  740. }
  741. }, this);
  742. this.setDBProperty('serviceConfigProperties', serviceConfigProperties);
  743. this.set('content.serviceConfigProperties', []);
  744. lazyLoading.run({
  745. initSize: 20,
  746. chunkSize: 50,
  747. delay: 50,
  748. destination: this.get('content.serviceConfigProperties'),
  749. source: serviceConfigProperties,
  750. context: this
  751. });
  752. this.setDBProperty('configsToUpdate', updateServiceConfigProperties);
  753. },
  754. /**
  755. * save Config groups
  756. * @param stepController
  757. */
  758. saveServiceConfigGroups: function (stepController) {
  759. var serviceConfigGroups = [];
  760. var isForUpdate = false;
  761. stepController.get('stepConfigs').forEach(function (service) {
  762. // mark group of installed service
  763. if (service.get('selected') === false) isForUpdate = true;
  764. service.get('configGroups').forEach(function (configGroup) {
  765. var properties = [];
  766. configGroup.get('properties').forEach(function (property) {
  767. properties.push({
  768. isRequiredByAgent: property.get('isRequiredByAgent'),
  769. name: property.get('name'),
  770. value: property.get('value'),
  771. filename: property.get('filename')
  772. })
  773. });
  774. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  775. serviceConfigGroups.push({
  776. id: configGroup.get('id'),
  777. name: configGroup.get('name'),
  778. description: configGroup.get('description'),
  779. hosts: configGroup.get('hosts'),
  780. properties: properties,
  781. isDefault: configGroup.get('isDefault'),
  782. isForUpdate: isForUpdate,
  783. service: {id: configGroup.get('service.id')}
  784. });
  785. }, this)
  786. }, this);
  787. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  788. this.set('content.configGroups', serviceConfigGroups);
  789. lazyLoading.run({
  790. initSize: 20,
  791. chunkSize: 50,
  792. delay: 50,
  793. destination: this.get('content.configGroups'),
  794. source: serviceConfigGroups,
  795. context: this
  796. });
  797. },
  798. /**
  799. * return slaveComponents bound to hosts
  800. * @return {Array}
  801. */
  802. getSlaveComponentHosts: function (context, property, message, filterFunction) {
  803. var components = this.get('slaveComponents');
  804. var installedServices = App.Service.find().mapProperty('serviceName');
  805. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  806. var installedComponentsMap = {};
  807. var uninstalledComponents = [];
  808. components.forEach(function (component) {
  809. if (installedServices.contains(component.get('serviceName'))) {
  810. installedComponentsMap[component.get('componentName')] = [];
  811. } else if (selectedServices.contains(component.get('serviceName'))) {
  812. uninstalledComponents.push(component);
  813. }
  814. }, this);
  815. installedComponentsMap['HDFS_CLIENT'] = [];
  816. App.ajax.send({
  817. name: 'host_components.all',
  818. sender: this,
  819. data: {
  820. clusterName: App.get('clusterName'),
  821. installedComponentsMap: installedComponentsMap,
  822. uninstalledComponents: uninstalledComponents,
  823. context: context,
  824. property: property,
  825. message: message,
  826. filterFunction: filterFunction
  827. },
  828. success: 'getSlaveComponentHostsSuccessCallback'
  829. });
  830. },
  831. getSlaveComponentHostsSuccessCallback: function (response, request, data) {
  832. var result = [];
  833. response.items.mapProperty('HostRoles').forEach(function (hostComponent) {
  834. if (data.installedComponentsMap[hostComponent.component_name]) {
  835. data.installedComponentsMap[hostComponent.component_name].push(hostComponent.host_name);
  836. }
  837. }, this);
  838. for (var componentName in data.installedComponentsMap) {
  839. var name = (componentName === 'HDFS_CLIENT') ? 'CLIENT' : componentName;
  840. var component = {
  841. componentName: name,
  842. displayName: App.format.role(name),
  843. hosts: [],
  844. isInstalled: true
  845. };
  846. data.installedComponentsMap[componentName].forEach(function (hostName) {
  847. component.hosts.push({
  848. group: "Default",
  849. hostName: hostName,
  850. isInstalled: true
  851. });
  852. }, this);
  853. result.push(component);
  854. }
  855. data.uninstalledComponents.forEach(function (component) {
  856. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  857. hosts.setEach('isInstalled', false);
  858. result.push({
  859. componentName: component.get('componentName'),
  860. displayName: App.format.role(component.get('componentName')),
  861. hosts: hosts,
  862. isInstalled: false
  863. })
  864. });
  865. if (data.filterFunction) {
  866. result = result.filter(data.filterFunction);
  867. }
  868. data.context.set(data.property, []);
  869. lazyLoading.run({
  870. initSize: 20,
  871. chunkSize: 50,
  872. delay: 50,
  873. destination: data.context.get(data.property),
  874. source: result,
  875. context: this
  876. });
  877. console.log(data.message, result);
  878. },
  879. /**
  880. * Load master component hosts data for using in required step controllers
  881. */
  882. loadMasterComponentHosts: function () {
  883. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  884. if (!masterComponentHosts) {
  885. masterComponentHosts = [];
  886. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  887. masterComponentHosts.push({
  888. component: item.get('componentName'),
  889. hostName: item.get('host.hostName'),
  890. isInstalled: true,
  891. serviceId: item.get('service.id'),
  892. display_name: item.get('displayName')
  893. })
  894. });
  895. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  896. }
  897. this.set("content.masterComponentHosts", masterComponentHosts);
  898. },
  899. /**
  900. * Load information about hosts with clients components
  901. */
  902. loadClients: function () {
  903. var clients = this.getDBProperty('clientInfo');
  904. this.set('content.clients', []);
  905. lazyLoading.run({
  906. initSize: 20,
  907. chunkSize: 50,
  908. delay: 50,
  909. destination: this.get('content.clients'),
  910. source: clients,
  911. context: this
  912. });
  913. console.log(this.get('content.controllerName') + ".loadClients: loaded list ", clients);
  914. }
  915. });