step3_controller.js 54 KB

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