step3_controller.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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. hosts.push(host);
  1093. }, this);
  1094. for (var categoryId in warningCategories) {
  1095. var category = warningCategories[categoryId]
  1096. for (var warningId in category) {
  1097. warnings.push(category[warningId]);
  1098. }
  1099. }
  1100. warnings.forEach(function (warn) {
  1101. if (warn.hosts.length < 11) {
  1102. warn.hostsList = warn.hosts.join('<br>')
  1103. } else {
  1104. warn.hostsList = warn.hosts.slice(0, 10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  1105. }
  1106. });
  1107. hosts.unshift({
  1108. name: 'All Hosts',
  1109. warnings: warnings
  1110. });
  1111. this.set('warnings', warnings);
  1112. this.set('warningsByHost', hosts);
  1113. this.set('isWarningsLoaded', true);
  1114. },
  1115. /**
  1116. * Open popup that contain hosts' warnings
  1117. * @return {App.ModalPopup}
  1118. * @method hostWarningsPopup
  1119. */
  1120. hostWarningsPopup: function () {
  1121. var self = this;
  1122. return App.ModalPopup.show({
  1123. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  1124. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  1125. primary: Em.I18n.t('common.close'),
  1126. onPrimary: function () {
  1127. self.set('checksUpdateStatus', null);
  1128. this.hide();
  1129. },
  1130. onClose: function () {
  1131. self.set('checksUpdateStatus', null);
  1132. this.hide();
  1133. },
  1134. onSecondary: function () {
  1135. self.rerunChecks();
  1136. },
  1137. didInsertElement: function () {
  1138. this.fitHeight();
  1139. },
  1140. footerClass: App.WizardStep3HostWarningPopupFooter,
  1141. bodyClass: App.WizardStep3HostWarningPopupBody
  1142. });
  1143. },
  1144. /**
  1145. * Show popup with registered hosts
  1146. * @return {App.ModalPopup}
  1147. * @method registeredHostsPopup
  1148. */
  1149. registeredHostsPopup: function () {
  1150. var self = this;
  1151. return App.ModalPopup.show({
  1152. header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
  1153. secondary: null,
  1154. bodyClass: Em.View.extend({
  1155. templateName: require('templates/wizard/step3/step3_registered_hosts_popup'),
  1156. message: Em.I18n.t('installer.step3.registeredHostsPopup'),
  1157. registeredHosts: self.get('registeredHosts')
  1158. })
  1159. })
  1160. }
  1161. });