step3_controller.js 54 KB

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