step3_controller.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  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.get('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 self = this;
  291. var bootStrapData = JSON.stringify({
  292. 'verbose': true,
  293. 'sshKey': this.get('content.installOptions.sshKey'),
  294. 'hosts': hosts.mapProperty('name'),
  295. 'user': this.get('content.installOptions.sshUser')}
  296. );
  297. this.set('numPolls', 0);
  298. this.set('registrationStartedAt', null);
  299. if (this.get('content.installOptions.manualInstall')) {
  300. this.get('bootHosts').setEach('bootStatus', 'DONE');
  301. this.startRegistration();
  302. }
  303. else {
  304. App.router.get(this.get('content.controllerName')).launchBootstrap(bootStrapData, function (requestId) {
  305. self.set('content.installOptions.bootRequestId', requestId);
  306. self.doBootstrap();
  307. });
  308. }
  309. },
  310. /**
  311. * Retry selected hosts (click-handler)
  312. * @method retrySelectedHosts
  313. */
  314. retrySelectedHosts: function () {
  315. if (!this.get('isRetryDisabled')) {
  316. this.set('isRetryDisabled', true);
  317. var selectedHosts = this.get('bootHosts').filterProperty('bootStatus', 'FAILED');
  318. selectedHosts.forEach(function (_host) {
  319. _host.set('bootStatus', 'RUNNING');
  320. _host.set('bootLog', 'Retrying ...');
  321. }, this);
  322. this.retryHosts(selectedHosts);
  323. }
  324. },
  325. /**
  326. * Init bootstrap settings and start it
  327. * @method startBootstrap
  328. */
  329. startBootstrap: function () {
  330. //this.set('isSubmitDisabled', true); //TODO: uncomment after actual hookup
  331. this.set('numPolls', 0);
  332. this.set('registrationStartedAt', null);
  333. this.set('bootHosts', this.get('hosts'));
  334. this.doBootstrap();
  335. },
  336. /**
  337. * Update <code>isRegistrationInProgress</code> once
  338. * @method setRegistrationInProgressOnce
  339. */
  340. setRegistrationInProgressOnce: function () {
  341. Em.run.once(this, 'setRegistrationInProgress');
  342. }.observes('bootHosts.@each.bootStatus'),
  343. /**
  344. * Set <code>isRegistrationInProgress</code> value based on each host boot status
  345. * @method setRegistrationInProgress
  346. */
  347. setRegistrationInProgress: function () {
  348. var bootHosts = this.get('bootHosts');
  349. //if hosts aren't loaded yet then registration should be in progress
  350. var result = (bootHosts.length === 0 && !this.get('isLoaded'));
  351. for (var i = 0, l = bootHosts.length; i < l; i++) {
  352. if (bootHosts[i].get('bootStatus') !== 'REGISTERED' && bootHosts[i].get('bootStatus') !== 'FAILED') {
  353. result = true;
  354. break;
  355. }
  356. }
  357. this.set('isRegistrationInProgress', result);
  358. },
  359. /**
  360. * Disable wizard's previous steps (while registering)
  361. * @method disablePreviousSteps
  362. */
  363. disablePreviousSteps: function () {
  364. App.router.get('installerController.isStepDisabled').filter(function (step) {
  365. return step.step >= 0 && step.step <= 2;
  366. }).setEach('value', this.get('isRegistrationInProgress'));
  367. if (this.get('isRegistrationInProgress')) {
  368. this.set('isSubmitDisabled', true);
  369. }
  370. }.observes('isRegistrationInProgress'),
  371. /**
  372. * Do bootstrap calls
  373. * @method doBootstrap
  374. * @return {$.ajax|null}
  375. */
  376. doBootstrap: function () {
  377. if (this.get('stopBootstrap')) {
  378. return null;
  379. }
  380. this.incrementProperty('numPolls');
  381. return App.ajax.send({
  382. name: 'wizard.step3.bootstrap',
  383. sender: this,
  384. data: {
  385. bootRequestId: this.get('content.installOptions.bootRequestId'),
  386. numPolls: this.get('numPolls')
  387. },
  388. success: 'doBootstrapSuccessCallback'
  389. }).
  390. retry({
  391. times: App.maxRetries,
  392. timeout: App.timeout
  393. }).
  394. then(
  395. null,
  396. function () {
  397. App.showReloadPopup();
  398. console.log('Bootstrap failed');
  399. }
  400. );
  401. },
  402. /**
  403. * Success-callback for each boostrap request
  404. * @param {object} data
  405. * @method doBootstrapSuccessCallback
  406. */
  407. doBootstrapSuccessCallback: function (data) {
  408. var self = this;
  409. var pollingInterval = 3000;
  410. if (Em.isNone(data.hostsStatus)) {
  411. console.log('Invalid response, setting timeout');
  412. window.setTimeout(function () {
  413. self.doBootstrap()
  414. }, pollingInterval);
  415. } else {
  416. // in case of bootstrapping just one host, the server returns an object rather than an array, so
  417. // force into an array
  418. if (!(data.hostsStatus instanceof Array)) {
  419. data.hostsStatus = [ data.hostsStatus ];
  420. }
  421. console.log("TRACE: In success function for the GET bootstrap call");
  422. var keepPolling = this.parseHostInfo(data.hostsStatus);
  423. // Single host : if the only hostname is invalid (data.status == 'ERROR')
  424. // Multiple hosts : if one or more hostnames are invalid
  425. // following check will mark the bootStatus as 'FAILED' for the invalid hostname
  426. if (data.status == 'ERROR' || data.hostsStatus.length != this.get('bootHosts').length) {
  427. var hosts = this.get('bootHosts');
  428. for (var i = 0; i < hosts.length; i++) {
  429. var isValidHost = data.hostsStatus.someProperty('hostName', hosts[i].get('name'));
  430. if (hosts[i].get('bootStatus') !== 'REGISTERED') {
  431. if (!isValidHost) {
  432. hosts[i].set('bootStatus', 'FAILED');
  433. hosts[i].set('bootLog', Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  434. }
  435. }
  436. }
  437. }
  438. if (data.status == 'ERROR' || data.hostsStatus.someProperty('status', 'DONE') || data.hostsStatus.someProperty('status', 'FAILED')) {
  439. // kicking off registration polls after at least one host has succeeded
  440. this.startRegistration();
  441. }
  442. if (keepPolling) {
  443. window.setTimeout(function () {
  444. self.doBootstrap()
  445. }, pollingInterval);
  446. }
  447. }
  448. },
  449. /**
  450. * Start hosts registration
  451. * @method startRegistration
  452. */
  453. startRegistration: function () {
  454. if (Em.isNone(this.get('registrationStartedAt'))) {
  455. this.set('registrationStartedAt', App.dateTime());
  456. console.log('registration started at ' + this.get('registrationStartedAt'));
  457. this.isHostsRegistered();
  458. }
  459. },
  460. /**
  461. * Do requests to check if hosts are already registered
  462. * @return {$.ajax|null}
  463. * @method isHostsRegistered
  464. */
  465. isHostsRegistered: function () {
  466. if (this.get('stopBootstrap')) {
  467. return null;
  468. }
  469. return App.ajax.send({
  470. name: 'wizard.step3.is_hosts_registered',
  471. sender: this,
  472. success: 'isHostsRegisteredSuccessCallback'
  473. }).
  474. retry({
  475. times: App.maxRetries,
  476. timeout: App.timeout
  477. }).
  478. then(
  479. null,
  480. function () {
  481. App.showReloadPopup();
  482. console.log('Error: Getting registered host information from the server');
  483. }
  484. );
  485. },
  486. /**
  487. * Success-callback for registered hosts request
  488. * @param {object} data
  489. * @method isHostsRegisteredSuccessCallback
  490. */
  491. isHostsRegisteredSuccessCallback: function (data) {
  492. console.log('registration attempt...');
  493. var hosts = this.get('bootHosts');
  494. var jsonData = data;
  495. if (!jsonData) {
  496. console.warn("Error: jsonData is null");
  497. return;
  498. }
  499. // keep polling until all hosts have registered/failed, or registrationTimeout seconds after the last host finished bootstrapping
  500. var stopPolling = true;
  501. hosts.forEach(function (_host, index) {
  502. // Change name of first host for test mode.
  503. if (App.testMode) {
  504. if (index == 0) {
  505. _host.set('name', 'localhost.localdomain');
  506. }
  507. }
  508. // actions to take depending on the host's current bootStatus
  509. // RUNNING - bootstrap is running; leave it alone
  510. // DONE - bootstrap is done; transition to REGISTERING
  511. // REGISTERING - bootstrap is done but has not registered; transition to REGISTERED if host found in polling API result
  512. // REGISTERED - bootstrap and registration is done; leave it alone
  513. // FAILED - either bootstrap or registration failed; leave it alone
  514. switch (_host.get('bootStatus')) {
  515. case 'DONE':
  516. _host.set('bootStatus', 'REGISTERING');
  517. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  518. // update registration timestamp so that the timeout is computed from the last host that finished bootstrapping
  519. this.set('registrationStartedAt', App.dateTime());
  520. stopPolling = false;
  521. break;
  522. case 'REGISTERING':
  523. if (jsonData.items.someProperty('Hosts.host_name', _host.name)) {
  524. _host.set('bootStatus', 'REGISTERED');
  525. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  526. } else {
  527. stopPolling = false;
  528. }
  529. break;
  530. case 'RUNNING':
  531. stopPolling = false;
  532. break;
  533. case 'REGISTERED':
  534. case 'FAILED':
  535. default:
  536. break;
  537. }
  538. }, this);
  539. if (stopPolling) {
  540. this.getHostInfo();
  541. }
  542. else {
  543. if (hosts.someProperty('bootStatus', 'RUNNING') || App.dateTime() - this.get('registrationStartedAt') < this.get('registrationTimeoutSecs') * 1000) {
  544. // we want to keep polling for registration status if any of the hosts are still bootstrapping (so we check for RUNNING).
  545. var self = this;
  546. window.setTimeout(function () {
  547. self.isHostsRegistered();
  548. }, 3000);
  549. }
  550. else {
  551. // registration timed out. mark all REGISTERING hosts to FAILED
  552. console.log('registration timed out');
  553. hosts.filterProperty('bootStatus', 'REGISTERING').forEach(function (_host) {
  554. _host.set('bootStatus', 'FAILED');
  555. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  556. });
  557. this.getHostInfo();
  558. }
  559. }
  560. },
  561. /**
  562. * Do request for all registered hosts
  563. * @return {$.ajax}
  564. * @method getAllRegisteredHosts
  565. */
  566. getAllRegisteredHosts: function () {
  567. return App.ajax.send({
  568. name: 'wizard.step3.is_hosts_registered',
  569. sender: this,
  570. success: 'getAllRegisteredHostsCallback'
  571. });
  572. }.observes('bootHosts'),
  573. /**
  574. * Success-callback for all registered hosts request
  575. * @param {object} hosts
  576. * @method getAllRegisteredHostsCallback
  577. */
  578. getAllRegisteredHostsCallback: function (hosts) {
  579. var registeredHosts = [];
  580. var hostsInCluster = this.get('hostsInCluster');
  581. var addedHosts = this.get('bootHosts').getEach('name');
  582. hosts.items.forEach(function (host) {
  583. if (!hostsInCluster.contains(host.Hosts.host_name) && !addedHosts.contains(host.Hosts.host_name)) {
  584. registeredHosts.push(host.Hosts.host_name);
  585. }
  586. });
  587. if (registeredHosts.length) {
  588. this.set('hasMoreRegisteredHosts', true);
  589. this.set('registeredHosts', registeredHosts);
  590. } else {
  591. this.set('hasMoreRegisteredHosts', false);
  592. this.set('registeredHosts', '');
  593. }
  594. },
  595. /**
  596. * Show popup with regitration error-message
  597. * @param {string} header
  598. * @param {string} message
  599. * @return {App.ModalPopup}
  600. * @method registerErrPopup
  601. */
  602. registerErrPopup: function (header, message) {
  603. return App.ModalPopup.show({
  604. header: header,
  605. secondary: false,
  606. bodyClass: Em.View.extend({
  607. template: Em.Handlebars.compile('<p>{{view.message}}</p>'),
  608. message: message
  609. })
  610. });
  611. },
  612. /**
  613. * Get disk info and cpu count of booted hosts from server
  614. * @return {$.ajax}
  615. * @method getHostInfo
  616. */
  617. getHostInfo: function () {
  618. this.set('isWarningsLoaded', false);
  619. return App.ajax.send({
  620. name: 'wizard.step3.host_info',
  621. sender: this,
  622. success: 'getHostInfoSuccessCallback',
  623. error: 'getHostInfoErrorCallback'
  624. });
  625. },
  626. /**
  627. * Success-callback for hosts info request
  628. * @param {object} jsonData
  629. * @method getHostInfoSuccessCallback
  630. */
  631. getHostInfoSuccessCallback: function (jsonData) {
  632. var hosts = this.get('bootHosts'),
  633. self = this,
  634. repoWarnings = [],
  635. hostsContext = [],
  636. diskWarnings = [],
  637. hostsDiskContext = [],
  638. hostsDiskNames = [],
  639. hostsRepoNames = [];
  640. this.parseWarnings(jsonData);
  641. hosts.forEach(function (_host) {
  642. var host = (App.get('testMode')) ? jsonData.items[0] : jsonData.items.findProperty('Hosts.host_name', _host.name);
  643. if (App.get('skipBootstrap')) {
  644. self._setHostDataWithSkipBootstrap(_host);
  645. }
  646. else {
  647. if (host) {
  648. self._setHostDataFromLoadedHostInfo(_host, host);
  649. var host_name = Em.get(host, 'Hosts.host_name');
  650. var context = self.checkHostOSType(host.Hosts.os_type, host_name);
  651. if (context) {
  652. hostsContext.push(context);
  653. hostsRepoNames.push(host_name);
  654. }
  655. var diskContext = self.checkHostDiskSpace(host_name, host.Hosts.disk_info);
  656. if (diskContext) {
  657. hostsDiskContext.push(diskContext);
  658. hostsDiskNames.push(host_name);
  659. }
  660. }
  661. }
  662. });
  663. if (hostsContext.length > 0) { // warning exist
  664. repoWarnings.push({
  665. name: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.name'),
  666. hosts: hostsContext,
  667. hostsNames: hostsRepoNames,
  668. category: 'repositories',
  669. onSingleHost: false
  670. });
  671. }
  672. if (hostsDiskContext.length > 0) { // disk space warning exist
  673. diskWarnings.push({
  674. name: Em.I18n.t('installer.step3.hostWarningsPopup.disk.name'),
  675. hosts: hostsDiskContext,
  676. hostsNames: hostsDiskNames,
  677. category: 'disk',
  678. onSingleHost: false
  679. });
  680. }
  681. this.set('repoCategoryWarnings', repoWarnings);
  682. this.set('diskCategoryWarnings', diskWarnings);
  683. this.stopRegistration();
  684. },
  685. /**
  686. * Set metrics to host object
  687. * Used when <code>App.skipBootstrap</code> is true
  688. * @param {Ember.Object} host
  689. * @returns {object}
  690. * @private
  691. * @methos _setHostDataWithSkipBootstrap
  692. */
  693. _setHostDataWithSkipBootstrap: function(host) {
  694. host.set('cpu', 2);
  695. host.set('memory', ((parseInt(2000000))).toFixed(2));
  696. host.set('disk_info', [
  697. {"mountpoint": "/", "type": "ext4"},
  698. {"mountpoint": "/grid/0", "type": "ext4"},
  699. {"mountpoint": "/grid/1", "type": "ext4"},
  700. {"mountpoint": "/grid/2", "type": "ext4"}
  701. ]);
  702. return host;
  703. },
  704. /**
  705. * Set loaded metrics to host object
  706. * @param {object} host
  707. * @param {object} hostInfo
  708. * @returns {object}
  709. * @method _setHostDataFromLoadedHostInfo
  710. * @private
  711. */
  712. _setHostDataFromLoadedHostInfo: function(host, hostInfo) {
  713. host.set('cpu', Em.get(hostInfo, 'Hosts.cpu_count'));
  714. host.set('memory', ((parseInt(Em.get(hostInfo, 'Hosts.total_mem')))).toFixed(2));
  715. host.set('disk_info', Em.get(hostInfo, 'Hosts.disk_info').filter(function (h) {
  716. return h.mountpoint != "/boot"
  717. }));
  718. host.set('os_type', Em.get(hostInfo, 'Hosts.os_type'));
  719. host.set('os_arch', Em.get(hostInfo, 'Hosts.os_arch'));
  720. host.set('ip', Em.get(hostInfo, 'Hosts.ip'));
  721. return host;
  722. },
  723. /**
  724. * Error-callback for hosts info request
  725. * @method getHostInfoErrorCallback
  726. */
  727. getHostInfoErrorCallback: function () {
  728. console.log('INFO: Getting host information(cpu_count and total_mem) from the server failed');
  729. this.set('isWarningsLoaded', true);
  730. this.registerErrPopup(Em.I18n.t('installer.step3.hostInformation.popup.header'), Em.I18n.t('installer.step3.hostInformation.popup.body'));
  731. },
  732. /**
  733. * Enable or disable submit/retry buttons according to hosts boot statuses
  734. * @method stopRegistration
  735. */
  736. stopRegistration: function () {
  737. this.set('isSubmitDisabled', !this.get('bootHosts').someProperty('bootStatus', 'REGISTERED'));
  738. this.set('isRetryDisabled', !this.get('bootHosts').someProperty('bootStatus', 'FAILED'));
  739. },
  740. /**
  741. * Check if the customized os group contains the registered host os type. If not the repo on that host is invalid.
  742. * @param {string} osType
  743. * @param {string} hostName
  744. * @return {string} error-message or empty string
  745. * @method checkHostOSType
  746. */
  747. checkHostOSType: function (osType, hostName) {
  748. if (this.get('content.stacks')) {
  749. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  750. var selectedOS = [];
  751. var isValid = false;
  752. if (selectedStack && selectedStack.operatingSystems) {
  753. selectedStack.get('operatingSystems').filterProperty('selected', true).forEach(function (os) {
  754. selectedOS.pushObject(os.osType);
  755. if (os.osType == osType) {
  756. isValid = true;
  757. }
  758. });
  759. }
  760. if (isValid) {
  761. return '';
  762. } else {
  763. console.log('WARNING: Getting host os type does NOT match the user selected os group in step1. ' +
  764. 'Host Name: ' + hostName + '. Host os type:' + osType + '. Selected group:' + selectedOS);
  765. return Em.I18n.t('installer.step3.hostWarningsPopup.repositories.context').format(hostName, osType, selectedOS);
  766. }
  767. } else {
  768. return '';
  769. }
  770. },
  771. /**
  772. * Check if current host has enough free disk usage.
  773. * @param {string} hostName
  774. * @param {object} diskInfo
  775. * @return {string} error-message or empty string
  776. * @method checkHostDiskSpace
  777. */
  778. checkHostDiskSpace: function (hostName, diskInfo) {
  779. var minFreeRootSpace = App.minDiskSpace * 1024 * 1024; //in kilobyte
  780. var minFreeUsrLibSpace = App.minDiskSpaceUsrLib * 1024 * 1024; //in kilobyte
  781. var warningString = '';
  782. diskInfo.forEach(function (info) {
  783. switch (info.mountpoint) {
  784. case '/':
  785. warningString = info.available < minFreeRootSpace ?
  786. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpace + 'GB', info.mountpoint) + ' ' + warningString :
  787. warningString;
  788. break;
  789. case '/usr':
  790. case '/usr/lib':
  791. warningString = info.available < minFreeUsrLibSpace ?
  792. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpaceUsrLib + 'GB', info.mountpoint) + ' ' + warningString :
  793. warningString;
  794. break;
  795. default:
  796. break;
  797. }
  798. });
  799. if (warningString) {
  800. console.log('WARNING: Getting host free disk space. ' + 'Host Name: ' + hostName);
  801. return Em.I18n.t('installer.step3.hostWarningsPopup.disk.context1').format(hostName) + ' ' + warningString;
  802. } else {
  803. return '';
  804. }
  805. },
  806. /**
  807. * Submit-click handler
  808. * @return {App.ModalPopup|null}
  809. * @method submit
  810. */
  811. submit: function () {
  812. if (this.get('isHostHaveWarnings')) {
  813. var self = this;
  814. return App.showConfirmationPopup(
  815. function () {
  816. self.set('content.hosts', self.get('bootHosts'));
  817. App.router.send('next');
  818. },
  819. Em.I18n.t('installer.step3.hostWarningsPopup.hostHasWarnings'));
  820. }
  821. else {
  822. this.set('content.hosts', this.get('bootHosts'));
  823. App.router.send('next');
  824. }
  825. return null;
  826. },
  827. /**
  828. * Show popup with host log
  829. * @param {object} event
  830. * @return {App.ModalPopup}
  831. */
  832. hostLogPopup: function (event) {
  833. var host = event.context;
  834. return App.ModalPopup.show({
  835. header: Em.I18n.t('installer.step3.hostLog.popup.header').format(host.get('name')),
  836. secondary: null,
  837. host: host,
  838. bodyClass: App.WizardStep3HostLogPopupBody
  839. });
  840. },
  841. /**
  842. * Check warnings from server and put it in parsing
  843. * @method rerunChecks
  844. */
  845. rerunChecks: function () {
  846. var self = this;
  847. var currentProgress = 0;
  848. var interval = setInterval(function () {
  849. currentProgress += 100000 / self.get('warningsTimeInterval');
  850. if (currentProgress < 100) {
  851. self.set('checksUpdateProgress', currentProgress);
  852. } else {
  853. clearInterval(interval);
  854. App.ajax.send({
  855. name: 'wizard.step3.rerun_checks',
  856. sender: self,
  857. success: 'rerunChecksSuccessCallback',
  858. error: 'rerunChecksErrorCallback'
  859. });
  860. }
  861. }, 1000);
  862. },
  863. /**
  864. * Success-callback for rerun request
  865. * @param {object} data
  866. * @method rerunChecksSuccessCallback
  867. */
  868. rerunChecksSuccessCallback: function (data) {
  869. this.set('checksUpdateProgress', 100);
  870. this.set('checksUpdateStatus', 'SUCCESS');
  871. this.parseWarnings(data);
  872. },
  873. /**
  874. * Error-callback for rerun request
  875. * @method rerunChecksErrorCallback
  876. */
  877. rerunChecksErrorCallback: function () {
  878. this.set('checksUpdateProgress', 100);
  879. this.set('checksUpdateStatus', 'FAILED');
  880. console.log('INFO: Getting host information(last_agent_env) from the server failed');
  881. },
  882. /**
  883. * Filter data for warnings parse
  884. * is data from host in bootStrap
  885. * @param {object} data
  886. * @return {Object}
  887. * @method filterBootHosts
  888. */
  889. filterBootHosts: function (data) {
  890. var bootHostNames = {};
  891. this.get('bootHosts').forEach(function (bootHost) {
  892. bootHostNames[bootHost.get('name')] = true;
  893. });
  894. var filteredData = {
  895. href: data.href,
  896. items: []
  897. };
  898. data.items.forEach(function (host) {
  899. if (bootHostNames[host.Hosts.host_name]) {
  900. filteredData.items.push(host);
  901. }
  902. });
  903. return filteredData;
  904. },
  905. /**
  906. * Parse warnings data for each host and total
  907. * @param {object} data
  908. * @method parseWarnings
  909. */
  910. parseWarnings: function (data) {
  911. data = App.testMode ? data : this.filterBootHosts(data);
  912. var warnings = [];
  913. var warning;
  914. var hosts = [];
  915. var warningCategories = {
  916. fileFoldersWarnings: {},
  917. packagesWarnings: {},
  918. processesWarnings: {},
  919. servicesWarnings: {},
  920. usersWarnings: {},
  921. alternativeWarnings: {}
  922. };
  923. data.items.sortPropertyLight('Hosts.host_name').forEach(function (_host) {
  924. var host = {
  925. name: _host.Hosts.host_name,
  926. warnings: []
  927. };
  928. if (!_host.Hosts.last_agent_env) {
  929. // in some unusual circumstances when last_agent_env is not available from the _host,
  930. // skip the _host and proceed to process the rest of the hosts.
  931. console.log("last_agent_env is missing for " + _host.Hosts.host_name + ". Skipping _host check.");
  932. return;
  933. }
  934. //parse all directories and files warnings for host
  935. //todo: to be removed after check in new API
  936. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || [];
  937. stackFoldersAndFiles.forEach(function (path) {
  938. warning = warningCategories.fileFoldersWarnings[path.name];
  939. if (warning) {
  940. warning.hosts.push(_host.Hosts.host_name);
  941. warning.onSingleHost = false;
  942. } else {
  943. warningCategories.fileFoldersWarnings[path.name] = warning = {
  944. name: path.name,
  945. hosts: [_host.Hosts.host_name],
  946. category: 'fileFolders',
  947. onSingleHost: true
  948. };
  949. }
  950. host.warnings.push(warning);
  951. }, this);
  952. //parse all package warnings for host
  953. if (_host.Hosts.last_agent_env.installedPackages) {
  954. _host.Hosts.last_agent_env.installedPackages.forEach(function (_package) {
  955. warning = warningCategories.packagesWarnings[_package.name];
  956. if (warning) {
  957. warning.hosts.push(_host.Hosts.host_name);
  958. warning.version = _package.version;
  959. warning.onSingleHost = false;
  960. } else {
  961. warningCategories.packagesWarnings[_package.name] = warning = {
  962. name: _package.name,
  963. version: _package.version,
  964. hosts: [_host.Hosts.host_name],
  965. category: 'packages',
  966. onSingleHost: true
  967. };
  968. }
  969. host.warnings.push(warning);
  970. }, this);
  971. }
  972. //parse all process warnings for host
  973. //todo: to be removed after check in new API
  974. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  975. if (javaProcs) {
  976. javaProcs.forEach(function (process) {
  977. warning = warningCategories.processesWarnings[process.pid];
  978. if (warning) {
  979. warning.hosts.push(_host.Hosts.host_name);
  980. warning.onSingleHost = false;
  981. } else {
  982. warningCategories.processesWarnings[process.pid] = warning = {
  983. name: (process.command.substr(0, 35) + '...'),
  984. hosts: [_host.Hosts.host_name],
  985. category: 'processes',
  986. user: process.user,
  987. pid: process.pid,
  988. command: '<table><tr><td style="word-break: break-all;">' +
  989. ((process.command.length < 500) ? process.command : process.command.substr(0, 230) + '...' +
  990. '<p style="text-align: center">................</p>' +
  991. '...' + process.command.substr(-230)) + '</td></tr></table>',
  992. onSingleHost: true
  993. };
  994. }
  995. host.warnings.push(warning);
  996. }, this);
  997. }
  998. //parse all service warnings for host
  999. //todo: to be removed after check in new API
  1000. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  1001. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  1002. if (service.status === 'Unhealthy') {
  1003. warning = warningCategories.servicesWarnings[service.name];
  1004. if (warning) {
  1005. warning.hosts.push(_host.Hosts.host_name);
  1006. warning.onSingleHost = false;
  1007. } else {
  1008. warningCategories.servicesWarnings[service.name] = warning = {
  1009. name: service.name,
  1010. hosts: [_host.Hosts.host_name],
  1011. category: 'services',
  1012. onSingleHost: true
  1013. };
  1014. }
  1015. host.warnings.push(warning);
  1016. }
  1017. }, this);
  1018. }
  1019. //parse all user warnings for host
  1020. //todo: to be removed after check in new API
  1021. if (_host.Hosts.last_agent_env.existingUsers) {
  1022. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  1023. warning = warningCategories.usersWarnings[user.userName];
  1024. if (warning) {
  1025. warning.hosts.push(_host.Hosts.host_name);
  1026. warning.onSingleHost = false;
  1027. } else {
  1028. warningCategories.usersWarnings[user.userName] = warning = {
  1029. name: user.userName,
  1030. hosts: [_host.Hosts.host_name],
  1031. category: 'users',
  1032. onSingleHost: true
  1033. };
  1034. }
  1035. host.warnings.push(warning);
  1036. }, this);
  1037. }
  1038. //parse misc warnings for host
  1039. var umask = _host.Hosts.last_agent_env.umask;
  1040. if (umask && umask !== 18) {
  1041. warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
  1042. if (warning) {
  1043. warning.hosts.push(_host.Hosts.host_name);
  1044. warning.onSingleHost = false;
  1045. } else {
  1046. warning = {
  1047. name: umask,
  1048. hosts: [_host.Hosts.host_name],
  1049. category: 'misc',
  1050. onSingleHost: true
  1051. };
  1052. warnings.push(warning);
  1053. }
  1054. host.warnings.push(warning);
  1055. }
  1056. var firewallRunning = _host.Hosts.last_agent_env.iptablesIsRunning;
  1057. if (firewallRunning !== null && firewallRunning) {
  1058. var name = Em.I18n.t('installer.step3.hostWarningsPopup.firewall.name');
  1059. warning = warnings.filterProperty('category', 'firewall').findProperty('name', name);
  1060. if (warning) {
  1061. warning.hosts.push(_host.Hosts.host_name);
  1062. warning.onSingleHost = false;
  1063. } else {
  1064. warning = {
  1065. name: name,
  1066. hosts: [_host.Hosts.host_name],
  1067. category: 'firewall',
  1068. onSingleHost: true
  1069. };
  1070. warnings.push(warning);
  1071. }
  1072. host.warnings.push(warning);
  1073. }
  1074. if (_host.Hosts.last_agent_env.alternatives) {
  1075. _host.Hosts.last_agent_env.alternatives.forEach(function (alternative) {
  1076. warning = warningCategories.alternativeWarnings[alternative.name];
  1077. if (warning) {
  1078. warning.hosts.push(_host.Hosts.host_name);
  1079. warning.onSingleHost = false;
  1080. } else {
  1081. warningCategories.alternativeWarnings[alternative.name] = warning = {
  1082. name: alternative.name,
  1083. target: alternative.target,
  1084. hosts: [_host.Hosts.host_name],
  1085. category: 'alternatives',
  1086. onSingleHost: true
  1087. };
  1088. }
  1089. host.warnings.push(warning);
  1090. }, this);
  1091. }
  1092. if (_host.Hosts.last_agent_env.reverseLookup === false) {
  1093. var name = Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.name');
  1094. warning = warnings.filterProperty('category', 'reverseLookup').findProperty('name', name);
  1095. if (warning) {
  1096. warning.hosts.push(_host.Hosts.host_name);
  1097. warning.onSingleHost = false;
  1098. } else {
  1099. warning = {
  1100. name: name,
  1101. hosts: [_host.Hosts.host_name],
  1102. category: 'reverseLookup',
  1103. onSingleHost: true
  1104. };
  1105. warnings.push(warning);
  1106. }
  1107. host.warnings.push(warning);
  1108. }
  1109. hosts.push(host);
  1110. }, this);
  1111. for (var categoryId in warningCategories) {
  1112. var category = warningCategories[categoryId]
  1113. for (var warningId in category) {
  1114. warnings.push(category[warningId]);
  1115. }
  1116. }
  1117. warnings.forEach(function (warn) {
  1118. if (warn.hosts.length < 11) {
  1119. warn.hostsList = warn.hosts.join('<br>')
  1120. } else {
  1121. warn.hostsList = warn.hosts.slice(0, 10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  1122. }
  1123. });
  1124. hosts.unshift({
  1125. name: 'All Hosts',
  1126. warnings: warnings
  1127. });
  1128. this.set('warnings', warnings);
  1129. this.set('warningsByHost', hosts);
  1130. this.set('isWarningsLoaded', true);
  1131. },
  1132. /**
  1133. * Open popup that contain hosts' warnings
  1134. * @return {App.ModalPopup}
  1135. * @method hostWarningsPopup
  1136. */
  1137. hostWarningsPopup: function () {
  1138. var self = this;
  1139. return App.ModalPopup.show({
  1140. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  1141. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  1142. primary: Em.I18n.t('common.close'),
  1143. onPrimary: function () {
  1144. self.set('checksUpdateStatus', null);
  1145. this.hide();
  1146. },
  1147. onClose: function () {
  1148. self.set('checksUpdateStatus', null);
  1149. this.hide();
  1150. },
  1151. onSecondary: function () {
  1152. self.rerunChecks();
  1153. },
  1154. didInsertElement: function () {
  1155. this.fitHeight();
  1156. },
  1157. footerClass: App.WizardStep3HostWarningPopupFooter,
  1158. bodyClass: App.WizardStep3HostWarningPopupBody
  1159. });
  1160. },
  1161. /**
  1162. * Show popup with registered hosts
  1163. * @return {App.ModalPopup}
  1164. * @method registeredHostsPopup
  1165. */
  1166. registeredHostsPopup: function () {
  1167. var self = this;
  1168. return App.ModalPopup.show({
  1169. header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
  1170. secondary: null,
  1171. bodyClass: Em.View.extend({
  1172. templateName: require('templates/wizard/step3/step3_registered_hosts_popup'),
  1173. message: Em.I18n.t('installer.step3.registeredHostsPopup'),
  1174. registeredHosts: self.get('registeredHosts')
  1175. })
  1176. })
  1177. }
  1178. });