step3_controller.js 57 KB

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