step3_controller.js 54 KB

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