step3_controller.js 67 KB

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