step3_controller.js 54 KB

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