step3_controller.js 53 KB

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