step3_controller.js 54 KB

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