step3_controller.js 48 KB

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