wizard.js 31 KB

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