step3_controller.js 50 KB

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