step3_controller.js 56 KB

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