step3_controller.js 45 KB

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