step3_controller.js 53 KB

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