step3_controller.js 68 KB

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