step3_controller.js 50 KB

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