step3_controller.js 54 KB

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