step3_controller.js 51 KB

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