step3_controller.js 54 KB

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