step3_controller.js 55 KB

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