step3_controller.js 38 KB

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