step3_controller.js 55 KB

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