step3_controller.js 50 KB

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