step3_controller.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  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. var numberUtils = require('utils/number_utils');
  21. App.WizardStep3Controller = Em.Controller.extend({
  22. name: 'wizardStep3Controller',
  23. hosts: [],
  24. content: [],
  25. bootHosts: [],
  26. registeredHosts: [],
  27. repoCategoryWarnings: [],
  28. diskCategoryWarnings: [],
  29. registrationStartedAt: null,
  30. /**
  31. * Timeout for registration
  32. * Based on <code>installOptions.manualInstall</code>
  33. * @type {number}
  34. */
  35. registrationTimeoutSecs: function () {
  36. return this.get('content.installOptions.manualInstall') ? 15 : 120;
  37. }.property('content.installOptions.manualInstall'),
  38. /**
  39. * Bootstrap calls are stopped
  40. * @type {bool}
  41. */
  42. stopBootstrap: false,
  43. /**
  44. * is Submit button disabled
  45. * @type {bool}
  46. */
  47. isSubmitDisabled: true,
  48. /**
  49. * is Retry button disabled
  50. * @type {bool}
  51. */
  52. isRetryDisabled: true,
  53. /**
  54. * @type {bool}
  55. */
  56. isLoaded: false,
  57. /**
  58. * Polls count
  59. * @type {number}
  60. */
  61. numPolls: 0,
  62. /**
  63. * Is hosts registration in progress
  64. * @type {bool}
  65. */
  66. isRegistrationInProgress: true,
  67. /**
  68. * Are some registered hosts which are not added by user
  69. * @type {bool}
  70. */
  71. hasMoreRegisteredHosts: false,
  72. /**
  73. * List of installed hostnames
  74. * @type {string[]}
  75. */
  76. hostsInCluster: function () {
  77. return App.Host.find().getEach('hostName');
  78. }.property().volatile(),
  79. /**
  80. * All hosts warnings
  81. * @type {object[]}
  82. */
  83. warnings: [],
  84. /**
  85. * Warnings grouped by host
  86. * @type {Ember.Enumerable}
  87. */
  88. warningsByHost: [],
  89. /**
  90. * Timeout for "warning"-requests
  91. * @type {number}
  92. */
  93. warningsTimeInterval: 60000,
  94. /**
  95. * Are hosts warnings loaded
  96. * @type {bool}
  97. */
  98. isWarningsLoaded: false,
  99. /**
  100. * Check are hosts have any warnings
  101. * @type {bool}
  102. */
  103. isHostHaveWarnings: function () {
  104. return this.get('warnings.length') > 0;
  105. }.property('warnings'),
  106. /**
  107. * Should warnings-box be visible
  108. * @type {bool}
  109. */
  110. isWarningsBoxVisible: function () {
  111. return (App.testMode) ? true : !this.get('isRegistrationInProgress');
  112. }.property('isRegistrationInProgress'),
  113. /**
  114. * Progress value for "update hosts status" process
  115. * @type {number}
  116. */
  117. checksUpdateProgress: 0,
  118. /**
  119. *
  120. * @type {object}
  121. */
  122. checksUpdateStatus: null,
  123. /**
  124. *
  125. * @method navigateStep
  126. */
  127. navigateStep: function () {
  128. if (this.get('isLoaded')) {
  129. if (!this.get('content.installOptions.manualInstall')) {
  130. if (!this.get('wizardController').getDBProperty('bootStatus')) {
  131. this.startBootstrap();
  132. }
  133. } else {
  134. this.set('bootHosts', this.get('hosts'));
  135. if (App.testMode) {
  136. this.getHostInfo();
  137. this.get('bootHosts').setEach('cpu', '2');
  138. this.get('bootHosts').setEach('memory', '2000000');
  139. this.set('isSubmitDisabled', false);
  140. } else {
  141. this.set('registrationStartedAt', null);
  142. this.startRegistration();
  143. }
  144. }
  145. }
  146. }.observes('isLoaded'),
  147. /**
  148. * Clear controller data
  149. * @method clearStep
  150. */
  151. clearStep: function () {
  152. this.set('stopBootstrap', false);
  153. this.set('hosts', []);
  154. this.get('bootHosts').clear();
  155. this.get('wizardController').setDBProperty('bootStatus', false);
  156. this.set('isSubmitDisabled', true);
  157. this.set('isRetryDisabled', true);
  158. },
  159. /**
  160. * Make basic init steps
  161. * @method loadStep
  162. */
  163. loadStep: function () {
  164. console.log("TRACE: Loading step3: Confirm Hosts");
  165. this.set('registrationStartedAt', null);
  166. this.set('isLoaded', false);
  167. this.disablePreviousSteps();
  168. this.clearStep();
  169. this.loadHosts();
  170. },
  171. /**
  172. * Loads the hostinfo from localStorage on the insertion of view. It's being called from view
  173. * @method loadHosts
  174. */
  175. loadHosts: function () {
  176. var hostsInfo = this.get('content.hosts');
  177. var hosts = [];
  178. var bootStatus = (this.get('content.installOptions.manualInstall')) ? 'DONE' : 'PENDING';
  179. if (App.testMode) {
  180. bootStatus = 'REGISTERED';
  181. }
  182. for (var index in hostsInfo) {
  183. if (hostsInfo.hasOwnProperty(index)) {
  184. hosts.pushObject(App.HostInfo.create({
  185. name: hostsInfo[index].name,
  186. bootStatus: bootStatus,
  187. isChecked: false
  188. }));
  189. }
  190. }
  191. this.set('hosts', hosts);
  192. this.set('isLoaded', true);
  193. },
  194. /**
  195. * Parses and updates the content based on bootstrap API response.
  196. * @return {bool} true if polling should continue (some hosts are in "RUNNING" state); false otherwise
  197. * @method parseHostInfo
  198. */
  199. parseHostInfo: function (hostsStatusFromServer) {
  200. hostsStatusFromServer.forEach(function (_hostStatus) {
  201. var host = this.get('bootHosts').findProperty('name', _hostStatus.hostName);
  202. // check if hostname extracted from REST API data matches any hostname in content
  203. // also, make sure that bootStatus modified by isHostsRegistered call does not get overwritten
  204. // since these calls are being made in parallel
  205. if (host && !['REGISTERED', 'REGISTERING'].contains(host.get('bootStatus'))) {
  206. host.set('bootStatus', _hostStatus.status);
  207. host.set('bootLog', _hostStatus.log);
  208. }
  209. }, this);
  210. // if the data rendered by REST API has hosts in "RUNNING" state, polling will continue
  211. return this.get('bootHosts').length != 0 && this.get('bootHosts').someProperty('bootStatus', 'RUNNING');
  212. },
  213. /**
  214. * Remove list of hosts
  215. * @param {Ember.Enumerable} hosts
  216. * @return {App.ModalPopup}
  217. * @method removeHosts
  218. */
  219. removeHosts: function (hosts) {
  220. var self = this;
  221. return App.showConfirmationPopup(function () {
  222. App.router.send('removeHosts', hosts);
  223. self.hosts.removeObjects(hosts);
  224. if (!self.hosts.length) {
  225. self.set('isSubmitDisabled', true);
  226. }
  227. }, Em.I18n.t('installer.step3.hosts.remove.popup.body'));
  228. },
  229. /**
  230. * Removes a single element on the trash icon click. Called from View
  231. * @param {object} hostInfo
  232. * @method removeHost
  233. */
  234. removeHost: function (hostInfo) {
  235. this.removeHosts([hostInfo]);
  236. },
  237. /**
  238. * Remove selected hosts (click-handler)
  239. * @return App.ModalPopup
  240. * @method removeSelectedHosts
  241. */
  242. removeSelectedHosts: function () {
  243. var selectedHosts = this.get('hosts').filterProperty('isChecked', true);
  244. selectedHosts.forEach(function (_hostInfo) {
  245. console.log('Removing: ' + _hostInfo.name);
  246. });
  247. return this.removeHosts(selectedHosts);
  248. },
  249. /**
  250. * Show popup with the list of hosts which are selected
  251. * @return App.ModalPopup
  252. * @method selectedHostsPopup
  253. */
  254. selectedHostsPopup: function () {
  255. var selectedHosts = this.get('hosts').filterProperty('isChecked').mapProperty('name');
  256. return App.ModalPopup.show({
  257. header: Em.I18n.t('installer.step3.selectedHosts.popup.header'),
  258. secondary: null,
  259. bodyClass: Em.View.extend({
  260. templateName: require('templates/common/items_list_popup'),
  261. items: selectedHosts,
  262. insertedItems: [],
  263. didInsertElement: function () {
  264. lazyloading.run({
  265. destination: this.get('insertedItems'),
  266. source: this.get('items'),
  267. context: this,
  268. initSize: 100,
  269. chunkSize: 500,
  270. delay: 100
  271. });
  272. }
  273. })
  274. });
  275. },
  276. /**
  277. * Retry one host {click-handler}
  278. * @param {object} hostInfo
  279. * @method retryHost
  280. */
  281. retryHost: function (hostInfo) {
  282. this.retryHosts([hostInfo]);
  283. },
  284. /**
  285. * Retry list of hosts
  286. * @param {object[]} hosts
  287. * @method retryHosts
  288. */
  289. retryHosts: function (hosts) {
  290. var bootStrapData = JSON.stringify({
  291. 'verbose': true,
  292. 'sshKey': this.get('content.installOptions.sshKey'),
  293. 'hosts': hosts.mapProperty('name'),
  294. 'user': this.get('content.installOptions.sshUser')}
  295. );
  296. this.set('numPolls', 0);
  297. this.set('registrationStartedAt', null);
  298. if (this.get('content.installOptions.manualInstall')) {
  299. this.get('bootHosts').setEach('bootStatus', 'DONE');
  300. this.startRegistration();
  301. }
  302. else {
  303. var requestId = App.router.get('installerController').launchBootstrap(bootStrapData);
  304. this.set('content.installOptions.bootRequestId', requestId);
  305. this.doBootstrap();
  306. }
  307. },
  308. /**
  309. * Retry selected hosts (click-handler)
  310. * @method retrySelectedHosts
  311. */
  312. retrySelectedHosts: function () {
  313. if (!this.get('isRetryDisabled')) {
  314. this.set('isRetryDisabled', true);
  315. var selectedHosts = this.get('bootHosts').filterProperty('bootStatus', 'FAILED');
  316. selectedHosts.forEach(function (_host) {
  317. _host.set('bootStatus', 'RUNNING');
  318. _host.set('bootLog', 'Retrying ...');
  319. }, this);
  320. this.retryHosts(selectedHosts);
  321. }
  322. },
  323. /**
  324. * Init bootstrap settings and start it
  325. * @method startBootstrap
  326. */
  327. startBootstrap: function () {
  328. //this.set('isSubmitDisabled', true); //TODO: uncomment after actual hookup
  329. this.set('numPolls', 0);
  330. this.set('registrationStartedAt', null);
  331. this.set('bootHosts', this.get('hosts'));
  332. this.doBootstrap();
  333. },
  334. /**
  335. * Update <code>isRegistrationInProgress</code> once
  336. * @method setRegistrationInProgressOnce
  337. */
  338. setRegistrationInProgressOnce: function () {
  339. Em.run.once(this, 'setRegistrationInProgress');
  340. }.observes('bootHosts.@each.bootStatus'),
  341. /**
  342. * Set <code>isRegistrationInProgress</code> value based on each host boot status
  343. * @method setRegistrationInProgress
  344. */
  345. setRegistrationInProgress: function () {
  346. var bootHosts = this.get('bootHosts');
  347. //if hosts aren't loaded yet then registration should be in progress
  348. var result = (bootHosts.length === 0 && !this.get('isLoaded'));
  349. for (var i = 0, l = bootHosts.length; i < l; i++) {
  350. if (bootHosts[i].get('bootStatus') !== 'REGISTERED' && bootHosts[i].get('bootStatus') !== 'FAILED') {
  351. result = true;
  352. break;
  353. }
  354. }
  355. this.set('isRegistrationInProgress', result);
  356. },
  357. /**
  358. * Disable wizard's previous steps (while registering)
  359. * @method disablePreviousSteps
  360. */
  361. disablePreviousSteps: function () {
  362. App.router.get('installerController.isStepDisabled').filter(function (step) {
  363. return step.step >= 0 && step.step <= 2;
  364. }).setEach('value', this.get('isRegistrationInProgress'));
  365. if (this.get('isRegistrationInProgress')) {
  366. this.set('isSubmitDisabled', true);
  367. }
  368. }.observes('isRegistrationInProgress'),
  369. /**
  370. * Do bootstrap calls
  371. * @method doBootstrap
  372. */
  373. doBootstrap: function () {
  374. if (this.get('stopBootstrap')) {
  375. return;
  376. }
  377. this.incrementProperty('numPolls');
  378. App.ajax.send({
  379. name: 'wizard.step3.bootstrap',
  380. sender: this,
  381. data: {
  382. bootRequestId: this.get('content.installOptions.bootRequestId'),
  383. numPolls: this.get('numPolls')
  384. },
  385. success: 'doBootstrapSuccessCallback'
  386. }).
  387. retry({
  388. times: App.maxRetries,
  389. timeout: App.timeout
  390. }).
  391. then(
  392. null,
  393. function () {
  394. App.showReloadPopup();
  395. console.log('Bootstrap failed');
  396. }
  397. );
  398. },
  399. /**
  400. * Success-callback for each boostrap request
  401. * @param {object} data
  402. * @method doBootstrapSuccessCallback
  403. */
  404. doBootstrapSuccessCallback: function (data) {
  405. var self = this;
  406. var pollingInterval = 3000;
  407. if (Em.isNone(data.hostsStatus)) {
  408. console.log('Invalid response, setting timeout');
  409. window.setTimeout(function () {
  410. self.doBootstrap()
  411. }, pollingInterval);
  412. } else {
  413. // in case of bootstrapping just one host, the server returns an object rather than an array, so
  414. // force into an array
  415. if (!(data.hostsStatus instanceof Array)) {
  416. data.hostsStatus = [ data.hostsStatus ];
  417. }
  418. console.log("TRACE: In success function for the GET bootstrap call");
  419. var keepPolling = this.parseHostInfo(data.hostsStatus);
  420. // Single host : if the only hostname is invalid (data.status == 'ERROR')
  421. // Multiple hosts : if one or more hostnames are invalid
  422. // following check will mark the bootStatus as 'FAILED' for the invalid hostname
  423. if (data.status == 'ERROR' || data.hostsStatus.length != this.get('bootHosts').length) {
  424. var hosts = this.get('bootHosts');
  425. for (var i = 0; i < hosts.length; i++) {
  426. var isValidHost = data.hostsStatus.someProperty('hostName', hosts[i].get('name'));
  427. if (hosts[i].get('bootStatus') !== 'REGISTERED') {
  428. if (!isValidHost) {
  429. hosts[i].set('bootStatus', 'FAILED');
  430. hosts[i].set('bootLog', Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  431. }
  432. }
  433. }
  434. }
  435. if (data.status == 'ERROR' || data.hostsStatus.someProperty('status', 'DONE') || data.hostsStatus.someProperty('status', 'FAILED')) {
  436. // kicking off registration polls after at least one host has succeeded
  437. this.startRegistration();
  438. }
  439. if (keepPolling) {
  440. window.setTimeout(function () {
  441. self.doBootstrap()
  442. }, pollingInterval);
  443. }
  444. }
  445. },
  446. /**
  447. * Start hosts registration
  448. * @method startRegistration
  449. */
  450. startRegistration: function () {
  451. if (Em.isNone(this.get('registrationStartedAt'))) {
  452. this.set('registrationStartedAt', App.dateTime());
  453. console.log('registration started at ' + this.get('registrationStartedAt'));
  454. this.isHostsRegistered();
  455. }
  456. },
  457. /**
  458. * Do requests to check if hosts are already registered
  459. * @method isHostsRegistered
  460. */
  461. isHostsRegistered: function () {
  462. if (this.get('stopBootstrap')) {
  463. return;
  464. }
  465. App.ajax.send({
  466. name: 'wizard.step3.is_hosts_registered',
  467. sender: this,
  468. success: 'isHostsRegisteredSuccessCallback'
  469. }).
  470. retry({
  471. times: App.maxRetries,
  472. timeout: App.timeout
  473. }).
  474. then(
  475. null,
  476. function () {
  477. App.showReloadPopup();
  478. console.log('Error: Getting registered host information from the server');
  479. }
  480. );
  481. },
  482. /**
  483. * Success-callback for registered hosts request
  484. * @param {object} data
  485. * @method isHostsRegisteredSuccessCallback
  486. */
  487. isHostsRegisteredSuccessCallback: function (data) {
  488. console.log('registration attempt...');
  489. var hosts = this.get('bootHosts');
  490. var jsonData = data;
  491. if (!jsonData) {
  492. console.warn("Error: jsonData is null");
  493. return;
  494. }
  495. // keep polling until all hosts have registered/failed, or registrationTimeout seconds after the last host finished bootstrapping
  496. var stopPolling = true;
  497. hosts.forEach(function (_host, index) {
  498. // Change name of first host for test mode.
  499. if (App.testMode) {
  500. if (index == 0) {
  501. _host.set('name', 'localhost.localdomain');
  502. }
  503. }
  504. // actions to take depending on the host's current bootStatus
  505. // RUNNING - bootstrap is running; leave it alone
  506. // DONE - bootstrap is done; transition to REGISTERING
  507. // REGISTERING - bootstrap is done but has not registered; transition to REGISTERED if host found in polling API result
  508. // REGISTERED - bootstrap and registration is done; leave it alone
  509. // FAILED - either bootstrap or registration failed; leave it alone
  510. switch (_host.get('bootStatus')) {
  511. case 'DONE':
  512. _host.set('bootStatus', 'REGISTERING');
  513. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  514. // update registration timestamp so that the timeout is computed from the last host that finished bootstrapping
  515. this.set('registrationStartedAt', App.dateTime());
  516. stopPolling = false;
  517. break;
  518. case 'REGISTERING':
  519. if (jsonData.items.someProperty('Hosts.host_name', _host.name)) {
  520. _host.set('bootStatus', 'REGISTERED');
  521. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  522. } else {
  523. stopPolling = false;
  524. }
  525. break;
  526. case 'RUNNING':
  527. stopPolling = false;
  528. break;
  529. case 'REGISTERED':
  530. case 'FAILED':
  531. default:
  532. break;
  533. }
  534. }, this);
  535. if (stopPolling) {
  536. this.getHostInfo();
  537. }
  538. else {
  539. if (hosts.someProperty('bootStatus', 'RUNNING') || App.dateTime() - this.get('registrationStartedAt') < this.get('registrationTimeoutSecs') * 1000) {
  540. // we want to keep polling for registration status if any of the hosts are still bootstrapping (so we check for RUNNING).
  541. var self = this;
  542. window.setTimeout(function () {
  543. self.isHostsRegistered();
  544. }, 3000);
  545. }
  546. else {
  547. // registration timed out. mark all REGISTERING hosts to FAILED
  548. console.log('registration timed out');
  549. hosts.filterProperty('bootStatus', 'REGISTERING').forEach(function (_host) {
  550. _host.set('bootStatus', 'FAILED');
  551. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  552. });
  553. this.getHostInfo();
  554. }
  555. }
  556. },
  557. /**
  558. * Do request for all registered hosts
  559. * @return {$.ajax}
  560. * @method getAllRegisteredHosts
  561. */
  562. getAllRegisteredHosts: function () {
  563. return App.ajax.send({
  564. name: 'wizard.step3.is_hosts_registered',
  565. sender: this,
  566. success: 'getAllRegisteredHostsCallback'
  567. });
  568. }.observes('bootHosts'),
  569. /**
  570. * Success-callback for all registered hosts request
  571. * @param {object} hosts
  572. * @method getAllRegisteredHostsCallback
  573. */
  574. getAllRegisteredHostsCallback: function (hosts) {
  575. var registeredHosts = [];
  576. var hostsInCluster = this.get('hostsInCluster');
  577. var addedHosts = this.get('bootHosts').getEach('name');
  578. hosts.items.forEach(function (host) {
  579. if (!hostsInCluster.contains(host.Hosts.host_name) && !addedHosts.contains(host.Hosts.host_name)) {
  580. registeredHosts.push(host.Hosts.host_name);
  581. }
  582. });
  583. if (registeredHosts.length) {
  584. this.set('hasMoreRegisteredHosts', true);
  585. this.set('registeredHosts', registeredHosts);
  586. } else {
  587. this.set('hasMoreRegisteredHosts', false);
  588. this.set('registeredHosts', '');
  589. }
  590. },
  591. /**
  592. * Show popup with regitration error-message
  593. * @param {string} header
  594. * @param {string} message
  595. * @return {App.ModalPopup}
  596. * @method registerErrPopup
  597. */
  598. registerErrPopup: function (header, message) {
  599. return App.ModalPopup.show({
  600. header: header,
  601. secondary: false,
  602. bodyClass: Em.View.extend({
  603. template: Em.Handlebars.compile('<p>{{view.message}}</p>'),
  604. message: message
  605. })
  606. });
  607. },
  608. /**
  609. * Get disk info and cpu count of booted hosts from server
  610. * @return {$.ajax}
  611. * @method getHostInfo
  612. */
  613. getHostInfo: function () {
  614. this.set('isWarningsLoaded', false);
  615. return App.ajax.send({
  616. name: 'wizard.step3.host_info',
  617. sender: this,
  618. success: 'getHostInfoSuccessCallback',
  619. error: 'getHostInfoErrorCallback'
  620. });
  621. },
  622. /**
  623. * Success-callback for hosts info request
  624. * @param {object} jsonData
  625. * @method getHostInfoSuccessCallback
  626. */
  627. getHostInfoSuccessCallback: function (jsonData) {
  628. var hosts = this.get('bootHosts');
  629. var self = this;
  630. this.parseWarnings(jsonData);
  631. var repoWarnings = [];
  632. var hostsContext = [];
  633. var diskWarnings = [];
  634. var hostsDiskContext = [];
  635. var hostsDiskNames = [];
  636. var hostsRepoNames = [];
  637. hosts.forEach(function (_host) {
  638. var host = (App.testMode) ? jsonData.items[0] : jsonData.items.findProperty('Hosts.host_name', _host.name);
  639. if (App.skipBootstrap) {
  640. _host.set('cpu', 2);
  641. _host.set('memory', ((parseInt(2000000))).toFixed(2));
  642. _host.set('disk_info', [
  643. {"mountpoint": "/", "type": "ext4"},
  644. {"mountpoint": "/grid/0", "type": "ext4"},
  645. {"mountpoint": "/grid/1", "type": "ext4"},
  646. {"mountpoint": "/grid/2", "type": "ext4"}
  647. ]);
  648. } else if (host) {
  649. _host.set('cpu', host.Hosts.cpu_count);
  650. _host.set('memory', ((parseInt(host.Hosts.total_mem))).toFixed(2));
  651. _host.set('disk_info', host.Hosts.disk_info.filter(function(host){ return host.mountpoint!="/boot"}));
  652. _host.set('os_type', host.Hosts.os_type);
  653. _host.set('os_arch', host.Hosts.os_arch);
  654. _host.set('ip', host.Hosts.ip);
  655. var context = self.checkHostOSType(host.Hosts.os_type, host.Hosts.host_name);
  656. if (context) {
  657. hostsContext.push(context);
  658. hostsRepoNames.push(host.Hosts.host_name);
  659. }
  660. var diskContext = self.checkHostDiskSpace(host.Hosts.host_name, host.Hosts.disk_info);
  661. if (diskContext) {
  662. hostsDiskContext.push(diskContext);
  663. hostsDiskNames.push(host.Hosts.host_name);
  664. }
  665. }
  666. });
  667. if (hostsContext.length > 0) { // warning exist
  668. var repoWarning = {
  669. name: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.name'),
  670. hosts: hostsContext,
  671. hostsNames: hostsRepoNames,
  672. category: 'repositories',
  673. onSingleHost: false
  674. };
  675. repoWarnings.push(repoWarning);
  676. }
  677. if (hostsDiskContext.length > 0) { // disk space warning exist
  678. var diskWarning = {
  679. name: Em.I18n.t('installer.step3.hostWarningsPopup.disk.name'),
  680. hosts: hostsDiskContext,
  681. hostsNames: hostsDiskNames,
  682. category: 'disk',
  683. onSingleHost: false
  684. };
  685. diskWarnings.push(diskWarning);
  686. }
  687. this.set('repoCategoryWarnings', repoWarnings);
  688. this.set('diskCategoryWarnings', diskWarnings);
  689. this.stopRegistration();
  690. },
  691. /**
  692. * Error-callback for hosts info request
  693. * @method getHostInfoErrorCallback
  694. */
  695. getHostInfoErrorCallback: function () {
  696. console.log('INFO: Getting host information(cpu_count and total_mem) from the server failed');
  697. this.set('isWarningsLoaded', true);
  698. this.registerErrPopup(Em.I18n.t('installer.step3.hostInformation.popup.header'), Em.I18n.t('installer.step3.hostInformation.popup.body'));
  699. },
  700. /**
  701. * Enable or disable submit/retry buttons according to hosts boot statuses
  702. * @method stopRegistration
  703. */
  704. stopRegistration: function () {
  705. this.set('isSubmitDisabled', !this.get('bootHosts').someProperty('bootStatus', 'REGISTERED'));
  706. this.set('isRetryDisabled', !this.get('bootHosts').someProperty('bootStatus', 'FAILED'));
  707. },
  708. /**
  709. * Check if the customized os group contains the registered host os type. If not the repo on that host is invalid.
  710. * @param {string} osType
  711. * @param {string} hostName
  712. * @return {string} error-message or empty string
  713. * @method checkHostOSType
  714. */
  715. checkHostOSType: function (osType, hostName) {
  716. if (this.get('content.stacks')) {
  717. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  718. var selectedOS = [];
  719. var isValid = false;
  720. if (selectedStack && selectedStack.operatingSystems) {
  721. selectedStack.get('operatingSystems').filterProperty('selected', true).forEach(function (os) {
  722. selectedOS.pushObject(os.osType);
  723. if (os.osType == osType) {
  724. isValid = true;
  725. }
  726. });
  727. }
  728. if (!isValid) {
  729. console.log('WARNING: Getting host os type does NOT match the user selected os group in step1. ' +
  730. 'Host Name: ' + hostName + '. Host os type:' + osType + '. Selected group:' + selectedOS);
  731. return Em.I18n.t('installer.step3.hostWarningsPopup.repositories.context').format(hostName, osType, selectedOS);
  732. } else {
  733. return '';
  734. }
  735. } else {
  736. return '';
  737. }
  738. },
  739. /**
  740. * Check if current host has enough free disk usage.
  741. * @param {string} hostName
  742. * @param {object} diskInfo
  743. * @return {string} error-message or empty string
  744. * @method checkHostDiskSpace
  745. */
  746. checkHostDiskSpace: function (hostName, diskInfo) {
  747. var minFreeRootSpace = App.minDiskSpace * 1024 * 1024; //in kilobyte
  748. var minFreeUsrLibSpace = App.minDiskSpaceUsrLib * 1024 * 1024; //in kilobyte
  749. var warningString = '';
  750. diskInfo.forEach(function (info) {
  751. switch (info.mountpoint) {
  752. case '/':
  753. warningString = info.available < minFreeRootSpace ?
  754. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpace + 'GB', info.mountpoint) + ' ' + warningString :
  755. warningString;
  756. break;
  757. case '/usr':
  758. case '/usr/lib':
  759. warningString = info.available < minFreeUsrLibSpace ?
  760. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpaceUsrLib + 'GB', info.mountpoint) + ' ' + warningString :
  761. warningString;
  762. break;
  763. default:
  764. break;
  765. }
  766. });
  767. if (warningString) {
  768. console.log('WARNING: Getting host free disk space. ' + 'Host Name: ' + hostName);
  769. return Em.I18n.t('installer.step3.hostWarningsPopup.disk.context1').format(hostName) + ' ' + warningString;
  770. } else {
  771. return '';
  772. }
  773. },
  774. /**
  775. * Submit-click handler
  776. * @return {App.ModalPopup|null}
  777. * @method submit
  778. */
  779. submit: function () {
  780. if (this.get('isHostHaveWarnings')) {
  781. var self = this;
  782. return App.showConfirmationPopup(
  783. function () {
  784. self.set('content.hosts', self.get('bootHosts'));
  785. App.router.send('next');
  786. },
  787. Em.I18n.t('installer.step3.hostWarningsPopup.hostHasWarnings'));
  788. }
  789. else {
  790. this.set('content.hosts', this.get('bootHosts'));
  791. App.router.send('next');
  792. }
  793. return null;
  794. },
  795. /**
  796. * Show popup with host log
  797. * @param {object} event
  798. * @return {App.ModalPopup}
  799. */
  800. hostLogPopup: function (event) {
  801. var host = event.context;
  802. return App.ModalPopup.show({
  803. header: Em.I18n.t('installer.step3.hostLog.popup.header').format(host.get('name')),
  804. secondary: null,
  805. host: host,
  806. bodyClass: App.WizardStep3HostLogPopupBody
  807. });
  808. },
  809. /**
  810. * Check warnings from server and put it in parsing
  811. * @method rerunChecks
  812. */
  813. rerunChecks: function () {
  814. var self = this;
  815. var currentProgress = 0;
  816. var interval = setInterval(function () {
  817. currentProgress += 100000 / self.get('warningsTimeInterval');
  818. if (currentProgress < 100) {
  819. self.set('checksUpdateProgress', currentProgress);
  820. } else {
  821. clearInterval(interval);
  822. App.ajax.send({
  823. name: 'wizard.step3.rerun_checks',
  824. sender: self,
  825. success: 'rerunChecksSuccessCallback',
  826. error: 'rerunChecksErrorCallback'
  827. });
  828. }
  829. }, 1000);
  830. },
  831. /**
  832. * Success-callback for rerun request
  833. * @param {object} data
  834. * @method rerunChecksSuccessCallback
  835. */
  836. rerunChecksSuccessCallback: function (data) {
  837. this.set('checksUpdateProgress', 100);
  838. this.set('checksUpdateStatus', 'SUCCESS');
  839. this.parseWarnings(data);
  840. },
  841. /**
  842. * Error-callback for rerun request
  843. * @method rerunChecksErrorCallback
  844. */
  845. rerunChecksErrorCallback: function () {
  846. this.set('checksUpdateProgress', 100);
  847. this.set('checksUpdateStatus', 'FAILED');
  848. console.log('INFO: Getting host information(last_agent_env) from the server failed');
  849. },
  850. /**
  851. * Filter data for warnings parse
  852. * is data from host in bootStrap
  853. * @param {object} data
  854. * @return {Object}
  855. * @method filterBootHosts
  856. */
  857. filterBootHosts: function (data) {
  858. var bootHostNames = {};
  859. this.get('bootHosts').forEach(function (bootHost) {
  860. bootHostNames[bootHost.get('name')] = true;
  861. });
  862. var filteredData = {
  863. href: data.href,
  864. items: []
  865. };
  866. data.items.forEach(function (host) {
  867. if (bootHostNames[host.Hosts.host_name]) {
  868. filteredData.items.push(host);
  869. }
  870. });
  871. return filteredData;
  872. },
  873. /**
  874. * Parse warnings data for each host and total
  875. * @param {object} data
  876. * @method parseWarnings
  877. */
  878. parseWarnings: function (data) {
  879. data = App.testMode ? data : this.filterBootHosts(data);
  880. var warnings = [];
  881. var warning;
  882. var hosts = [];
  883. var warningCategories = {
  884. fileFoldersWarnings: {},
  885. packagesWarnings: {},
  886. processesWarnings: {},
  887. servicesWarnings: {},
  888. usersWarnings: {},
  889. alternativeWarnings: {}
  890. };
  891. data.items.sortPropertyLight('Hosts.host_name').forEach(function (_host) {
  892. var host = {
  893. name: _host.Hosts.host_name,
  894. warnings: []
  895. };
  896. if (!_host.Hosts.last_agent_env) {
  897. // in some unusual circumstances when last_agent_env is not available from the _host,
  898. // skip the _host and proceed to process the rest of the hosts.
  899. console.log("last_agent_env is missing for " + _host.Hosts.host_name + ". Skipping _host check.");
  900. return;
  901. }
  902. //parse all directories and files warnings for host
  903. //todo: to be removed after check in new API
  904. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || [];
  905. stackFoldersAndFiles.forEach(function (path) {
  906. warning = warningCategories.fileFoldersWarnings[path.name];
  907. if (warning) {
  908. warning.hosts.push(_host.Hosts.host_name);
  909. warning.onSingleHost = false;
  910. } else {
  911. warningCategories.fileFoldersWarnings[path.name] = warning = {
  912. name: path.name,
  913. hosts: [_host.Hosts.host_name],
  914. category: 'fileFolders',
  915. onSingleHost: true
  916. };
  917. }
  918. host.warnings.push(warning);
  919. }, this);
  920. //parse all package warnings for host
  921. if (_host.Hosts.last_agent_env.installedPackages) {
  922. _host.Hosts.last_agent_env.installedPackages.forEach(function (_package) {
  923. warning = warningCategories.packagesWarnings[_package.name];
  924. if (warning) {
  925. warning.hosts.push(_host.Hosts.host_name);
  926. warning.version = _package.version;
  927. warning.onSingleHost = false;
  928. } else {
  929. warningCategories.packagesWarnings[_package.name] = warning = {
  930. name: _package.name,
  931. version: _package.version,
  932. hosts: [_host.Hosts.host_name],
  933. category: 'packages',
  934. onSingleHost: true
  935. };
  936. }
  937. host.warnings.push(warning);
  938. }, this);
  939. }
  940. //parse all process warnings for host
  941. //todo: to be removed after check in new API
  942. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  943. if (javaProcs) {
  944. javaProcs.forEach(function (process) {
  945. warning = warningCategories.processesWarnings[process.pid];
  946. if (warning) {
  947. warning.hosts.push(_host.Hosts.host_name);
  948. warning.onSingleHost = false;
  949. } else {
  950. warningCategories.processesWarnings[process.pid] = warning = {
  951. name: (process.command.substr(0, 35) + '...'),
  952. hosts: [_host.Hosts.host_name],
  953. category: 'processes',
  954. user: process.user,
  955. pid: process.pid,
  956. command: '<table><tr><td style="word-break: break-all;">' +
  957. ((process.command.length < 500) ? process.command : process.command.substr(0, 230) + '...' +
  958. '<p style="text-align: center">................</p>' +
  959. '...' + process.command.substr(-230)) + '</td></tr></table>',
  960. onSingleHost: true
  961. };
  962. }
  963. host.warnings.push(warning);
  964. }, this);
  965. }
  966. //parse all service warnings for host
  967. //todo: to be removed after check in new API
  968. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  969. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  970. if (service.status === 'Unhealthy') {
  971. warning = warningCategories.servicesWarnings[service.name];
  972. if (warning) {
  973. warning.hosts.push(_host.Hosts.host_name);
  974. warning.onSingleHost = false;
  975. } else {
  976. warningCategories.servicesWarnings[service.name] = warning = {
  977. name: service.name,
  978. hosts: [_host.Hosts.host_name],
  979. category: 'services',
  980. onSingleHost: true
  981. };
  982. }
  983. host.warnings.push(warning);
  984. }
  985. }, this);
  986. }
  987. //parse all user warnings for host
  988. //todo: to be removed after check in new API
  989. if (_host.Hosts.last_agent_env.existingUsers) {
  990. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  991. warning = warningCategories.usersWarnings[user.userName];
  992. if (warning) {
  993. warning.hosts.push(_host.Hosts.host_name);
  994. warning.onSingleHost = false;
  995. } else {
  996. warningCategories.usersWarnings[user.userName] = warning = {
  997. name: user.userName,
  998. hosts: [_host.Hosts.host_name],
  999. category: 'users',
  1000. onSingleHost: true
  1001. };
  1002. }
  1003. host.warnings.push(warning);
  1004. }, this);
  1005. }
  1006. //parse misc warnings for host
  1007. var umask = _host.Hosts.last_agent_env.umask;
  1008. if (umask && umask !== 18) {
  1009. warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
  1010. if (warning) {
  1011. warning.hosts.push(_host.Hosts.host_name);
  1012. warning.onSingleHost = false;
  1013. } else {
  1014. warning = {
  1015. name: umask,
  1016. hosts: [_host.Hosts.host_name],
  1017. category: 'misc',
  1018. onSingleHost: true
  1019. };
  1020. warnings.push(warning);
  1021. }
  1022. host.warnings.push(warning);
  1023. }
  1024. var firewallRunning = _host.Hosts.last_agent_env.iptablesIsRunning;
  1025. if (firewallRunning !== null && firewallRunning) {
  1026. var name = Em.I18n.t('installer.step3.hostWarningsPopup.firewall.name');
  1027. warning = warnings.filterProperty('category', 'firewall').findProperty('name', name);
  1028. if (warning) {
  1029. warning.hosts.push(_host.Hosts.host_name);
  1030. warning.onSingleHost = false;
  1031. } else {
  1032. warning = {
  1033. name: name,
  1034. hosts: [_host.Hosts.host_name],
  1035. category: 'firewall',
  1036. onSingleHost: true
  1037. };
  1038. warnings.push(warning);
  1039. }
  1040. host.warnings.push(warning);
  1041. }
  1042. if (_host.Hosts.last_agent_env.alternatives) {
  1043. _host.Hosts.last_agent_env.alternatives.forEach(function (alternative) {
  1044. warning = warningCategories.alternativeWarnings[alternative.name];
  1045. if (warning) {
  1046. warning.hosts.push(_host.Hosts.host_name);
  1047. warning.onSingleHost = false;
  1048. } else {
  1049. warningCategories.alternativeWarnings[alternative.name] = warning = {
  1050. name: alternative.name,
  1051. target: alternative.target,
  1052. hosts: [_host.Hosts.host_name],
  1053. category: 'alternatives',
  1054. onSingleHost: true
  1055. };
  1056. }
  1057. host.warnings.push(warning);
  1058. }, this);
  1059. }
  1060. hosts.push(host);
  1061. }, this);
  1062. for (var categoryId in warningCategories) {
  1063. var category = warningCategories[categoryId]
  1064. for (var warningId in category) {
  1065. warnings.push(category[warningId]);
  1066. }
  1067. }
  1068. warnings.forEach(function (warn) {
  1069. if (warn.hosts.length < 11) {
  1070. warn.hostsList = warn.hosts.join('<br>')
  1071. } else {
  1072. warn.hostsList = warn.hosts.slice(0, 10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  1073. }
  1074. });
  1075. hosts.unshift({
  1076. name: 'All Hosts',
  1077. warnings: warnings
  1078. });
  1079. this.set('warnings', warnings);
  1080. this.set('warningsByHost', hosts);
  1081. this.set('isWarningsLoaded', true);
  1082. },
  1083. /**
  1084. * Open popup that contain hosts' warnings
  1085. * @return {App.ModalPopup}
  1086. * @method hostWarningsPopup
  1087. */
  1088. hostWarningsPopup: function () {
  1089. var self = this;
  1090. return App.ModalPopup.show({
  1091. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  1092. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  1093. primary: Em.I18n.t('common.close'),
  1094. onPrimary: function () {
  1095. self.set('checksUpdateStatus', null);
  1096. this.hide();
  1097. },
  1098. onClose: function () {
  1099. self.set('checksUpdateStatus', null);
  1100. this.hide();
  1101. },
  1102. onSecondary: function () {
  1103. self.rerunChecks();
  1104. },
  1105. didInsertElement: function () {
  1106. this.fitHeight();
  1107. },
  1108. footerClass: App.WizardStep3HostWarningPopupFooter,
  1109. bodyClass: App.WizardStep3HostWarningPopupBody
  1110. });
  1111. },
  1112. /**
  1113. * Show popup with registered hosts
  1114. * @return {App.ModalPopup}
  1115. * @method registeredHostsPopup
  1116. */
  1117. registeredHostsPopup: function () {
  1118. var self = this;
  1119. return App.ModalPopup.show({
  1120. header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
  1121. secondary: null,
  1122. bodyClass: Em.View.extend({
  1123. templateName: require('templates/wizard/step3/step3_registered_hosts_popup'),
  1124. message: Em.I18n.t('installer.step3.registeredHostsPopup'),
  1125. registeredHosts: self.get('registeredHosts')
  1126. })
  1127. })
  1128. }
  1129. });