step3_controller.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  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. if (Em.get(task, "Tasks.structured_out.host_resolution_check.failed_count") == 0) {
  772. return;
  773. }
  774. }
  775. if (!hostInfo) {
  776. hostInfo = {
  777. name: name,
  778. hosts: [task.Tasks.host_name],
  779. onSingleHost: true
  780. };
  781. this.get("hostCheckWarnings").push(hostInfo);
  782. } else {
  783. if (!hostInfo.hosts.contains(task.Tasks.host_name)) {
  784. hostInfo.hosts.push(task.Tasks.host_name);
  785. }
  786. }
  787. } else {
  788. this.set('stopChecking', false);
  789. }
  790. }, this);
  791. },
  792. stopChecking: false,
  793. /**
  794. * @method getHostCheckTasksError
  795. */
  796. getHostCheckTasksError: function() {
  797. console.warn("failed to cheek hostName resolution");
  798. this.set('stopChecking', true);
  799. },
  800. /**
  801. * Success-callback for hosts info request
  802. * @param {object} jsonData
  803. * @method getHostInfoSuccessCallback
  804. */
  805. getHostInfoSuccessCallback: function (jsonData) {
  806. var hosts = this.get('bootHosts'),
  807. self = this,
  808. repoWarnings = [],
  809. hostsContext = [],
  810. diskWarnings = [],
  811. hostsDiskContext = [],
  812. hostsDiskNames = [],
  813. hostsRepoNames = [];
  814. this.parseWarnings(jsonData);
  815. hosts.forEach(function (_host) {
  816. var host = (App.get('testMode')) ? jsonData.items[0] : jsonData.items.findProperty('Hosts.host_name', _host.name);
  817. if (App.get('skipBootstrap')) {
  818. self._setHostDataWithSkipBootstrap(_host);
  819. }
  820. else {
  821. if (host) {
  822. self._setHostDataFromLoadedHostInfo(_host, host);
  823. var host_name = Em.get(host, 'Hosts.host_name');
  824. var context = self.checkHostOSType(host.Hosts.os_type, host_name);
  825. if (context) {
  826. hostsContext.push(context);
  827. hostsRepoNames.push(host_name);
  828. }
  829. var diskContext = self.checkHostDiskSpace(host_name, host.Hosts.disk_info);
  830. if (diskContext) {
  831. hostsDiskContext.push(diskContext);
  832. hostsDiskNames.push(host_name);
  833. }
  834. }
  835. }
  836. });
  837. if (hostsContext.length > 0) { // warning exist
  838. repoWarnings.push({
  839. name: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.name'),
  840. hosts: hostsContext,
  841. hostsNames: hostsRepoNames,
  842. category: 'repositories',
  843. onSingleHost: false
  844. });
  845. }
  846. if (hostsDiskContext.length > 0) { // disk space warning exist
  847. diskWarnings.push({
  848. name: Em.I18n.t('installer.step3.hostWarningsPopup.disk.name'),
  849. hosts: hostsDiskContext,
  850. hostsNames: hostsDiskNames,
  851. category: 'disk',
  852. onSingleHost: false
  853. });
  854. }
  855. this.set('repoCategoryWarnings', repoWarnings);
  856. this.set('diskCategoryWarnings', diskWarnings);
  857. this.stopRegistration();
  858. },
  859. /**
  860. * Set metrics to host object
  861. * Used when <code>App.skipBootstrap</code> is true
  862. * @param {Ember.Object} host
  863. * @returns {object}
  864. * @private
  865. * @methos _setHostDataWithSkipBootstrap
  866. */
  867. _setHostDataWithSkipBootstrap: function(host) {
  868. host.set('cpu', 2);
  869. host.set('memory', ((parseInt(2000000))).toFixed(2));
  870. host.set('disk_info', [
  871. {"mountpoint": "/", "type": "ext4"},
  872. {"mountpoint": "/grid/0", "type": "ext4"},
  873. {"mountpoint": "/grid/1", "type": "ext4"},
  874. {"mountpoint": "/grid/2", "type": "ext4"}
  875. ]);
  876. return host;
  877. },
  878. /**
  879. * Set loaded metrics to host object
  880. * @param {object} host
  881. * @param {object} hostInfo
  882. * @returns {object}
  883. * @method _setHostDataFromLoadedHostInfo
  884. * @private
  885. */
  886. _setHostDataFromLoadedHostInfo: function(host, hostInfo) {
  887. host.set('cpu', Em.get(hostInfo, 'Hosts.cpu_count'));
  888. host.set('memory', ((parseInt(Em.get(hostInfo, 'Hosts.total_mem')))).toFixed(2));
  889. host.set('disk_info', Em.get(hostInfo, 'Hosts.disk_info').filter(function (h) {
  890. return h.mountpoint != "/boot"
  891. }));
  892. host.set('os_type', Em.get(hostInfo, 'Hosts.os_type'));
  893. host.set('os_arch', Em.get(hostInfo, 'Hosts.os_arch'));
  894. host.set('ip', Em.get(hostInfo, 'Hosts.ip'));
  895. return host;
  896. },
  897. /**
  898. * Error-callback for hosts info request
  899. * @method getHostInfoErrorCallback
  900. */
  901. getHostInfoErrorCallback: function () {
  902. console.log('INFO: Getting host information(cpu_count and total_mem) from the server failed');
  903. this.set('isWarningsLoaded', true);
  904. this.registerErrPopup(Em.I18n.t('installer.step3.hostInformation.popup.header'), Em.I18n.t('installer.step3.hostInformation.popup.body'));
  905. },
  906. /**
  907. * Enable or disable submit/retry buttons according to hosts boot statuses
  908. * @method stopRegistration
  909. */
  910. stopRegistration: function () {
  911. this.set('isSubmitDisabled', !this.get('bootHosts').someProperty('bootStatus', 'REGISTERED'));
  912. this.set('isRetryDisabled', !this.get('bootHosts').someProperty('bootStatus', 'FAILED'));
  913. },
  914. /**
  915. * Check if the customized os group contains the registered host os type. If not the repo on that host is invalid.
  916. * @param {string} osType
  917. * @param {string} hostName
  918. * @return {string} error-message or empty string
  919. * @method checkHostOSType
  920. */
  921. checkHostOSType: function (osType, hostName) {
  922. if (this.get('content.stacks')) {
  923. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  924. var selectedOS = [];
  925. var self = this;
  926. var isValid = false;
  927. if (selectedStack && selectedStack.operatingSystems) {
  928. selectedStack.get('operatingSystems').filterProperty('selected', true).forEach(function (os) {
  929. selectedOS.pushObject(os.osType);
  930. if (self.repoToAgentOsType(os.osType).indexOf(osType) >= 0) {
  931. isValid = true;
  932. }
  933. });
  934. }
  935. if (isValid) {
  936. return '';
  937. } else {
  938. console.log('WARNING: Getting host os type does NOT match the user selected os group in step1. ' +
  939. 'Host Name: ' + hostName + '. Host os type:' + osType + '. Selected group:' + selectedOS.uniq());
  940. return Em.I18n.t('installer.step3.hostWarningsPopup.repositories.context').format(hostName, osType, selectedOS.uniq());
  941. }
  942. } else {
  943. return '';
  944. }
  945. },
  946. /**
  947. * return the supported agent os types for a repo os type
  948. * @param {String} repoType
  949. * @return {Array} supported agent os type array
  950. * @method repoToAgentOsType
  951. */
  952. repoToAgentOsType : function (repoType) {
  953. switch (repoType) {
  954. case "redhat6":
  955. return ["redhat6", "centos6", "oraclelinux6", "rhel6"];
  956. case "redhat5":
  957. return ["redhat5", "centos5", "oraclelinux5", "rhel5"];
  958. case "suse11":
  959. return ["suse11", "sles11", "opensuse11"];
  960. case "debian12":
  961. return ["debian12", "ubuntu12"];
  962. default:
  963. return [];
  964. }
  965. },
  966. /**
  967. * Check if current host has enough free disk usage.
  968. * @param {string} hostName
  969. * @param {object} diskInfo
  970. * @return {string} error-message or empty string
  971. * @method checkHostDiskSpace
  972. */
  973. checkHostDiskSpace: function (hostName, diskInfo) {
  974. var minFreeRootSpace = App.minDiskSpace * 1024 * 1024; //in kilobyte
  975. var minFreeUsrLibSpace = App.minDiskSpaceUsrLib * 1024 * 1024; //in kilobyte
  976. var warningString = '';
  977. diskInfo.forEach(function (info) {
  978. switch (info.mountpoint) {
  979. case '/':
  980. warningString = info.available < minFreeRootSpace ?
  981. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpace + 'GB', info.mountpoint) + ' ' + warningString :
  982. warningString;
  983. break;
  984. case '/usr':
  985. case '/usr/lib':
  986. warningString = info.available < minFreeUsrLibSpace ?
  987. Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpaceUsrLib + 'GB', info.mountpoint) + ' ' + warningString :
  988. warningString;
  989. break;
  990. default:
  991. break;
  992. }
  993. });
  994. if (warningString) {
  995. console.log('WARNING: Getting host free disk space. ' + 'Host Name: ' + hostName);
  996. return Em.I18n.t('installer.step3.hostWarningsPopup.disk.context1').format(hostName) + ' ' + warningString;
  997. } else {
  998. return '';
  999. }
  1000. },
  1001. /**
  1002. * Submit-click handler
  1003. * @return {App.ModalPopup|null}
  1004. * @method submit
  1005. */
  1006. submit: function () {
  1007. if (this.get('isHostHaveWarnings')) {
  1008. var self = this;
  1009. return App.showConfirmationPopup(
  1010. function () {
  1011. self.set('content.hosts', []);
  1012. lazyloading.run({
  1013. initSize: 20,
  1014. chunkSize: 50,
  1015. delay: 50,
  1016. destination: self.get('content.hosts'),
  1017. source: self.get('bootHosts'),
  1018. context: Em.Object.create()
  1019. });
  1020. App.router.send('next');
  1021. },
  1022. Em.I18n.t('installer.step3.hostWarningsPopup.hostHasWarnings'));
  1023. }
  1024. else {
  1025. this.set('content.hosts', []);
  1026. lazyloading.run({
  1027. initSize: 20,
  1028. chunkSize: 50,
  1029. delay: 50,
  1030. destination: this.get('content.hosts'),
  1031. source: this.get('bootHosts'),
  1032. context: Em.Object.create()
  1033. });
  1034. App.router.send('next');
  1035. }
  1036. return null;
  1037. },
  1038. /**
  1039. * Show popup with host log
  1040. * @param {object} event
  1041. * @return {App.ModalPopup}
  1042. */
  1043. hostLogPopup: function (event) {
  1044. var host = event.context;
  1045. return App.ModalPopup.show({
  1046. header: Em.I18n.t('installer.step3.hostLog.popup.header').format(host.get('name')),
  1047. secondary: null,
  1048. host: host,
  1049. bodyClass: App.WizardStep3HostLogPopupBody
  1050. });
  1051. },
  1052. /**
  1053. * Check warnings from server and put it in parsing
  1054. * @method rerunChecks
  1055. */
  1056. rerunChecks: function () {
  1057. var self = this;
  1058. var currentProgress = 0;
  1059. var interval = setInterval(function () {
  1060. currentProgress += 100000 / self.get('warningsTimeInterval');
  1061. if (currentProgress < 100) {
  1062. self.set('checksUpdateProgress', currentProgress);
  1063. } else {
  1064. clearInterval(interval);
  1065. App.ajax.send({
  1066. name: 'wizard.step3.rerun_checks',
  1067. sender: self,
  1068. success: 'rerunChecksSuccessCallback',
  1069. error: 'rerunChecksErrorCallback'
  1070. });
  1071. }
  1072. }, 1000);
  1073. },
  1074. /**
  1075. * Success-callback for rerun request
  1076. * @param {object} data
  1077. * @method rerunChecksSuccessCallback
  1078. */
  1079. rerunChecksSuccessCallback: function (data) {
  1080. this.set('checksUpdateProgress', 100);
  1081. this.set('checksUpdateStatus', 'SUCCESS');
  1082. this.parseWarnings(data);
  1083. },
  1084. /**
  1085. * Error-callback for rerun request
  1086. * @method rerunChecksErrorCallback
  1087. */
  1088. rerunChecksErrorCallback: function () {
  1089. this.set('checksUpdateProgress', 100);
  1090. this.set('checksUpdateStatus', 'FAILED');
  1091. console.log('INFO: Getting host information(last_agent_env) from the server failed');
  1092. },
  1093. /**
  1094. * Filter data for warnings parse
  1095. * is data from host in bootStrap
  1096. * @param {object} data
  1097. * @return {Object}
  1098. * @method filterBootHosts
  1099. */
  1100. filterBootHosts: function (data) {
  1101. var bootHostNames = {};
  1102. this.get('bootHosts').forEach(function (bootHost) {
  1103. bootHostNames[bootHost.get('name')] = true;
  1104. });
  1105. var filteredData = {
  1106. href: data.href,
  1107. items: []
  1108. };
  1109. data.items.forEach(function (host) {
  1110. if (bootHostNames[host.Hosts.host_name]) {
  1111. filteredData.items.push(host);
  1112. }
  1113. });
  1114. return filteredData;
  1115. },
  1116. /**
  1117. * Parse warnings data for each host and total
  1118. * @param {object} data
  1119. * @method parseWarnings
  1120. */
  1121. parseWarnings: function (data) {
  1122. data = App.testMode ? data : this.filterBootHosts(data);
  1123. var warnings = [];
  1124. var warning;
  1125. var hosts = [];
  1126. var warningCategories = {
  1127. fileFoldersWarnings: {},
  1128. packagesWarnings: {},
  1129. processesWarnings: {},
  1130. servicesWarnings: {},
  1131. usersWarnings: {},
  1132. alternativeWarnings: {}
  1133. };
  1134. data.items.sortPropertyLight('Hosts.host_name').forEach(function (_host) {
  1135. var host = {
  1136. name: _host.Hosts.host_name,
  1137. warnings: []
  1138. };
  1139. if (!_host.Hosts.last_agent_env) {
  1140. // in some unusual circumstances when last_agent_env is not available from the _host,
  1141. // skip the _host and proceed to process the rest of the hosts.
  1142. console.log("last_agent_env is missing for " + _host.Hosts.host_name + ". Skipping _host check.");
  1143. return;
  1144. }
  1145. //parse all directories and files warnings for host
  1146. //todo: to be removed after check in new API
  1147. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || [];
  1148. stackFoldersAndFiles.forEach(function (path) {
  1149. warning = warningCategories.fileFoldersWarnings[path.name];
  1150. if (warning) {
  1151. warning.hosts.push(_host.Hosts.host_name);
  1152. warning.onSingleHost = false;
  1153. } else {
  1154. warningCategories.fileFoldersWarnings[path.name] = warning = {
  1155. name: path.name,
  1156. hosts: [_host.Hosts.host_name],
  1157. category: 'fileFolders',
  1158. onSingleHost: true
  1159. };
  1160. }
  1161. host.warnings.push(warning);
  1162. }, this);
  1163. //parse all package warnings for host
  1164. if (_host.Hosts.last_agent_env.installedPackages) {
  1165. _host.Hosts.last_agent_env.installedPackages.forEach(function (_package) {
  1166. warning = warningCategories.packagesWarnings[_package.name];
  1167. if (warning) {
  1168. warning.hosts.push(_host.Hosts.host_name);
  1169. warning.version = _package.version;
  1170. warning.onSingleHost = false;
  1171. } else {
  1172. warningCategories.packagesWarnings[_package.name] = warning = {
  1173. name: _package.name,
  1174. version: _package.version,
  1175. hosts: [_host.Hosts.host_name],
  1176. category: 'packages',
  1177. onSingleHost: true
  1178. };
  1179. }
  1180. host.warnings.push(warning);
  1181. }, this);
  1182. }
  1183. //parse all process warnings for host
  1184. //todo: to be removed after check in new API
  1185. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  1186. if (javaProcs) {
  1187. javaProcs.forEach(function (process) {
  1188. warning = warningCategories.processesWarnings[process.pid];
  1189. if (warning) {
  1190. warning.hosts.push(_host.Hosts.host_name);
  1191. warning.onSingleHost = false;
  1192. } else {
  1193. warningCategories.processesWarnings[process.pid] = warning = {
  1194. name: (process.command.substr(0, 35) + '...'),
  1195. hosts: [_host.Hosts.host_name],
  1196. category: 'processes',
  1197. user: process.user,
  1198. pid: process.pid,
  1199. command: '<table><tr><td style="word-break: break-all;">' +
  1200. ((process.command.length < 500) ? process.command : process.command.substr(0, 230) + '...' +
  1201. '<p style="text-align: center">................</p>' +
  1202. '...' + process.command.substr(-230)) + '</td></tr></table>',
  1203. onSingleHost: true
  1204. };
  1205. }
  1206. host.warnings.push(warning);
  1207. }, this);
  1208. }
  1209. //parse all service warnings for host
  1210. //todo: to be removed after check in new API
  1211. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  1212. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  1213. if (service.status === 'Unhealthy') {
  1214. warning = warningCategories.servicesWarnings[service.name];
  1215. if (warning) {
  1216. warning.hosts.push(_host.Hosts.host_name);
  1217. warning.onSingleHost = false;
  1218. } else {
  1219. warningCategories.servicesWarnings[service.name] = warning = {
  1220. name: service.name,
  1221. hosts: [_host.Hosts.host_name],
  1222. category: 'services',
  1223. onSingleHost: true
  1224. };
  1225. }
  1226. host.warnings.push(warning);
  1227. }
  1228. }, this);
  1229. }
  1230. //parse all user warnings for host
  1231. //todo: to be removed after check in new API
  1232. if (_host.Hosts.last_agent_env.existingUsers) {
  1233. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  1234. warning = warningCategories.usersWarnings[user.userName];
  1235. if (warning) {
  1236. warning.hosts.push(_host.Hosts.host_name);
  1237. warning.onSingleHost = false;
  1238. } else {
  1239. warningCategories.usersWarnings[user.userName] = warning = {
  1240. name: user.userName,
  1241. hosts: [_host.Hosts.host_name],
  1242. category: 'users',
  1243. onSingleHost: true
  1244. };
  1245. }
  1246. host.warnings.push(warning);
  1247. }, this);
  1248. }
  1249. //parse misc warnings for host
  1250. var umask = _host.Hosts.last_agent_env.umask;
  1251. if (umask && umask !== 18) {
  1252. warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
  1253. if (warning) {
  1254. warning.hosts.push(_host.Hosts.host_name);
  1255. warning.onSingleHost = false;
  1256. } else {
  1257. warning = {
  1258. name: umask,
  1259. hosts: [_host.Hosts.host_name],
  1260. category: 'misc',
  1261. onSingleHost: true
  1262. };
  1263. warnings.push(warning);
  1264. }
  1265. host.warnings.push(warning);
  1266. }
  1267. var firewallRunning = _host.Hosts.last_agent_env.iptablesIsRunning;
  1268. if (firewallRunning !== null && firewallRunning) {
  1269. var name = Em.I18n.t('installer.step3.hostWarningsPopup.firewall.name');
  1270. warning = warnings.filterProperty('category', 'firewall').findProperty('name', name);
  1271. if (warning) {
  1272. warning.hosts.push(_host.Hosts.host_name);
  1273. warning.onSingleHost = false;
  1274. } else {
  1275. warning = {
  1276. name: name,
  1277. hosts: [_host.Hosts.host_name],
  1278. category: 'firewall',
  1279. onSingleHost: true
  1280. };
  1281. warnings.push(warning);
  1282. }
  1283. host.warnings.push(warning);
  1284. }
  1285. if (_host.Hosts.last_agent_env.alternatives) {
  1286. _host.Hosts.last_agent_env.alternatives.forEach(function (alternative) {
  1287. warning = warningCategories.alternativeWarnings[alternative.name];
  1288. if (warning) {
  1289. warning.hosts.push(_host.Hosts.host_name);
  1290. warning.onSingleHost = false;
  1291. } else {
  1292. warningCategories.alternativeWarnings[alternative.name] = warning = {
  1293. name: alternative.name,
  1294. target: alternative.target,
  1295. hosts: [_host.Hosts.host_name],
  1296. category: 'alternatives',
  1297. onSingleHost: true
  1298. };
  1299. }
  1300. host.warnings.push(warning);
  1301. }, this);
  1302. }
  1303. if (_host.Hosts.last_agent_env.reverseLookup === false) {
  1304. var name = Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.name');
  1305. warning = warnings.filterProperty('category', 'reverseLookup').findProperty('name', name);
  1306. if (warning) {
  1307. warning.hosts.push(_host.Hosts.host_name);
  1308. warning.onSingleHost = false;
  1309. } else {
  1310. warning = {
  1311. name: name,
  1312. hosts: [_host.Hosts.host_name],
  1313. category: 'reverseLookup',
  1314. onSingleHost: true
  1315. };
  1316. warnings.push(warning);
  1317. }
  1318. host.warnings.push(warning);
  1319. }
  1320. hosts.push(host);
  1321. }, this);
  1322. for (var categoryId in warningCategories) {
  1323. var category = warningCategories[categoryId]
  1324. for (var warningId in category) {
  1325. warnings.push(category[warningId]);
  1326. }
  1327. }
  1328. warnings.forEach(function (warn) {
  1329. if (warn.hosts.length < 11) {
  1330. warn.hostsList = warn.hosts.join('<br>')
  1331. } else {
  1332. warn.hostsList = warn.hosts.slice(0, 10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  1333. }
  1334. });
  1335. hosts.unshift({
  1336. name: 'All Hosts',
  1337. warnings: warnings
  1338. });
  1339. this.set('warnings', warnings);
  1340. this.set('warningsByHost', hosts);
  1341. this.set('isWarningsLoaded', true);
  1342. },
  1343. /**
  1344. * Open popup that contain hosts' warnings
  1345. * @return {App.ModalPopup}
  1346. * @method hostWarningsPopup
  1347. */
  1348. hostWarningsPopup: function () {
  1349. var self = this;
  1350. return App.ModalPopup.show({
  1351. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  1352. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  1353. primary: Em.I18n.t('common.close'),
  1354. onPrimary: function () {
  1355. self.set('checksUpdateStatus', null);
  1356. this.hide();
  1357. },
  1358. onClose: function () {
  1359. self.set('checksUpdateStatus', null);
  1360. this.hide();
  1361. },
  1362. onSecondary: function () {
  1363. self.rerunChecks();
  1364. },
  1365. didInsertElement: function () {
  1366. this.fitHeight();
  1367. },
  1368. footerClass: App.WizardStep3HostWarningPopupFooter,
  1369. bodyClass: App.WizardStep3HostWarningPopupBody
  1370. });
  1371. },
  1372. /**
  1373. * Show popup with registered hosts
  1374. * @return {App.ModalPopup}
  1375. * @method registeredHostsPopup
  1376. */
  1377. registeredHostsPopup: function () {
  1378. var self = this;
  1379. return App.ModalPopup.show({
  1380. header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
  1381. secondary: null,
  1382. bodyClass: Em.View.extend({
  1383. templateName: require('templates/wizard/step3/step3_registered_hosts_popup'),
  1384. message: Em.I18n.t('installer.step3.registeredHostsPopup'),
  1385. registeredHosts: self.get('registeredHosts')
  1386. })
  1387. })
  1388. }
  1389. });