step3_controller.js 48 KB

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