step3_controller.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  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. hostCheckWarnings: [],
  28. repoCategoryWarnings: [],
  29. diskCategoryWarnings: [],
  30. thpCategoryWarnings: [],
  31. jdkCategoryWarnings: null,
  32. jdkRequestIndex: null,
  33. registrationStartedAt: null,
  34. requestId: 0,
  35. /**
  36. * Timeout for registration
  37. * Based on <code>installOptions.manualInstall</code>
  38. * @type {number}
  39. */
  40. registrationTimeoutSecs: function () {
  41. return this.get('content.installOptions.manualInstall') ? 15 : 120;
  42. }.property('content.installOptions.manualInstall'),
  43. /**
  44. * Bootstrap calls are stopped
  45. * @type {bool}
  46. */
  47. stopBootstrap: false,
  48. /**
  49. * is Submit button disabled
  50. * @type {bool}
  51. */
  52. isSubmitDisabled: true,
  53. /**
  54. * is Retry button disabled
  55. * @type {bool}
  56. */
  57. isRetryDisabled: true,
  58. /**
  59. * @type {bool}
  60. */
  61. isLoaded: false,
  62. /**
  63. * Polls count
  64. * @type {number}
  65. */
  66. numPolls: 0,
  67. /**
  68. * Is hosts registration in progress
  69. * @type {bool}
  70. */
  71. isRegistrationInProgress: true,
  72. /**
  73. * Are some registered hosts which are not added by user
  74. * @type {bool}
  75. */
  76. hasMoreRegisteredHosts: false,
  77. /**
  78. * List of installed hostnames
  79. * @type {string[]}
  80. */
  81. hostsInCluster: function () {
  82. var installedHostsName = [];
  83. var hosts = this.get('content.hosts');
  84. for (var hostName in hosts) {
  85. if (hosts[hostName].isInstalled) {
  86. installedHostsName.push(hostName);
  87. }
  88. }
  89. return installedHostsName;
  90. }.property('content.hosts'),
  91. /**
  92. * All hosts warnings
  93. * @type {object[]}
  94. */
  95. warnings: [],
  96. /**
  97. * Warnings grouped by host
  98. * @type {Ember.Enumerable}
  99. */
  100. warningsByHost: [],
  101. /**
  102. * Timeout for "warning"-requests
  103. * @type {number}
  104. */
  105. warningsTimeInterval: 60000,
  106. /**
  107. * Are hosts warnings loaded
  108. * @type {bool}
  109. */
  110. isWarningsLoaded: function () {
  111. return this.get('isJDKWarningsLoaded') && this.get('isHostsWarningsLoaded');
  112. }.property('isJDKWarningsLoaded', 'isHostsWarningsLoaded'),
  113. /**
  114. * Check are hosts have any warnings
  115. * @type {bool}
  116. */
  117. isHostHaveWarnings: function () {
  118. return this.get('warnings.length') > 0;
  119. }.property('warnings'),
  120. /**
  121. * Should warnings-box be visible
  122. * @type {bool}
  123. */
  124. isWarningsBoxVisible: function () {
  125. return (App.get('testMode')) ? true : !this.get('isRegistrationInProgress');
  126. }.property('isRegistrationInProgress'),
  127. /**
  128. * Progress value for "update hosts status" process
  129. * @type {number}
  130. */
  131. checksUpdateProgress: 0,
  132. /**
  133. *
  134. * @type {object}
  135. */
  136. checksUpdateStatus: null,
  137. /**
  138. *
  139. * @method navigateStep
  140. */
  141. navigateStep: function () {
  142. if (this.get('isLoaded')) {
  143. if (!this.get('content.installOptions.manualInstall')) {
  144. if (!this.get('wizardController').getDBProperty('bootStatus')) {
  145. this.startBootstrap();
  146. }
  147. } else {
  148. this.set('bootHosts', this.get('hosts'));
  149. if (App.get('testMode')) {
  150. this.startHostcheck();
  151. this.get('bootHosts').setEach('cpu', '2');
  152. this.get('bootHosts').setEach('memory', '2000000');
  153. this.set('isSubmitDisabled', false);
  154. } else {
  155. this.set('registrationStartedAt', null);
  156. this.startRegistration();
  157. }
  158. }
  159. }
  160. }.observes('isLoaded'),
  161. /**
  162. * Clear controller data
  163. * @method clearStep
  164. */
  165. clearStep: function () {
  166. this.set('stopBootstrap', false);
  167. this.set('hosts', []);
  168. this.get('bootHosts').clear();
  169. this.get('wizardController').setDBProperty('bootStatus', false);
  170. this.set('isHostsWarningsLoaded', false);
  171. this.set('isJDKWarningsLoaded', false);
  172. this.set('registrationStartedAt', null);
  173. this.set('isLoaded', false);
  174. this.set('isSubmitDisabled', true);
  175. this.set('isRetryDisabled', true);
  176. },
  177. /**
  178. * Make basic init steps
  179. * @method loadStep
  180. */
  181. loadStep: function () {
  182. console.log("TRACE: Loading step3: Confirm Hosts");
  183. this.disablePreviousSteps();
  184. this.clearStep();
  185. App.router.get('clusterController').loadAmbariProperties();
  186. this.loadHosts();
  187. },
  188. /**
  189. * Loads the hostinfo from localStorage on the insertion of view. It's being called from view
  190. * @method loadHosts
  191. */
  192. loadHosts: function () {
  193. var hostsInfo = this.get('content.hosts');
  194. var hosts = [];
  195. var bootStatus = (this.get('content.installOptions.manualInstall')) ? 'DONE' : 'PENDING';
  196. if (App.get('testMode')) {
  197. bootStatus = 'REGISTERED';
  198. }
  199. for (var index in hostsInfo) {
  200. if (hostsInfo.hasOwnProperty(index) && !hostsInfo[index].isInstalled) {
  201. hosts.pushObject(App.HostInfo.create({
  202. name: hostsInfo[index].name,
  203. bootStatus: bootStatus,
  204. isChecked: false
  205. }));
  206. }
  207. }
  208. this.set('hosts', hosts);
  209. this.set('isLoaded', true);
  210. },
  211. /**
  212. * Parses and updates the content based on bootstrap API response.
  213. * @return {bool} true if polling should continue (some hosts are in "RUNNING" state); false otherwise
  214. * @method parseHostInfo
  215. */
  216. parseHostInfo: function (hostsStatusFromServer) {
  217. hostsStatusFromServer.forEach(function (_hostStatus) {
  218. var host = this.get('bootHosts').findProperty('name', _hostStatus.hostName);
  219. // check if hostname extracted from REST API data matches any hostname in content
  220. // also, make sure that bootStatus modified by isHostsRegistered call does not get overwritten
  221. // since these calls are being made in parallel
  222. if (host && !['REGISTERED', 'REGISTERING'].contains(host.get('bootStatus'))) {
  223. host.set('bootStatus', _hostStatus.status);
  224. host.set('bootLog', _hostStatus.log);
  225. }
  226. }, this);
  227. // if the data rendered by REST API has hosts in "RUNNING" state, polling will continue
  228. return this.get('bootHosts').length != 0 && this.get('bootHosts').someProperty('bootStatus', 'RUNNING');
  229. },
  230. /**
  231. * Remove list of hosts
  232. * @param {Ember.Enumerable} hosts
  233. * @return {App.ModalPopup}
  234. * @method removeHosts
  235. */
  236. removeHosts: function (hosts) {
  237. var self = this;
  238. return App.showConfirmationPopup(function () {
  239. App.router.send('removeHosts', hosts);
  240. self.hosts.removeObjects(hosts);
  241. if (!self.hosts.length) {
  242. self.set('isSubmitDisabled', true);
  243. }
  244. }, Em.I18n.t('installer.step3.hosts.remove.popup.body'));
  245. },
  246. /**
  247. * Removes a single element on the trash icon click. Called from View
  248. * @param {object} hostInfo
  249. * @method removeHost
  250. */
  251. removeHost: function (hostInfo) {
  252. this.removeHosts([hostInfo]);
  253. },
  254. /**
  255. * Remove selected hosts (click-handler)
  256. * @return App.ModalPopup
  257. * @method removeSelectedHosts
  258. */
  259. removeSelectedHosts: function () {
  260. var selectedHosts = this.get('hosts').filterProperty('isChecked', true);
  261. selectedHosts.forEach(function (_hostInfo) {
  262. console.log('Removing: ' + _hostInfo.name);
  263. });
  264. return this.removeHosts(selectedHosts);
  265. },
  266. /**
  267. * Show popup with the list of hosts which are selected
  268. * @return App.ModalPopup
  269. * @method selectedHostsPopup
  270. */
  271. selectedHostsPopup: function () {
  272. var selectedHosts = this.get('hosts').filterProperty('isChecked').mapProperty('name');
  273. return App.ModalPopup.show({
  274. header: Em.I18n.t('installer.step3.selectedHosts.popup.header'),
  275. secondary: null,
  276. bodyClass: Em.View.extend({
  277. templateName: require('templates/common/items_list_popup'),
  278. items: selectedHosts,
  279. insertedItems: [],
  280. didInsertElement: function () {
  281. lazyloading.run({
  282. destination: this.get('insertedItems'),
  283. source: this.get('items'),
  284. context: this,
  285. initSize: 100,
  286. chunkSize: 500,
  287. delay: 100
  288. });
  289. }
  290. })
  291. });
  292. },
  293. /**
  294. * Retry one host {click-handler}
  295. * @param {object} hostInfo
  296. * @method retryHost
  297. */
  298. retryHost: function (hostInfo) {
  299. this.retryHosts([hostInfo]);
  300. },
  301. /**
  302. * Retry list of hosts
  303. * @param {object[]} hosts
  304. * @method retryHosts
  305. */
  306. retryHosts: function (hosts) {
  307. var self = this;
  308. var bootStrapData = JSON.stringify({
  309. 'verbose': true,
  310. 'sshKey': this.get('content.installOptions.sshKey'),
  311. 'hosts': hosts.mapProperty('name'),
  312. 'user': this.get('content.installOptions.sshUser')}
  313. );
  314. this.set('numPolls', 0);
  315. this.set('registrationStartedAt', null);
  316. if (this.get('content.installOptions.manualInstall')) {
  317. this.get('bootHosts').setEach('bootStatus', 'DONE');
  318. this.startRegistration();
  319. }
  320. else {
  321. App.router.get(this.get('content.controllerName')).launchBootstrap(bootStrapData, function (requestId) {
  322. self.set('content.installOptions.bootRequestId', requestId);
  323. self.doBootstrap();
  324. });
  325. }
  326. },
  327. /**
  328. * Retry selected hosts (click-handler)
  329. * @method retrySelectedHosts
  330. */
  331. retrySelectedHosts: function () {
  332. if (!this.get('isRetryDisabled')) {
  333. this.set('isRetryDisabled', true);
  334. var selectedHosts = this.get('bootHosts').filterProperty('bootStatus', 'FAILED');
  335. selectedHosts.forEach(function (_host) {
  336. _host.set('bootStatus', 'RUNNING');
  337. _host.set('bootLog', 'Retrying ...');
  338. }, this);
  339. this.retryHosts(selectedHosts);
  340. }
  341. },
  342. /**
  343. * Init bootstrap settings and start it
  344. * @method startBootstrap
  345. */
  346. startBootstrap: function () {
  347. //this.set('isSubmitDisabled', true); //TODO: uncomment after actual hookup
  348. this.set('numPolls', 0);
  349. this.set('registrationStartedAt', null);
  350. this.set('bootHosts', this.get('hosts'));
  351. this.doBootstrap();
  352. },
  353. /**
  354. * Update <code>isRegistrationInProgress</code> once
  355. * @method setRegistrationInProgressOnce
  356. */
  357. setRegistrationInProgressOnce: function () {
  358. Em.run.once(this, 'setRegistrationInProgress');
  359. }.observes('bootHosts.@each.bootStatus'),
  360. /**
  361. * Set <code>isRegistrationInProgress</code> value based on each host boot status
  362. * @method setRegistrationInProgress
  363. */
  364. setRegistrationInProgress: function () {
  365. var bootHosts = this.get('bootHosts');
  366. //if hosts aren't loaded yet then registration should be in progress
  367. var result = (bootHosts.length === 0 && !this.get('isLoaded'));
  368. for (var i = 0, l = bootHosts.length; i < l; i++) {
  369. if (bootHosts[i].get('bootStatus') !== 'REGISTERED' && bootHosts[i].get('bootStatus') !== 'FAILED') {
  370. result = true;
  371. break;
  372. }
  373. }
  374. this.set('isRegistrationInProgress', result);
  375. },
  376. /**
  377. * Disable wizard's previous steps (while registering)
  378. * @method disablePreviousSteps
  379. */
  380. disablePreviousSteps: function () {
  381. App.router.get('installerController.isStepDisabled').filter(function (step) {
  382. return step.step >= 0 && step.step <= 2;
  383. }).setEach('value', this.get('isRegistrationInProgress'));
  384. if (this.get('isRegistrationInProgress')) {
  385. this.set('isSubmitDisabled', true);
  386. }
  387. }.observes('isRegistrationInProgress'),
  388. /**
  389. * Do bootstrap calls
  390. * @method doBootstrap
  391. * @return {$.ajax|null}
  392. */
  393. doBootstrap: function () {
  394. if (this.get('stopBootstrap')) {
  395. return null;
  396. }
  397. this.incrementProperty('numPolls');
  398. return App.ajax.send({
  399. name: 'wizard.step3.bootstrap',
  400. sender: this,
  401. data: {
  402. bootRequestId: this.get('content.installOptions.bootRequestId'),
  403. numPolls: this.get('numPolls')
  404. },
  405. success: 'doBootstrapSuccessCallback'
  406. }).
  407. retry({
  408. times: App.maxRetries,
  409. timeout: App.timeout
  410. }).
  411. then(
  412. null,
  413. function () {
  414. App.showReloadPopup();
  415. console.log('Bootstrap failed');
  416. }
  417. );
  418. },
  419. /**
  420. * Success-callback for each boostrap request
  421. * @param {object} data
  422. * @method doBootstrapSuccessCallback
  423. */
  424. doBootstrapSuccessCallback: function (data) {
  425. var self = this;
  426. var pollingInterval = 3000;
  427. if (Em.isNone(data.hostsStatus)) {
  428. console.log('Invalid response, setting timeout');
  429. window.setTimeout(function () {
  430. self.doBootstrap()
  431. }, pollingInterval);
  432. } else {
  433. // in case of bootstrapping just one host, the server returns an object rather than an array, so
  434. // force into an array
  435. if (!(data.hostsStatus instanceof Array)) {
  436. data.hostsStatus = [ data.hostsStatus ];
  437. }
  438. console.log("TRACE: In success function for the GET bootstrap call");
  439. var keepPolling = this.parseHostInfo(data.hostsStatus);
  440. // Single host : if the only hostname is invalid (data.status == 'ERROR')
  441. // Multiple hosts : if one or more hostnames are invalid
  442. // following check will mark the bootStatus as 'FAILED' for the invalid hostname
  443. if (data.status == 'ERROR' || data.hostsStatus.length != this.get('bootHosts').length) {
  444. var hosts = this.get('bootHosts');
  445. for (var i = 0; i < hosts.length; i++) {
  446. var isValidHost = data.hostsStatus.someProperty('hostName', hosts[i].get('name'));
  447. if (hosts[i].get('bootStatus') !== 'REGISTERED') {
  448. if (!isValidHost) {
  449. hosts[i].set('bootStatus', 'FAILED');
  450. hosts[i].set('bootLog', Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  451. }
  452. }
  453. }
  454. }
  455. if (data.status == 'ERROR' || data.hostsStatus.someProperty('status', 'DONE') || data.hostsStatus.someProperty('status', 'FAILED')) {
  456. // kicking off registration polls after at least one host has succeeded
  457. this.startRegistration();
  458. }
  459. if (keepPolling) {
  460. window.setTimeout(function () {
  461. self.doBootstrap()
  462. }, pollingInterval);
  463. }
  464. }
  465. },
  466. /**
  467. * Start hosts registration
  468. * @method startRegistration
  469. */
  470. startRegistration: function () {
  471. if (Em.isNone(this.get('registrationStartedAt'))) {
  472. this.set('registrationStartedAt', App.dateTime());
  473. console.log('registration started at ' + this.get('registrationStartedAt'));
  474. this.isHostsRegistered();
  475. }
  476. },
  477. /**
  478. * Do requests to check if hosts are already registered
  479. * @return {$.ajax|null}
  480. * @method isHostsRegistered
  481. */
  482. isHostsRegistered: function () {
  483. if (this.get('stopBootstrap')) {
  484. return null;
  485. }
  486. return App.ajax.send({
  487. name: 'wizard.step3.is_hosts_registered',
  488. sender: this,
  489. success: 'isHostsRegisteredSuccessCallback'
  490. }).
  491. retry({
  492. times: App.maxRetries,
  493. timeout: App.timeout
  494. }).
  495. then(
  496. null,
  497. function () {
  498. App.showReloadPopup();
  499. console.log('Error: Getting registered host information from the server');
  500. }
  501. );
  502. },
  503. /**
  504. * Success-callback for registered hosts request
  505. * @param {object} data
  506. * @method isHostsRegisteredSuccessCallback
  507. */
  508. isHostsRegisteredSuccessCallback: function (data) {
  509. console.log('registration attempt...');
  510. var hosts = this.get('bootHosts');
  511. var jsonData = data;
  512. if (!jsonData) {
  513. console.warn("Error: jsonData is null");
  514. return;
  515. }
  516. // keep polling until all hosts have registered/failed, or registrationTimeout seconds after the last host finished bootstrapping
  517. var stopPolling = true;
  518. hosts.forEach(function (_host, index) {
  519. // Change name of first host for test mode.
  520. if (App.get('testMode')) {
  521. if (index == 0) {
  522. _host.set('name', 'localhost.localdomain');
  523. }
  524. }
  525. // actions to take depending on the host's current bootStatus
  526. // RUNNING - bootstrap is running; leave it alone
  527. // DONE - bootstrap is done; transition to REGISTERING
  528. // REGISTERING - bootstrap is done but has not registered; transition to REGISTERED if host found in polling API result
  529. // REGISTERED - bootstrap and registration is done; leave it alone
  530. // FAILED - either bootstrap or registration failed; leave it alone
  531. switch (_host.get('bootStatus')) {
  532. case 'DONE':
  533. _host.set('bootStatus', 'REGISTERING');
  534. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  535. // update registration timestamp so that the timeout is computed from the last host that finished bootstrapping
  536. this.set('registrationStartedAt', App.dateTime());
  537. stopPolling = false;
  538. break;
  539. case 'REGISTERING':
  540. if (jsonData.items.someProperty('Hosts.host_name', _host.name)) {
  541. _host.set('bootStatus', 'REGISTERED');
  542. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  543. } else {
  544. stopPolling = false;
  545. }
  546. break;
  547. case 'RUNNING':
  548. stopPolling = false;
  549. break;
  550. case 'REGISTERED':
  551. case 'FAILED':
  552. default:
  553. break;
  554. }
  555. }, this);
  556. if (stopPolling) {
  557. this.startHostcheck();
  558. }
  559. else {
  560. if (hosts.someProperty('bootStatus', 'RUNNING') || App.dateTime() - this.get('registrationStartedAt') < this.get('registrationTimeoutSecs') * 1000) {
  561. // we want to keep polling for registration status if any of the hosts are still bootstrapping (so we check for RUNNING).
  562. var self = this;
  563. window.setTimeout(function () {
  564. self.isHostsRegistered();
  565. }, 3000);
  566. }
  567. else {
  568. // registration timed out. mark all REGISTERING hosts to FAILED
  569. console.log('registration timed out');
  570. hosts.filterProperty('bootStatus', 'REGISTERING').forEach(function (_host) {
  571. _host.set('bootStatus', 'FAILED');
  572. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  573. });
  574. this.startHostcheck();
  575. }
  576. }
  577. },
  578. /**
  579. * Do request for all registered hosts
  580. * @return {$.ajax}
  581. * @method getAllRegisteredHosts
  582. */
  583. getAllRegisteredHosts: function () {
  584. return App.ajax.send({
  585. name: 'wizard.step3.is_hosts_registered',
  586. sender: this,
  587. success: 'getAllRegisteredHostsCallback'
  588. });
  589. }.observes('bootHosts'),
  590. /**
  591. * Success-callback for all registered hosts request
  592. * @param {object} hosts
  593. * @method getAllRegisteredHostsCallback
  594. */
  595. getAllRegisteredHostsCallback: function (hosts) {
  596. var registeredHosts = [];
  597. var hostsInCluster = this.get('hostsInCluster');
  598. var addedHosts = this.get('bootHosts').getEach('name');
  599. hosts.items.forEach(function (host) {
  600. if (!hostsInCluster.contains(host.Hosts.host_name) && !addedHosts.contains(host.Hosts.host_name)) {
  601. registeredHosts.push(host.Hosts.host_name);
  602. }
  603. });
  604. if (registeredHosts.length) {
  605. this.set('hasMoreRegisteredHosts', true);
  606. this.set('registeredHosts', registeredHosts);
  607. } else {
  608. this.set('hasMoreRegisteredHosts', false);
  609. this.set('registeredHosts', '');
  610. }
  611. },
  612. /**
  613. * Show popup with regitration error-message
  614. * @param {string} header
  615. * @param {string} message
  616. * @return {App.ModalPopup}
  617. * @method registerErrPopup
  618. */
  619. registerErrPopup: function (header, message) {
  620. return App.ModalPopup.show({
  621. header: header,
  622. secondary: false,
  623. bodyClass: Em.View.extend({
  624. template: Em.Handlebars.compile('<p>{{view.message}}</p>'),
  625. message: message
  626. })
  627. });
  628. },
  629. /**
  630. * Get JDK name from server to determine if user had setup a customized JDK path when doing 'ambari-server setup'.
  631. * The Ambari properties are different from default ambari-server setup, property 'jdk.name' will be missing if a customized jdk path is applied.
  632. * @return {$.ajax}
  633. * @method getJDKName
  634. */
  635. getJDKName: function () {
  636. return App.ajax.send({
  637. name: 'ambari.service.load_jdk_name',
  638. sender: this,
  639. success: 'getJDKNameSuccessCallback'
  640. });
  641. },
  642. /**
  643. * Success callback for JDK name, property 'jdk.name' will be missing if a customized jdk path is applied
  644. * @param {object} data
  645. * @method getJDKNameSuccessCallback
  646. */
  647. getJDKNameSuccessCallback: function (data) {
  648. this.set('needJDKCheckOnHosts', !data.RootServiceComponents.properties["jdk.name"]);
  649. this.set('jdkLocation', Em.get(data, "RootServiceComponents.properties.jdk_location"));
  650. this.set('javaHome', data.RootServiceComponents.properties["java.home"]);
  651. },
  652. doCheckJDK: function () {
  653. var hostsNames = this.get('bootHosts').getEach('name').join(",");
  654. var javaHome = this.get('javaHome');
  655. var jdkLocation = this.get('jdkLocation');
  656. App.ajax.send({
  657. name: 'wizard.step3.jdk_check',
  658. sender: this,
  659. data: {
  660. host_names: hostsNames,
  661. java_home: javaHome,
  662. jdk_location: jdkLocation
  663. },
  664. success: 'doCheckJDKsuccessCallback',
  665. error: 'doCheckJDKerrorCallback'
  666. });
  667. },
  668. doCheckJDKsuccessCallback: function (data) {
  669. if(data){
  670. this.set('jdkRequestIndex', data.href.split('/')[data.href.split('/').length - 1]);
  671. }
  672. if (this.get('jdkCategoryWarnings') == null) {
  673. // get jdk check results for all hosts
  674. App.ajax.send({
  675. name: 'wizard.step3.jdk_check.get_results',
  676. sender: this,
  677. data: {
  678. requestIndex: this.get('jdkRequestIndex')
  679. },
  680. success: 'parseJDKCheckResults'
  681. })
  682. } else {
  683. this.set('isJDKWarningsLoaded', true);
  684. }
  685. },
  686. doCheckJDKerrorCallback: function () {
  687. console.log('INFO: Doing JDK check for host failed');
  688. this.set('isJDKWarningsLoaded', true);
  689. },
  690. parseJDKCheckResults: function (data) {
  691. var jdkWarnings = [], hostsJDKContext = [], hostsJDKNames = [];
  692. // check if the request ended
  693. if (data.Requests.end_time > 0 && data.tasks) {
  694. data.tasks.forEach( function(task) {
  695. // generate warning context
  696. if (Em.get(task, "Tasks.structured_out.java_home_check.exit_code") == 1){
  697. var jdkContext = Em.I18n.t('installer.step3.hostWarningsPopup.jdk.context').format(task.Tasks.host_name);
  698. hostsJDKContext.push(jdkContext);
  699. hostsJDKNames.push(task.Tasks.host_name);
  700. }
  701. });
  702. if (hostsJDKContext.length > 0) { // java jdk warning exist
  703. var invalidJavaHome = this.get('javaHome');
  704. jdkWarnings.push({
  705. name: Em.I18n.t('installer.step3.hostWarningsPopup.jdk.name').format(invalidJavaHome),
  706. hosts: hostsJDKContext,
  707. hostsNames: hostsJDKNames,
  708. category: 'jdk',
  709. onSingleHost: false
  710. });
  711. }
  712. this.set('jdkCategoryWarnings', jdkWarnings);
  713. } else {
  714. // still doing JDK check, data not ready to be parsed
  715. this.set('jdkCategoryWarnings', null);
  716. }
  717. this.doCheckJDKsuccessCallback();
  718. },
  719. /**
  720. * Check JDK issues on registered hosts.
  721. */
  722. checkHostJDK: function () {
  723. this.set('isJDKWarningsLoaded', false);
  724. this.set('jdkCategoryWarnings', null);
  725. var self = this;
  726. this.getJDKName().done( function() {
  727. if (self.get('needJDKCheckOnHosts')) {
  728. // need to do JDK check on each host
  729. self.doCheckJDK();
  730. } else {
  731. // no customized JDK path, so no need to check jdk
  732. self.set('jdkCategoryWarnings', []);
  733. self.set('isJDKWarningsLoaded', true);
  734. }
  735. });
  736. },
  737. /**
  738. * Get disk info and cpu count of booted hosts from server
  739. * @return {$.ajax}
  740. * @method getHostInfo
  741. */
  742. getHostInfo: function () {
  743. this.set('isHostsWarningsLoaded', false);
  744. // begin JDK check for each host
  745. return App.ajax.send({
  746. name: 'wizard.step3.host_info',
  747. sender: this,
  748. success: 'getHostInfoSuccessCallback',
  749. error: 'getHostInfoErrorCallback'
  750. });
  751. },
  752. startHostcheck: function() {
  753. this.set('isWarningsLoaded', false);
  754. this.getHostNameResolution();
  755. this.checkHostJDK();
  756. },
  757. getHostNameResolution: function () {
  758. var hosts = this.get('bootHosts').getEach('name').join(",");
  759. var jdk_location = App.router.get('clusterController.ambariProperties.jdk_location');
  760. var RequestInfo = {
  761. "action": "check_host",
  762. "context": "Check host",
  763. "parameters": {
  764. "check_execute_list": "host_resolution_check",
  765. "jdk_location" : jdk_location,
  766. "threshold": "20",
  767. "hosts": hosts
  768. }
  769. };
  770. var resource_filters = {
  771. "hosts": hosts
  772. };
  773. if (App.get('testMode')) {
  774. this.getHostNameResolutionSuccess();
  775. } else {
  776. return App.ajax.send({
  777. name: 'preinstalled.checks',
  778. sender: this,
  779. data: {
  780. RequestInfo: RequestInfo,
  781. resource_filters: resource_filters
  782. },
  783. success: 'getHostNameResolutionSuccess',
  784. error: 'getHostNameResolutionError'
  785. });
  786. }
  787. },
  788. getHostNameResolutionSuccess: function(response) {
  789. if (!App.get('testMode')) {
  790. this.set("requestId", response.Requests.id);
  791. }
  792. this.getHostCheckTasks();
  793. },
  794. getHostNameResolutionError: function() {
  795. this.getHostInfo();
  796. },
  797. /**
  798. * send ajax request to get all tasks
  799. * @method getHostCheckTasks
  800. */
  801. getHostCheckTasks: function () {
  802. var self = this;
  803. var requestId = this.get("requestId");
  804. var checker = setTimeout(function () {
  805. if (self.get('stopChecking') == true) {
  806. clearInterval(checker);
  807. self.getHostInfo();
  808. } else {
  809. App.ajax.send({
  810. name: 'preinstalled.checks.tasks',
  811. sender: self,
  812. data: {
  813. requestId: requestId
  814. },
  815. success: 'getHostCheckTasksSuccess',
  816. error: 'getHostCheckTasksError'
  817. });
  818. }
  819. }, 1000);
  820. },
  821. /**
  822. * add warnings to host warning popup if needed
  823. * @param data {Object} - json
  824. * @method getHostCheckTasksSuccess
  825. */
  826. getHostCheckTasksSuccess: function (data) {
  827. console.log('checking attempt...');
  828. if (!data) {
  829. console.warn("Error: jsonData is null");
  830. return;
  831. }
  832. this.set('stopChecking', true);
  833. data.tasks.forEach(function (task) {
  834. var name = Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.error');
  835. var hostInfo = this.get("hostCheckWarnings").findProperty('name', name);
  836. if (task.Tasks.status == "FAILED" || task.Tasks.status == "COMPLETED" || task.Tasks.status == "TIMEDOUT") {
  837. if (task.Tasks.status == "COMPLETED") {
  838. if (Em.get(task, "Tasks.structured_out.host_resolution_check.failed_count") == 0) {
  839. return;
  840. }
  841. }
  842. var targetHostName = Em.get(task, "Tasks.host_name");
  843. var relatedHostNames = Em.get(task, "Tasks.structured_out.host_resolution_check.failures") ? Em.get(task, "Tasks.structured_out.host_resolution_check.failures").mapProperty('host') : [];
  844. var contextMessage = Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format(targetHostName, relatedHostNames.join(', '));
  845. if (!hostInfo) {
  846. hostInfo = {
  847. name: name,
  848. hosts: [contextMessage],
  849. hostsNames: [targetHostName],
  850. onSingleHost: true
  851. };
  852. this.get("hostCheckWarnings").push(hostInfo);
  853. } else {
  854. if (!hostInfo.hostsNames.contains(targetHostName)) {
  855. hostInfo.hosts.push(contextMessage);
  856. hostInfo.hostsNames.push(targetHostName);
  857. }
  858. }
  859. } else {
  860. this.set('stopChecking', false);
  861. }
  862. }, this);
  863. this.getHostCheckTasks();
  864. },
  865. stopChecking: false,
  866. /**
  867. * @method getHostCheckTasksError
  868. */
  869. getHostCheckTasksError: function() {
  870. console.warn("failed to cheek hostName resolution");
  871. this.set('stopChecking', true);
  872. },
  873. /**
  874. * Success-callback for hosts info request
  875. * @param {object} jsonData
  876. * @method getHostInfoSuccessCallback
  877. */
  878. getHostInfoSuccessCallback: function (jsonData) {
  879. var hosts = this.get('bootHosts'),
  880. self = this,
  881. repoWarnings = [], hostsRepoNames = [], hostsContext = [],
  882. diskWarnings = [], hostsDiskContext = [], hostsDiskNames = [],
  883. thpWarnings = [], thpContext = [], thpHostsNames = [];
  884. // parse host checks warning
  885. this.parseWarnings(jsonData);
  886. hosts.forEach(function (_host) {
  887. var host = (App.get('testMode')) ? jsonData.items[0] : jsonData.items.findProperty('Hosts.host_name', _host.name);
  888. if (App.get('skipBootstrap')) {
  889. self._setHostDataWithSkipBootstrap(_host);
  890. }
  891. else {
  892. if (host) {
  893. self._setHostDataFromLoadedHostInfo(_host, host);
  894. var host_name = Em.get(host, 'Hosts.host_name');
  895. var context = self.checkHostOSType(host.Hosts.os_type, host_name);
  896. if (context) {
  897. hostsContext.push(context);
  898. hostsRepoNames.push(host_name);
  899. }
  900. var diskContext = self.checkHostDiskSpace(host_name, host.Hosts.disk_info);
  901. if (diskContext) {
  902. hostsDiskContext.push(diskContext);
  903. hostsDiskNames.push(host_name);
  904. }
  905. // "Transparent Huge Pages" check
  906. context = self.checkTHP(host_name, Em.get(host, 'Hosts.last_agent_env.transparentHugePage'));
  907. if (context) {
  908. thpContext.push(context);
  909. thpHostsNames.push(host_name);
  910. }
  911. }
  912. }
  913. });
  914. if (hostsContext.length > 0) { // repository warning exist
  915. repoWarnings.push({
  916. name: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.name'),
  917. hosts: hostsContext,
  918. hostsNames: hostsRepoNames,
  919. category: 'repositories',
  920. onSingleHost: false
  921. });
  922. }
  923. if (hostsDiskContext.length > 0) { // disk space warning exist
  924. diskWarnings.push({
  925. name: Em.I18n.t('installer.step3.hostWarningsPopup.disk.name'),
  926. hosts: hostsDiskContext,
  927. hostsNames: hostsDiskNames,
  928. category: 'disk',
  929. onSingleHost: false
  930. });
  931. }
  932. if (thpContext.length > 0) { // THP warning existed
  933. thpWarnings.push({
  934. name: Em.I18n.t('installer.step3.hostWarningsPopup.thp.name'),
  935. hosts: thpContext,
  936. hostsNames: thpHostsNames,
  937. category: 'thp',
  938. onSingleHost: false
  939. });
  940. }
  941. this.set('repoCategoryWarnings', repoWarnings);
  942. this.set('diskCategoryWarnings', diskWarnings);
  943. this.set('thpCategoryWarnings', thpWarnings);
  944. this.stopRegistration();
  945. },
  946. /**
  947. * Set metrics to host object
  948. * Used when <code>App.skipBootstrap</code> is true
  949. * @param {Ember.Object} host
  950. * @returns {object}
  951. * @private
  952. * @methos _setHostDataWithSkipBootstrap
  953. */
  954. _setHostDataWithSkipBootstrap: function(host) {
  955. host.set('cpu', 2);
  956. host.set('memory', ((parseInt(2000000))).toFixed(2));
  957. host.set('disk_info', [
  958. {"mountpoint": "/", "type": "ext4"},
  959. {"mountpoint": "/grid/0", "type": "ext4"},
  960. {"mountpoint": "/grid/1", "type": "ext4"},
  961. {"mountpoint": "/grid/2", "type": "ext4"}
  962. ]);
  963. return host;
  964. },
  965. /**
  966. * Set loaded metrics to host object
  967. * @param {object} host
  968. * @param {object} hostInfo
  969. * @returns {object}
  970. * @method _setHostDataFromLoadedHostInfo
  971. * @private
  972. */
  973. _setHostDataFromLoadedHostInfo: function(host, hostInfo) {
  974. host.set('cpu', Em.get(hostInfo, 'Hosts.cpu_count'));
  975. host.set('memory', ((parseInt(Em.get(hostInfo, 'Hosts.total_mem')))).toFixed(2));
  976. host.set('disk_info', Em.get(hostInfo, 'Hosts.disk_info').filter(function (h) {
  977. return h.mountpoint != "/boot"
  978. }));
  979. host.set('os_type', Em.get(hostInfo, 'Hosts.os_type'));
  980. host.set('os_arch', Em.get(hostInfo, 'Hosts.os_arch'));
  981. host.set('ip', Em.get(hostInfo, 'Hosts.ip'));
  982. return host;
  983. },
  984. /**
  985. * Error-callback for hosts info request
  986. * @method getHostInfoErrorCallback
  987. */
  988. getHostInfoErrorCallback: function () {
  989. console.log('INFO: Getting host information(cpu_count and total_mem) from the server failed');
  990. this.set('isHostsWarningsLoaded', true);
  991. this.registerErrPopup(Em.I18n.t('installer.step3.hostInformation.popup.header'), Em.I18n.t('installer.step3.hostInformation.popup.body'));
  992. },
  993. /**
  994. * Enable or disable submit/retry buttons according to hosts boot statuses
  995. * @method stopRegistration
  996. */
  997. stopRegistration: function () {
  998. this.set('isSubmitDisabled', !this.get('bootHosts').someProperty('bootStatus', 'REGISTERED'));
  999. this.set('isRetryDisabled', !this.get('bootHosts').someProperty('bootStatus', 'FAILED'));
  1000. },
  1001. /**
  1002. * Check if the 'Transparent Huge Pages' enabled.
  1003. * @param {string} transparentHugePage
  1004. * @param {string} hostName
  1005. * @return {string} error-message or empty string
  1006. * @method checkTHP
  1007. */
  1008. checkTHP: function (hostName, transparentHugePage) {
  1009. if (transparentHugePage == "always") {
  1010. console.log('WARNING: Transparent Huge Page enabled on host: '+ hostName);
  1011. return Em.I18n.t('installer.step3.hostWarningsPopup.thp.context').format(hostName);
  1012. } else {
  1013. return '';
  1014. }
  1015. },
  1016. /**
  1017. * Check if the customized os group contains the registered host os type. If not the repo on that host is invalid.
  1018. * @param {string} osType
  1019. * @param {string} hostName
  1020. * @return {string} error-message or empty string
  1021. * @method checkHostOSType
  1022. */
  1023. checkHostOSType: function (osType, hostName) {
  1024. if (this.get('content.stacks')) {
  1025. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  1026. var selectedOS = [];
  1027. var self = this;
  1028. var isValid = false;
  1029. if (selectedStack && selectedStack.get('operatingSystems')) {
  1030. selectedStack.get('operatingSystems').filterProperty('isSelected', true).forEach(function (os) {
  1031. selectedOS.pushObject(os.get('osType'));
  1032. if (self.repoToAgentOsType(os.get('osType')).indexOf(osType) >= 0) {
  1033. isValid = true;
  1034. }
  1035. });
  1036. }
  1037. if (isValid) {
  1038. return '';
  1039. } else {
  1040. console.log('WARNING: Getting host os type does NOT match the user selected os group in step1. ' +
  1041. 'Host Name: ' + hostName + '. Host os type:' + osType + '. Selected group:' + selectedOS.uniq());
  1042. return Em.I18n.t('installer.step3.hostWarningsPopup.repositories.context').format(hostName, osType, selectedOS.uniq());
  1043. }
  1044. } else {
  1045. return '';
  1046. }
  1047. },
  1048. /**
  1049. * return the supported agent os types for a repo os type
  1050. * @param {String} repoType
  1051. * @return {Array} supported agent os type array
  1052. * @method repoToAgentOsType
  1053. */
  1054. repoToAgentOsType : function (repoType) {
  1055. /* istanbul ignore next */
  1056. switch (repoType) {
  1057. case "redhat6":
  1058. return ["redhat6", "centos6", "oraclelinux6", "rhel6"];
  1059. case "redhat5":
  1060. return ["redhat5", "centos5", "oraclelinux5", "rhel5"];
  1061. case "suse11":
  1062. return ["suse11", "sles11", "opensuse11"];
  1063. case "ubuntu12":
  1064. return ["debian12", "ubuntu12"];
  1065. default:
  1066. return [];
  1067. }
  1068. },
  1069. /**
  1070. * Check if current host has enough free disk usage.
  1071. * @param {string} hostName
  1072. * @param {object} diskInfo
  1073. * @return {string} error-message or empty string
  1074. * @method checkHostDiskSpace
  1075. */
  1076. checkHostDiskSpace: function (hostName, diskInfo) {
  1077. var minFreeRootSpace = App.minDiskSpace * 1024 * 1024; //in kilobyte
  1078. var minFreeUsrLibSpace = App.minDiskSpaceUsrLib * 1024 * 1024; //in kilobyte
  1079. var warningString = '';
  1080. diskInfo.forEach(function (info) {
  1081. switch (info.mountpoint) {
  1082. case '/':
  1083. warningString = info.available < minFreeRootSpace ?
  1084. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpace + 'GB', info.mountpoint) + ' ' + warningString :
  1085. warningString;
  1086. break;
  1087. case '/usr':
  1088. case '/usr/lib':
  1089. warningString = info.available < minFreeUsrLibSpace ?
  1090. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpaceUsrLib + 'GB', info.mountpoint) + ' ' + warningString :
  1091. warningString;
  1092. break;
  1093. default:
  1094. break;
  1095. }
  1096. });
  1097. if (warningString) {
  1098. console.log('WARNING: Getting host free disk space. ' + 'Host Name: ' + hostName);
  1099. return Em.I18n.t('installer.step3.hostWarningsPopup.disk.context1').format(hostName) + ' ' + warningString;
  1100. } else {
  1101. return '';
  1102. }
  1103. },
  1104. /**
  1105. * Submit-click handler
  1106. * @return {App.ModalPopup|null}
  1107. * @method submit
  1108. */
  1109. submit: function () {
  1110. var self = this;
  1111. if (this.get('isHostHaveWarnings')) {
  1112. return App.showConfirmationPopup(
  1113. function () {
  1114. self.set('confirmedHosts', self.get('bootHosts'));
  1115. App.router.send('next');
  1116. },
  1117. Em.I18n.t('installer.step3.hostWarningsPopup.hostHasWarnings'));
  1118. }
  1119. else {
  1120. this.set('confirmedHosts', this.get('bootHosts'));
  1121. App.router.send('next');
  1122. }
  1123. return null;
  1124. },
  1125. /**
  1126. * Show popup with host log
  1127. * @param {object} event
  1128. * @return {App.ModalPopup}
  1129. */
  1130. hostLogPopup: function (event) {
  1131. var host = event.context;
  1132. return App.ModalPopup.show({
  1133. header: Em.I18n.t('installer.step3.hostLog.popup.header').format(host.get('name')),
  1134. secondary: null,
  1135. host: host,
  1136. bodyClass: App.WizardStep3HostLogPopupBody
  1137. });
  1138. },
  1139. /**
  1140. * Check warnings from server and put it in parsing
  1141. * @method rerunChecks
  1142. */
  1143. rerunChecks: function () {
  1144. var self = this;
  1145. var currentProgress = 0;
  1146. this.getHostNameResolution();
  1147. this.checkHostJDK();
  1148. var interval = setInterval(function () {
  1149. currentProgress += 100000 / self.get('warningsTimeInterval');
  1150. if (currentProgress < 100) {
  1151. self.set('checksUpdateProgress', currentProgress);
  1152. } else {
  1153. clearInterval(interval);
  1154. App.ajax.send({
  1155. name: 'wizard.step3.rerun_checks',
  1156. sender: self,
  1157. success: 'rerunChecksSuccessCallback',
  1158. error: 'rerunChecksErrorCallback'
  1159. });
  1160. }
  1161. }, 1000);
  1162. },
  1163. /**
  1164. * Success-callback for rerun request
  1165. * @param {object} data
  1166. * @method rerunChecksSuccessCallback
  1167. */
  1168. rerunChecksSuccessCallback: function (data) {
  1169. this.set('checksUpdateProgress', 100);
  1170. this.set('checksUpdateStatus', 'SUCCESS');
  1171. this.parseWarnings(data);
  1172. },
  1173. /**
  1174. * Error-callback for rerun request
  1175. * @method rerunChecksErrorCallback
  1176. */
  1177. rerunChecksErrorCallback: function () {
  1178. this.set('checksUpdateProgress', 100);
  1179. this.set('checksUpdateStatus', 'FAILED');
  1180. console.log('INFO: Getting host information(last_agent_env) from the server failed');
  1181. },
  1182. /**
  1183. * Filter data for warnings parse
  1184. * is data from host in bootStrap
  1185. * @param {object} data
  1186. * @return {Object}
  1187. * @method filterBootHosts
  1188. */
  1189. filterBootHosts: function (data) {
  1190. var bootHostNames = {};
  1191. this.get('bootHosts').forEach(function (bootHost) {
  1192. bootHostNames[bootHost.get('name')] = true;
  1193. });
  1194. var filteredData = {
  1195. href: data.href,
  1196. items: []
  1197. };
  1198. data.items.forEach(function (host) {
  1199. if (bootHostNames[host.Hosts.host_name]) {
  1200. filteredData.items.push(host);
  1201. }
  1202. });
  1203. return filteredData;
  1204. },
  1205. /**
  1206. * Parse warnings data for each host and total
  1207. * @param {object} data
  1208. * @method parseWarnings
  1209. */
  1210. parseWarnings: function (data) {
  1211. data = App.get('testMode') ? data : this.filterBootHosts(data);
  1212. var warnings = [];
  1213. var warning;
  1214. var hosts = [];
  1215. var warningCategories = {
  1216. fileFoldersWarnings: {},
  1217. packagesWarnings: {},
  1218. processesWarnings: {},
  1219. servicesWarnings: {},
  1220. usersWarnings: {},
  1221. alternativeWarnings: {}
  1222. };
  1223. data.items.sortPropertyLight('Hosts.host_name').forEach(function (_host) {
  1224. var host = {
  1225. name: _host.Hosts.host_name,
  1226. warnings: []
  1227. };
  1228. if (!_host.Hosts.last_agent_env) {
  1229. // in some unusual circumstances when last_agent_env is not available from the _host,
  1230. // skip the _host and proceed to process the rest of the hosts.
  1231. console.log("last_agent_env is missing for " + _host.Hosts.host_name + ". Skipping _host check.");
  1232. return;
  1233. }
  1234. //parse all directories and files warnings for host
  1235. //todo: to be removed after check in new API
  1236. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || [];
  1237. stackFoldersAndFiles.forEach(function (path) {
  1238. warning = warningCategories.fileFoldersWarnings[path.name];
  1239. if (warning) {
  1240. warning.hosts.push(_host.Hosts.host_name);
  1241. warning.onSingleHost = false;
  1242. } else {
  1243. warningCategories.fileFoldersWarnings[path.name] = warning = {
  1244. name: path.name,
  1245. hosts: [_host.Hosts.host_name],
  1246. category: 'fileFolders',
  1247. onSingleHost: true
  1248. };
  1249. }
  1250. host.warnings.push(warning);
  1251. }, this);
  1252. //parse all package warnings for host
  1253. if (_host.Hosts.last_agent_env.installedPackages) {
  1254. _host.Hosts.last_agent_env.installedPackages.forEach(function (_package) {
  1255. warning = warningCategories.packagesWarnings[_package.name];
  1256. if (warning) {
  1257. warning.hosts.push(_host.Hosts.host_name);
  1258. warning.version = _package.version;
  1259. warning.onSingleHost = false;
  1260. } else {
  1261. warningCategories.packagesWarnings[_package.name] = warning = {
  1262. name: _package.name,
  1263. version: _package.version,
  1264. hosts: [_host.Hosts.host_name],
  1265. category: 'packages',
  1266. onSingleHost: true
  1267. };
  1268. }
  1269. host.warnings.push(warning);
  1270. }, this);
  1271. }
  1272. //parse all process warnings for host
  1273. //todo: to be removed after check in new API
  1274. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  1275. if (javaProcs) {
  1276. javaProcs.forEach(function (process) {
  1277. warning = warningCategories.processesWarnings[process.pid];
  1278. if (warning) {
  1279. warning.hosts.push(_host.Hosts.host_name);
  1280. warning.onSingleHost = false;
  1281. } else {
  1282. warningCategories.processesWarnings[process.pid] = warning = {
  1283. name: (process.command.substr(0, 35) + '...'),
  1284. hosts: [_host.Hosts.host_name],
  1285. category: 'processes',
  1286. user: process.user,
  1287. pid: process.pid,
  1288. command: '<table><tr><td style="word-break: break-all;">' +
  1289. ((process.command.length < 500) ? process.command : process.command.substr(0, 230) + '...' +
  1290. '<p style="text-align: center">................</p>' +
  1291. '...' + process.command.substr(-230)) + '</td></tr></table>',
  1292. onSingleHost: true
  1293. };
  1294. }
  1295. host.warnings.push(warning);
  1296. }, this);
  1297. }
  1298. //parse all service warnings for host
  1299. //todo: to be removed after check in new API
  1300. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  1301. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  1302. if (service.status === 'Unhealthy') {
  1303. warning = warningCategories.servicesWarnings[service.name];
  1304. if (warning) {
  1305. warning.hosts.push(_host.Hosts.host_name);
  1306. warning.onSingleHost = false;
  1307. } else {
  1308. warningCategories.servicesWarnings[service.name] = warning = {
  1309. name: service.name,
  1310. hosts: [_host.Hosts.host_name],
  1311. category: 'services',
  1312. onSingleHost: true
  1313. };
  1314. }
  1315. host.warnings.push(warning);
  1316. }
  1317. }, this);
  1318. }
  1319. //parse all user warnings for host
  1320. //todo: to be removed after check in new API
  1321. if (_host.Hosts.last_agent_env.existingUsers) {
  1322. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  1323. warning = warningCategories.usersWarnings[user.userName];
  1324. if (warning) {
  1325. warning.hosts.push(_host.Hosts.host_name);
  1326. warning.onSingleHost = false;
  1327. } else {
  1328. warningCategories.usersWarnings[user.userName] = warning = {
  1329. name: user.userName,
  1330. hosts: [_host.Hosts.host_name],
  1331. category: 'users',
  1332. onSingleHost: true
  1333. };
  1334. }
  1335. host.warnings.push(warning);
  1336. }, this);
  1337. }
  1338. //parse misc warnings for host
  1339. var umask = _host.Hosts.last_agent_env.umask;
  1340. if (umask && umask !== 18) {
  1341. warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
  1342. if (warning) {
  1343. warning.hosts.push(_host.Hosts.host_name);
  1344. warning.onSingleHost = false;
  1345. } else {
  1346. warning = {
  1347. name: umask,
  1348. hosts: [_host.Hosts.host_name],
  1349. category: 'misc',
  1350. onSingleHost: true
  1351. };
  1352. warnings.push(warning);
  1353. }
  1354. host.warnings.push(warning);
  1355. }
  1356. var firewallRunning = _host.Hosts.last_agent_env.iptablesIsRunning;
  1357. if (firewallRunning !== null && firewallRunning) {
  1358. var name = Em.I18n.t('installer.step3.hostWarningsPopup.firewall.name');
  1359. warning = warnings.filterProperty('category', 'firewall').findProperty('name', name);
  1360. if (warning) {
  1361. warning.hosts.push(_host.Hosts.host_name);
  1362. warning.onSingleHost = false;
  1363. } else {
  1364. warning = {
  1365. name: name,
  1366. hosts: [_host.Hosts.host_name],
  1367. category: 'firewall',
  1368. onSingleHost: true
  1369. };
  1370. warnings.push(warning);
  1371. }
  1372. host.warnings.push(warning);
  1373. }
  1374. if (_host.Hosts.last_agent_env.alternatives) {
  1375. _host.Hosts.last_agent_env.alternatives.forEach(function (alternative) {
  1376. warning = warningCategories.alternativeWarnings[alternative.name];
  1377. if (warning) {
  1378. warning.hosts.push(_host.Hosts.host_name);
  1379. warning.onSingleHost = false;
  1380. } else {
  1381. warningCategories.alternativeWarnings[alternative.name] = warning = {
  1382. name: alternative.name,
  1383. target: alternative.target,
  1384. hosts: [_host.Hosts.host_name],
  1385. category: 'alternatives',
  1386. onSingleHost: true
  1387. };
  1388. }
  1389. host.warnings.push(warning);
  1390. }, this);
  1391. }
  1392. if (_host.Hosts.last_agent_env.reverseLookup === false) {
  1393. var name = Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.name');
  1394. warning = warnings.filterProperty('category', 'reverseLookup').findProperty('name', name);
  1395. if (warning) {
  1396. warning.hosts.push(_host.Hosts.host_name);
  1397. warning.onSingleHost = false;
  1398. } else {
  1399. warning = {
  1400. name: name,
  1401. hosts: [_host.Hosts.host_name],
  1402. category: 'reverseLookup',
  1403. onSingleHost: true
  1404. };
  1405. warnings.push(warning);
  1406. }
  1407. host.warnings.push(warning);
  1408. }
  1409. hosts.push(host);
  1410. }, this);
  1411. for (var categoryId in warningCategories) {
  1412. var category = warningCategories[categoryId]
  1413. for (var warningId in category) {
  1414. warnings.push(category[warningId]);
  1415. }
  1416. }
  1417. warnings.forEach(function (warn) {
  1418. if (warn.hosts.length < 11) {
  1419. warn.hostsList = warn.hosts.join('<br>')
  1420. } else {
  1421. warn.hostsList = warn.hosts.slice(0, 10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  1422. }
  1423. });
  1424. hosts.unshift({
  1425. name: 'All Hosts',
  1426. warnings: warnings
  1427. });
  1428. this.set('warnings', warnings);
  1429. this.set('warningsByHost', hosts);
  1430. this.set('isHostsWarningsLoaded', true);
  1431. },
  1432. /**
  1433. * Open popup that contain hosts' warnings
  1434. * @return {App.ModalPopup}
  1435. * @method hostWarningsPopup
  1436. */
  1437. hostWarningsPopup: function () {
  1438. var self = this;
  1439. return App.ModalPopup.show({
  1440. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  1441. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  1442. primary: Em.I18n.t('common.close'),
  1443. onPrimary: function () {
  1444. self.set('checksUpdateStatus', null);
  1445. this.hide();
  1446. },
  1447. onClose: function () {
  1448. self.set('checksUpdateStatus', null);
  1449. this.hide();
  1450. },
  1451. onSecondary: function () {
  1452. self.rerunChecks();
  1453. },
  1454. didInsertElement: function () {
  1455. this.fitHeight();
  1456. },
  1457. footerClass: App.WizardStep3HostWarningPopupFooter,
  1458. bodyClass: App.WizardStep3HostWarningPopupBody
  1459. });
  1460. },
  1461. /**
  1462. * Show popup with registered hosts
  1463. * @return {App.ModalPopup}
  1464. * @method registeredHostsPopup
  1465. */
  1466. registeredHostsPopup: function () {
  1467. var self = this;
  1468. return App.ModalPopup.show({
  1469. header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
  1470. secondary: null,
  1471. bodyClass: Em.View.extend({
  1472. templateName: require('templates/wizard/step3/step3_registered_hosts_popup'),
  1473. message: Em.I18n.t('installer.step3.registeredHostsPopup'),
  1474. registeredHosts: self.get('registeredHosts')
  1475. })
  1476. })
  1477. }
  1478. });