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: function() {
  58. return (this.get('isBackDisabled')) ? this.get('isBackDisabled') : !this.get('bootHosts').filterProperty('bootStatus', 'FAILED').length;
  59. }.property('bootHosts.@each.bootStatus', 'isBackDisabled'),
  60. /**
  61. * Is Back button disabled
  62. * @return {bool}
  63. */
  64. isBackDisabled: function () {
  65. return this.get('isRegistrationInProgress') || !this.get('isWarningsLoaded');
  66. }.property('isRegistrationInProgress', 'isWarningsLoaded'),
  67. /**
  68. * @type {bool}
  69. */
  70. isLoaded: false,
  71. /**
  72. * Polls count
  73. * @type {number}
  74. */
  75. numPolls: 0,
  76. /**
  77. * Is hosts registration in progress
  78. * @type {bool}
  79. */
  80. isRegistrationInProgress: true,
  81. /**
  82. * Are some registered hosts which are not added by user
  83. * @type {bool}
  84. */
  85. hasMoreRegisteredHosts: false,
  86. /**
  87. * Contain data about installed packages on hosts
  88. * @type {Array}
  89. */
  90. hostsPackagesData: [],
  91. /**
  92. * List of installed hostnames
  93. * @type {string[]}
  94. */
  95. hostsInCluster: function () {
  96. var installedHostsName = [];
  97. var hosts = this.get('content.hosts');
  98. for (var hostName in hosts) {
  99. if (hosts[hostName].isInstalled) {
  100. installedHostsName.push(hostName);
  101. }
  102. }
  103. return installedHostsName;
  104. }.property('content.hosts'),
  105. /**
  106. * All hosts warnings
  107. * @type {object[]}
  108. */
  109. warnings: [],
  110. /**
  111. * Warnings grouped by host
  112. * @type {Ember.Enumerable}
  113. */
  114. warningsByHost: [],
  115. /**
  116. * Timeout for "warning"-requests
  117. * @type {number}
  118. */
  119. warningsTimeInterval: 60000,
  120. /**
  121. * Are hosts warnings loaded
  122. * @type {bool}
  123. */
  124. isWarningsLoaded: function () {
  125. return this.get('isJDKWarningsLoaded') && this.get('isHostsWarningsLoaded');
  126. }.property('isJDKWarningsLoaded', 'isHostsWarningsLoaded'),
  127. /**
  128. * Check are hosts have any warnings
  129. * @type {bool}
  130. */
  131. isHostHaveWarnings: function () {
  132. return this.get('warnings.length') > 0;
  133. }.property('warnings'),
  134. /**
  135. * Should warnings-box be visible
  136. * @type {bool}
  137. */
  138. isWarningsBoxVisible: function () {
  139. return (App.get('testMode')) ? true : !this.get('isRegistrationInProgress');
  140. }.property('isRegistrationInProgress'),
  141. /**
  142. * Progress value for "update hosts status" process
  143. * @type {number}
  144. */
  145. checksUpdateProgress: 0,
  146. /**
  147. *
  148. * @type {object}
  149. */
  150. checksUpdateStatus: null,
  151. /**
  152. *
  153. * @method navigateStep
  154. */
  155. navigateStep: function () {
  156. if (this.get('isLoaded')) {
  157. if (!this.get('content.installOptions.manualInstall')) {
  158. if (!this.get('wizardController').getDBProperty('bootStatus')) {
  159. this.setupBootStrap();
  160. }
  161. } else {
  162. this.set('bootHosts', this.get('hosts'));
  163. if (App.get('testMode')) {
  164. this.startHostcheck();
  165. this.get('bootHosts').setEach('cpu', '2');
  166. this.get('bootHosts').setEach('memory', '2000000');
  167. this.set('isSubmitDisabled', false);
  168. } else {
  169. this.set('registrationStartedAt', null);
  170. this.startRegistration();
  171. }
  172. }
  173. }
  174. }.observes('isLoaded'),
  175. /**
  176. * Clear controller data
  177. * @method clearStep
  178. */
  179. clearStep: function () {
  180. this.set('stopBootstrap', false);
  181. this.set('hosts', []);
  182. this.get('bootHosts').clear();
  183. this.get('wizardController').setDBProperty('bootStatus', false);
  184. this.set('isHostsWarningsLoaded', false);
  185. this.set('isJDKWarningsLoaded', false);
  186. this.set('registrationStartedAt', null);
  187. this.set('isLoaded', false);
  188. this.set('isSubmitDisabled', true);
  189. this.set('stopChecking', false);
  190. },
  191. /**
  192. * setup bootstrap data and completion callback for bootstrap call
  193. * @method setupBootStrap
  194. */
  195. setupBootStrap: function () {
  196. var self = this;
  197. var bootStrapData = JSON.stringify({
  198. 'verbose': true,
  199. 'sshKey': this.get('content.installOptions.sshKey'),
  200. 'hosts': Em.keys(this.get('content.hosts')),
  201. 'user': this.get('content.installOptions.sshUser'),
  202. 'userRunAs': App.get('supports.customizeAgentUserAccount') ? this.get('content.installOptions.agentUser') : 'root'
  203. });
  204. App.router.get(this.get('content.controllerName')).launchBootstrap(bootStrapData, function (requestId) {
  205. if (requestId == '0') {
  206. self.startBootstrap();
  207. } else if (requestId) {
  208. self.set('content.installOptions.bootRequestId', requestId);
  209. App.router.get(self.get('content.controllerName')).save('installOptions');
  210. self.startBootstrap();
  211. }
  212. });
  213. },
  214. /**
  215. * Make basic init steps
  216. * @method loadStep
  217. */
  218. loadStep: function () {
  219. console.log("TRACE: Loading step3: Confirm Hosts");
  220. this.disablePreviousSteps();
  221. this.clearStep();
  222. App.router.get('clusterController').loadAmbariProperties();
  223. this.loadHosts();
  224. },
  225. /**
  226. * Loads the hostinfo from localStorage on the insertion of view. It's being called from view
  227. * @method loadHosts
  228. */
  229. loadHosts: function () {
  230. var hostsInfo = this.get('content.hosts');
  231. var hosts = [];
  232. var bootStatus = (this.get('content.installOptions.manualInstall')) ? 'DONE' : 'PENDING';
  233. if (App.get('testMode')) {
  234. bootStatus = 'REGISTERED';
  235. }
  236. for (var index in hostsInfo) {
  237. if (hostsInfo.hasOwnProperty(index) && !hostsInfo[index].isInstalled) {
  238. hosts.pushObject(App.HostInfo.create({
  239. name: hostsInfo[index].name,
  240. bootStatus: bootStatus,
  241. isChecked: false
  242. }));
  243. }
  244. }
  245. this.set('hosts', hosts);
  246. this.set('isLoaded', true);
  247. },
  248. /**
  249. * Parses and updates the content based on bootstrap API response.
  250. * @return {bool} true if polling should continue (some hosts are in "RUNNING" state); false otherwise
  251. * @method parseHostInfo
  252. */
  253. parseHostInfo: function (hostsStatusFromServer) {
  254. hostsStatusFromServer.forEach(function (_hostStatus) {
  255. var host = this.get('bootHosts').findProperty('name', _hostStatus.hostName);
  256. // check if hostname extracted from REST API data matches any hostname in content
  257. // also, make sure that bootStatus modified by isHostsRegistered call does not get overwritten
  258. // since these calls are being made in parallel
  259. if (host && !['REGISTERED', 'REGISTERING'].contains(host.get('bootStatus'))) {
  260. host.set('bootStatus', _hostStatus.status);
  261. host.set('bootLog', _hostStatus.log);
  262. }
  263. }, this);
  264. // if the data rendered by REST API has hosts in "RUNNING" state, polling will continue
  265. return this.get('bootHosts').length != 0 && this.get('bootHosts').someProperty('bootStatus', 'RUNNING');
  266. },
  267. /**
  268. * Remove list of hosts
  269. * @param {Ember.Enumerable} hosts
  270. * @return {App.ModalPopup}
  271. * @method removeHosts
  272. */
  273. removeHosts: function (hosts) {
  274. var self = this;
  275. return App.showConfirmationPopup(function () {
  276. App.router.send('removeHosts', hosts);
  277. self.hosts.removeObjects(hosts);
  278. self.stopRegistration();
  279. if (!self.hosts.length) {
  280. self.set('isSubmitDisabled', true);
  281. }
  282. }, Em.I18n.t('installer.step3.hosts.remove.popup.body'));
  283. },
  284. /**
  285. * Removes a single element on the trash icon click. Called from View
  286. * @param {object} hostInfo
  287. * @method removeHost
  288. */
  289. removeHost: function (hostInfo) {
  290. if (!this.get('isBackDisabled'))
  291. this.removeHosts([hostInfo]);
  292. },
  293. /**
  294. * Remove selected hosts (click-handler)
  295. * @return App.ModalPopup
  296. * @method removeSelectedHosts
  297. */
  298. removeSelectedHosts: function () {
  299. var selectedHosts = this.get('hosts').filterProperty('isChecked', true);
  300. selectedHosts.forEach(function (_hostInfo) {
  301. console.log('Removing: ' + _hostInfo.name);
  302. });
  303. return this.removeHosts(selectedHosts);
  304. },
  305. /**
  306. * Show popup with the list of hosts which are selected
  307. * @return App.ModalPopup
  308. * @method selectedHostsPopup
  309. */
  310. selectedHostsPopup: function () {
  311. var selectedHosts = this.get('hosts').filterProperty('isChecked').mapProperty('name');
  312. return App.ModalPopup.show({
  313. header: Em.I18n.t('installer.step3.selectedHosts.popup.header'),
  314. secondary: null,
  315. bodyClass: Em.View.extend({
  316. templateName: require('templates/common/items_list_popup'),
  317. items: selectedHosts,
  318. insertedItems: [],
  319. didInsertElement: function () {
  320. lazyloading.run({
  321. destination: this.get('insertedItems'),
  322. source: this.get('items'),
  323. context: this,
  324. initSize: 100,
  325. chunkSize: 500,
  326. delay: 100
  327. });
  328. }
  329. })
  330. });
  331. },
  332. /**
  333. * Retry one host {click-handler}
  334. * @param {object} hostInfo
  335. * @method retryHost
  336. */
  337. retryHost: function (hostInfo) {
  338. this.retryHosts([hostInfo]);
  339. },
  340. /**
  341. * Retry list of hosts
  342. * @param {object[]} hosts
  343. * @method retryHosts
  344. */
  345. retryHosts: function (hosts) {
  346. var self = this;
  347. var bootStrapData = JSON.stringify({
  348. 'verbose': true,
  349. 'sshKey': this.get('content.installOptions.sshKey'),
  350. 'hosts': hosts.mapProperty('name'),
  351. 'user': this.get('content.installOptions.sshUser'),
  352. 'userRunAs': App.get('supports.customizeAgentUserAccount') ? this.get('content.installOptions.agentUser') : 'root'
  353. });
  354. this.set('numPolls', 0);
  355. this.set('registrationStartedAt', null);
  356. this.set('isHostsWarningsLoaded', false);
  357. this.set('stopChecking', false);
  358. if (this.get('content.installOptions.manualInstall')) {
  359. this.startRegistration();
  360. } else {
  361. App.router.get(this.get('content.controllerName')).launchBootstrap(bootStrapData, function (requestId) {
  362. self.set('content.installOptions.bootRequestId', requestId);
  363. self.doBootstrap();
  364. });
  365. }
  366. },
  367. /**
  368. * Retry selected hosts (click-handler)
  369. * @method retrySelectedHosts
  370. */
  371. retrySelectedHosts: function () {
  372. if (!this.get('isRetryDisabled')) {
  373. var selectedHosts = this.get('bootHosts').filterProperty('bootStatus', 'FAILED');
  374. selectedHosts.forEach(function (_host) {
  375. _host.set('bootStatus', 'DONE');
  376. _host.set('bootLog', 'Retrying ...');
  377. }, this);
  378. this.retryHosts(selectedHosts);
  379. }
  380. },
  381. /**
  382. * Init bootstrap settings and start it
  383. * @method startBootstrap
  384. */
  385. startBootstrap: function () {
  386. //this.set('isSubmitDisabled', true); //TODO: uncomment after actual hookup
  387. this.set('numPolls', 0);
  388. this.set('registrationStartedAt', null);
  389. this.set('bootHosts', this.get('hosts'));
  390. this.doBootstrap();
  391. },
  392. /**
  393. * Update <code>isRegistrationInProgress</code> once
  394. * @method setRegistrationInProgressOnce
  395. */
  396. setRegistrationInProgressOnce: function () {
  397. Em.run.once(this, 'setRegistrationInProgress');
  398. }.observes('bootHosts.@each.bootStatus'),
  399. /**
  400. * Set <code>isRegistrationInProgress</code> value based on each host boot status
  401. * @method setRegistrationInProgress
  402. */
  403. setRegistrationInProgress: function () {
  404. var bootHosts = this.get('bootHosts');
  405. //if hosts aren't loaded yet then registration should be in progress
  406. var result = (bootHosts.length === 0 && !this.get('isLoaded'));
  407. for (var i = 0, l = bootHosts.length; i < l; i++) {
  408. if (bootHosts[i].get('bootStatus') !== 'REGISTERED' && bootHosts[i].get('bootStatus') !== 'FAILED') {
  409. result = true;
  410. break;
  411. }
  412. }
  413. this.set('isRegistrationInProgress', result);
  414. },
  415. /**
  416. * Disable wizard's previous steps (while registering)
  417. * @method disablePreviousSteps
  418. */
  419. disablePreviousSteps: function () {
  420. App.router.get('installerController.isStepDisabled').filter(function (step) {
  421. return step.step >= 0 && step.step <= 2;
  422. }).setEach('value', this.get('isBackDisabled'));
  423. App.router.get('addHostController.isStepDisabled').filter(function (step) {
  424. return step.step >= 0 && step.step <= 1;
  425. }).setEach('value', this.get('isBackDisabled'));
  426. }.observes('isBackDisabled'),
  427. /**
  428. * Do bootstrap calls
  429. * @method doBootstrap
  430. * @return {$.ajax|null}
  431. */
  432. doBootstrap: function () {
  433. var self = this;
  434. if (this.get('stopBootstrap')) {
  435. return null;
  436. }
  437. this.incrementProperty('numPolls');
  438. return App.ajax.send({
  439. name: 'wizard.step3.bootstrap',
  440. sender: this,
  441. data: {
  442. bootRequestId: this.get('content.installOptions.bootRequestId'),
  443. numPolls: this.get('numPolls')
  444. },
  445. success: 'doBootstrapSuccessCallback'
  446. }).
  447. retry({
  448. times: App.maxRetries,
  449. timeout: App.timeout
  450. }).
  451. then(
  452. function () {
  453. self.closeReloadPopup();
  454. },
  455. function () {
  456. self.showReloadPopup();
  457. console.log('Bootstrap failed');
  458. }
  459. );
  460. },
  461. /**
  462. * Success-callback for each boostrap request
  463. * @param {object} data
  464. * @method doBootstrapSuccessCallback
  465. */
  466. doBootstrapSuccessCallback: function (data) {
  467. var self = this;
  468. var pollingInterval = 3000;
  469. if (Em.isNone(data.hostsStatus)) {
  470. console.log('Invalid response, setting timeout');
  471. window.setTimeout(function () {
  472. self.doBootstrap()
  473. }, pollingInterval);
  474. } else {
  475. // in case of bootstrapping just one host, the server returns an object rather than an array, so
  476. // force into an array
  477. if (!(data.hostsStatus instanceof Array)) {
  478. data.hostsStatus = [ data.hostsStatus ];
  479. }
  480. console.log("TRACE: In success function for the GET bootstrap call");
  481. var keepPolling = this.parseHostInfo(data.hostsStatus);
  482. // Single host : if the only hostname is invalid (data.status == 'ERROR')
  483. // Multiple hosts : if one or more hostnames are invalid
  484. // following check will mark the bootStatus as 'FAILED' for the invalid hostname
  485. if (data.status == 'ERROR' || data.hostsStatus.length != this.get('bootHosts').length) {
  486. var hosts = this.get('bootHosts');
  487. for (var i = 0; i < hosts.length; i++) {
  488. var isValidHost = data.hostsStatus.someProperty('hostName', hosts[i].get('name'));
  489. if (hosts[i].get('bootStatus') !== 'REGISTERED') {
  490. if (!isValidHost) {
  491. hosts[i].set('bootStatus', 'FAILED');
  492. hosts[i].set('bootLog', Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  493. }
  494. }
  495. }
  496. }
  497. if (data.status == 'ERROR' || data.hostsStatus.someProperty('status', 'DONE') || data.hostsStatus.someProperty('status', 'FAILED')) {
  498. // kicking off registration polls after at least one host has succeeded
  499. this.startRegistration();
  500. }
  501. if (keepPolling) {
  502. window.setTimeout(function () {
  503. self.doBootstrap()
  504. }, pollingInterval);
  505. }
  506. }
  507. },
  508. /**
  509. * Start hosts registration
  510. * @method startRegistration
  511. */
  512. startRegistration: function () {
  513. if (Em.isNone(this.get('registrationStartedAt'))) {
  514. this.set('registrationStartedAt', App.dateTime());
  515. console.log('registration started at ' + this.get('registrationStartedAt'));
  516. this.isHostsRegistered();
  517. }
  518. },
  519. /**
  520. * Do requests to check if hosts are already registered
  521. * @return {$.ajax|null}
  522. * @method isHostsRegistered
  523. */
  524. isHostsRegistered: function () {
  525. if (this.get('stopBootstrap')) {
  526. return null;
  527. }
  528. var self = this;
  529. return App.ajax.send({
  530. name: 'wizard.step3.is_hosts_registered',
  531. sender: this,
  532. success: 'isHostsRegisteredSuccessCallback'
  533. }).
  534. retry({
  535. times: App.maxRetries,
  536. timeout: App.timeout
  537. }).
  538. then(
  539. function () {
  540. self.closeReloadPopup();
  541. },
  542. function () {
  543. self.showReloadPopup();
  544. console.log('Error: Getting registered host information from the server');
  545. }
  546. );
  547. },
  548. /**
  549. * Success-callback for registered hosts request
  550. * @param {object} data
  551. * @method isHostsRegisteredSuccessCallback
  552. */
  553. isHostsRegisteredSuccessCallback: function (data) {
  554. console.log('registration attempt...');
  555. var hosts = this.get('bootHosts');
  556. var jsonData = data;
  557. if (!jsonData) {
  558. console.warn("Error: jsonData is null");
  559. return;
  560. }
  561. // keep polling until all hosts have registered/failed, or registrationTimeout seconds after the last host finished bootstrapping
  562. var stopPolling = true;
  563. hosts.forEach(function (_host, index) {
  564. // Change name of first host for test mode.
  565. if (App.get('testMode')) {
  566. if (index == 0) {
  567. _host.set('name', 'localhost.localdomain');
  568. }
  569. }
  570. // actions to take depending on the host's current bootStatus
  571. // RUNNING - bootstrap is running; leave it alone
  572. // DONE - bootstrap is done; transition to REGISTERING
  573. // REGISTERING - bootstrap is done but has not registered; transition to REGISTERED if host found in polling API result
  574. // REGISTERED - bootstrap and registration is done; leave it alone
  575. // FAILED - either bootstrap or registration failed; leave it alone
  576. switch (_host.get('bootStatus')) {
  577. case 'DONE':
  578. _host.set('bootStatus', 'REGISTERING');
  579. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  580. // update registration timestamp so that the timeout is computed from the last host that finished bootstrapping
  581. this.set('registrationStartedAt', App.dateTime());
  582. stopPolling = false;
  583. break;
  584. case 'REGISTERING':
  585. if (jsonData.items.someProperty('Hosts.host_name', _host.name) && !jsonData.items.filterProperty('Hosts.host_name', _host.name).someProperty('Hosts.host_status', 'UNKNOWN')) {
  586. _host.set('bootStatus', 'REGISTERED');
  587. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  588. } else {
  589. stopPolling = false;
  590. }
  591. break;
  592. case 'RUNNING':
  593. stopPolling = false;
  594. break;
  595. case 'REGISTERED':
  596. case 'FAILED':
  597. default:
  598. break;
  599. }
  600. }, this);
  601. if (stopPolling) {
  602. this.startHostcheck();
  603. }
  604. else {
  605. if (hosts.someProperty('bootStatus', 'RUNNING') || App.dateTime() - this.get('registrationStartedAt') < this.get('registrationTimeoutSecs') * 1000) {
  606. // we want to keep polling for registration status if any of the hosts are still bootstrapping (so we check for RUNNING).
  607. var self = this;
  608. window.setTimeout(function () {
  609. self.isHostsRegistered();
  610. }, 3000);
  611. }
  612. else {
  613. // registration timed out. mark all REGISTERING hosts to FAILED
  614. console.log('registration timed out');
  615. hosts.filterProperty('bootStatus', 'REGISTERING').forEach(function (_host) {
  616. _host.set('bootStatus', 'FAILED');
  617. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  618. });
  619. this.startHostcheck();
  620. }
  621. }
  622. },
  623. /**
  624. * Do request for all registered hosts
  625. * @return {$.ajax}
  626. * @method getAllRegisteredHosts
  627. */
  628. getAllRegisteredHosts: function () {
  629. return App.ajax.send({
  630. name: 'wizard.step3.is_hosts_registered',
  631. sender: this,
  632. success: 'getAllRegisteredHostsCallback'
  633. });
  634. }.observes('bootHosts'),
  635. /**
  636. * Success-callback for all registered hosts request
  637. * @param {object} hosts
  638. * @method getAllRegisteredHostsCallback
  639. */
  640. getAllRegisteredHostsCallback: function (hosts) {
  641. var registeredHosts = [];
  642. var hostsInCluster = this.get('hostsInCluster');
  643. var addedHosts = this.get('bootHosts').getEach('name');
  644. hosts.items.forEach(function (host) {
  645. if (!hostsInCluster.contains(host.Hosts.host_name) && !addedHosts.contains(host.Hosts.host_name)) {
  646. registeredHosts.push(host.Hosts.host_name);
  647. }
  648. });
  649. if (registeredHosts.length) {
  650. this.set('hasMoreRegisteredHosts', true);
  651. this.set('registeredHosts', registeredHosts);
  652. } else {
  653. this.set('hasMoreRegisteredHosts', false);
  654. this.set('registeredHosts', '');
  655. }
  656. },
  657. /**
  658. * Show popup with regitration error-message
  659. * @param {string} header
  660. * @param {string} message
  661. * @return {App.ModalPopup}
  662. * @method registerErrPopup
  663. */
  664. registerErrPopup: function (header, message) {
  665. return App.ModalPopup.show({
  666. header: header,
  667. secondary: false,
  668. bodyClass: Em.View.extend({
  669. template: Em.Handlebars.compile('<p>{{view.message}}</p>'),
  670. message: message
  671. })
  672. });
  673. },
  674. /**
  675. * Get JDK name from server to determine if user had setup a customized JDK path when doing 'ambari-server setup'.
  676. * The Ambari properties are different from default ambari-server setup, property 'jdk.name' will be missing if a customized jdk path is applied.
  677. * @return {$.ajax}
  678. * @method getJDKName
  679. */
  680. getJDKName: function () {
  681. return App.ajax.send({
  682. name: 'ambari.service.load_jdk_name',
  683. sender: this,
  684. success: 'getJDKNameSuccessCallback'
  685. });
  686. },
  687. /**
  688. * Success callback for JDK name, property 'jdk.name' will be missing if a customized jdk path is applied
  689. * @param {object} data
  690. * @method getJDKNameSuccessCallback
  691. */
  692. getJDKNameSuccessCallback: function (data) {
  693. this.set('needJDKCheckOnHosts', !data.RootServiceComponents.properties["jdk.name"]);
  694. this.set('jdkLocation', Em.get(data, "RootServiceComponents.properties.jdk_location"));
  695. this.set('javaHome', data.RootServiceComponents.properties["java.home"]);
  696. },
  697. doCheckJDK: function () {
  698. var hostsNames = (!this.get('content.installOptions.manualInstall')) ? this.get('bootHosts').filterProperty('bootStatus', 'REGISTERED').getEach('name').join(",") : this.get('bootHosts').getEach('name').join(",");
  699. var javaHome = this.get('javaHome');
  700. var jdkLocation = this.get('jdkLocation');
  701. App.ajax.send({
  702. name: 'wizard.step3.jdk_check',
  703. sender: this,
  704. data: {
  705. host_names: hostsNames,
  706. java_home: javaHome,
  707. jdk_location: jdkLocation
  708. },
  709. success: 'doCheckJDKsuccessCallback',
  710. error: 'doCheckJDKerrorCallback'
  711. });
  712. },
  713. doCheckJDKsuccessCallback: function (data) {
  714. if(data){
  715. this.set('jdkRequestIndex', data.href.split('/')[data.href.split('/').length - 1]);
  716. }
  717. if (this.get('jdkCategoryWarnings') == null) {
  718. // get jdk check results for all hosts
  719. App.ajax.send({
  720. name: 'wizard.step3.jdk_check.get_results',
  721. sender: this,
  722. data: {
  723. requestIndex: this.get('jdkRequestIndex')
  724. },
  725. success: 'parseJDKCheckResults'
  726. })
  727. } else {
  728. this.set('isJDKWarningsLoaded', true);
  729. }
  730. },
  731. doCheckJDKerrorCallback: function () {
  732. console.log('INFO: Doing JDK check for host failed');
  733. this.set('isJDKWarningsLoaded', true);
  734. },
  735. parseJDKCheckResults: function (data) {
  736. var jdkWarnings = [], hostsJDKContext = [], hostsJDKNames = [];
  737. // check if the request ended
  738. if (data.Requests.end_time > 0 && data.tasks) {
  739. data.tasks.forEach( function(task) {
  740. // generate warning context
  741. if (Em.get(task, "Tasks.structured_out.java_home_check.exit_code") == 1){
  742. var jdkContext = Em.I18n.t('installer.step3.hostWarningsPopup.jdk.context').format(task.Tasks.host_name);
  743. hostsJDKContext.push(jdkContext);
  744. hostsJDKNames.push(task.Tasks.host_name);
  745. }
  746. });
  747. if (hostsJDKContext.length > 0) { // java jdk warning exist
  748. var invalidJavaHome = this.get('javaHome');
  749. jdkWarnings.push({
  750. name: Em.I18n.t('installer.step3.hostWarningsPopup.jdk.name').format(invalidJavaHome),
  751. hosts: hostsJDKContext,
  752. hostsNames: hostsJDKNames,
  753. category: 'jdk',
  754. onSingleHost: false
  755. });
  756. }
  757. this.set('jdkCategoryWarnings', jdkWarnings);
  758. } else {
  759. // still doing JDK check, data not ready to be parsed
  760. this.set('jdkCategoryWarnings', null);
  761. }
  762. this.doCheckJDKsuccessCallback();
  763. },
  764. /**
  765. * Check JDK issues on registered hosts.
  766. */
  767. checkHostJDK: function () {
  768. this.set('isJDKWarningsLoaded', false);
  769. this.set('jdkCategoryWarnings', null);
  770. var self = this;
  771. this.getJDKName().done( function() {
  772. if (self.get('needJDKCheckOnHosts')) {
  773. // need to do JDK check on each host
  774. self.doCheckJDK();
  775. } else {
  776. // no customized JDK path, so no need to check jdk
  777. self.set('jdkCategoryWarnings', []);
  778. self.set('isJDKWarningsLoaded', true);
  779. }
  780. });
  781. },
  782. /**
  783. * Get disk info and cpu count of booted hosts from server
  784. * @return {$.ajax}
  785. * @method getHostInfo
  786. */
  787. getHostInfo: function () {
  788. this.set('isHostsWarningsLoaded', false);
  789. // begin JDK check for each host
  790. return App.ajax.send({
  791. name: 'wizard.step3.host_info',
  792. sender: this,
  793. success: 'getHostInfoSuccessCallback',
  794. error: 'getHostInfoErrorCallback'
  795. });
  796. },
  797. startHostcheck: function() {
  798. this.set('isWarningsLoaded', false);
  799. this.getHostNameResolution();
  800. this.checkHostJDK();
  801. },
  802. getHostNameResolution: function () {
  803. if (App.get('testMode')) {
  804. this.getHostCheckSuccess();
  805. } else {
  806. var data = this.getDataForCheckRequest("host_resolution_check", true);
  807. data ? this.requestToPerformHostCheck(data) : this.stopHostCheck();
  808. }
  809. },
  810. getGeneralHostCheck: function () {
  811. if (App.get('testMode')) {
  812. this.getHostInfo();
  813. } else {
  814. var data = this.getDataForCheckRequest("last_agent_env_check,installed_packages,existing_repos", false);
  815. data ? this.requestToPerformHostCheck(data) : this.stopHostCheck();
  816. }
  817. },
  818. /**
  819. * set all fields from which depends running host check to true value
  820. * which force finish checking;
  821. */
  822. stopHostCheck: function() {
  823. this.set('stopChecking', true);
  824. this.set('isJDKWarningsLoaded', true);
  825. this.set('isHostsWarningsLoaded', true);
  826. },
  827. getHostCheckSuccess: function(response) {
  828. if (!App.get('testMode')) {
  829. this.set("requestId", response.Requests.id);
  830. }
  831. this.getHostCheckTasks();
  832. },
  833. /**
  834. * generates data for reuest to perform check
  835. * @param {string} checkExecuteList - for now supported:
  836. * <code>"last_agent_env_check"<code>
  837. * <code>"host_resolution_check"<code>
  838. * @param {boolean} addHosts - true
  839. * @return {object|null}
  840. * @method getDataForCheckRequest
  841. */
  842. getDataForCheckRequest: function (checkExecuteList, addHosts) {
  843. var hosts = this.get('bootHosts').filterProperty('bootStatus', 'REGISTERED').getEach('name').join(",");
  844. if (hosts.length == 0) return null;
  845. var jdk_location = App.router.get('clusterController.ambariProperties.jdk_location');
  846. var RequestInfo = {
  847. "action": "check_host",
  848. "context": "Check host",
  849. "parameters": {
  850. "check_execute_list": checkExecuteList,
  851. "jdk_location" : jdk_location,
  852. "threshold": "20"
  853. }
  854. };
  855. if (addHosts) {
  856. RequestInfo.parameters.hosts = hosts;
  857. }
  858. var resource_filters = {
  859. "hosts": hosts
  860. };
  861. return {
  862. RequestInfo: RequestInfo,
  863. resource_filters: resource_filters
  864. }
  865. },
  866. /**
  867. * send request to ceate tasks for performing hosts checks
  868. * @params {object} data
  869. * {
  870. * RequestInfo: {
  871. * "action": {string},
  872. * "context": {string},
  873. * "parameters": {
  874. * "check_execute_list": {string},
  875. * "jdk_location" : {string},
  876. * "threshold": {string}
  877. * "hosts": {string|undefined}
  878. * },
  879. * resource_filters: {
  880. * "hosts": {string}
  881. * }
  882. * }
  883. * @returns {$.ajax}
  884. * @method requestToPerformHostCheck
  885. */
  886. requestToPerformHostCheck: function(data) {
  887. return App.ajax.send({
  888. name: 'preinstalled.checks',
  889. sender: this,
  890. data: {
  891. RequestInfo: data.RequestInfo,
  892. resource_filters: data.resource_filters
  893. },
  894. success: "getHostCheckSuccess",
  895. error: "getHostCheckError"
  896. })
  897. },
  898. /**
  899. * send ajax request to get all tasks
  900. * @method getHostCheckTasks
  901. */
  902. getHostCheckTasks: function () {
  903. var self = this;
  904. var requestId = this.get("requestId");
  905. var checker = setTimeout(function () {
  906. if (self.get('stopChecking') == true) {
  907. clearTimeout(checker);
  908. } else {
  909. App.ajax.send({
  910. name: 'preinstalled.checks.tasks',
  911. sender: self,
  912. data: {
  913. requestId: requestId
  914. },
  915. success: 'getHostCheckTasksSuccess',
  916. error: 'getHostCheckTasksError'
  917. });
  918. }
  919. }, 1000);
  920. },
  921. /**
  922. * add warnings to host warning popup if needed
  923. * @param data {Object} - json
  924. * @method getHostCheckTasksSuccess
  925. */
  926. getHostCheckTasksSuccess: function (data) {
  927. console.log('checking attempt...');
  928. if (!data) {
  929. console.warn("Error: jsonData is null");
  930. return;
  931. }
  932. if (["FAILED", "COMPLETED", "TIMEDOUT"].contains(data.Requests.request_status)) {
  933. if (data.Requests.inputs.indexOf("last_agent_env_check") != -1) {
  934. this.set('stopChecking', true);
  935. this.set('hostsPackagesData', data.tasks.map(function (task) {
  936. var installed_packages = Em.get(task, 'Tasks.structured_out.installed_packages');
  937. return {
  938. hostName: Em.get(task, 'Tasks.host_name'),
  939. installedPackages: installed_packages ? installed_packages : []
  940. }
  941. }));
  942. this.getHostInfo();
  943. } else if (data.Requests.inputs.indexOf("host_resolution_check") != -1) {
  944. this.parseHostNameResolution(data);
  945. this.getGeneralHostCheck();
  946. }
  947. } else {
  948. this.getHostCheckTasks();
  949. }
  950. },
  951. /**
  952. * parse warnings for host names resolution only
  953. * @param {object} data
  954. * @method parseHostNameResolution
  955. */
  956. parseHostNameResolution: function (data) {
  957. if (!data) {
  958. console.warn("Error: jsonData is null");
  959. return;
  960. }
  961. data.tasks.forEach(function (task) {
  962. var name = Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.error');
  963. var hostInfo = this.get("hostCheckWarnings").findProperty('name', name);
  964. if (["FAILED", "COMPLETED", "TIMEDOUT"].contains(task.Tasks.status)) {
  965. if (!(task.Tasks.status == "COMPLETED" && Em.get(task, "Tasks.structured_out.host_resolution_check.failed_count") == 0)) {
  966. var targetHostName = Em.get(task, "Tasks.host_name");
  967. var relatedHostNames = Em.get(task, "Tasks.structured_out.host_resolution_check.failures")
  968. ? Em.get(task, "Tasks.structured_out.host_resolution_check.failures").mapProperty('host') : [];
  969. var contextMessage = Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format(targetHostName, relatedHostNames.join(', '));
  970. if (!hostInfo) {
  971. hostInfo = {
  972. name: name,
  973. hosts: [contextMessage],
  974. hostsNames: [targetHostName],
  975. onSingleHost: true
  976. };
  977. this.get("hostCheckWarnings").push(hostInfo);
  978. } else {
  979. if (!hostInfo.hostsNames.contains(targetHostName)) {
  980. hostInfo.hosts.push(contextMessage);
  981. hostInfo.hostsNames.push(targetHostName);
  982. }
  983. }
  984. }
  985. }
  986. }, this);
  987. },
  988. getHostCheckError: function() {
  989. this.getHostInfo();
  990. },
  991. stopChecking: false,
  992. /**
  993. * @method getHostCheckTasksError
  994. */
  995. getHostCheckTasksError: function() {
  996. console.warn("failed to cheek hostName resolution");
  997. this.set('stopChecking', true);
  998. },
  999. /**
  1000. * Success-callback for hosts info request
  1001. * @param {object} jsonData
  1002. * @method getHostInfoSuccessCallback
  1003. */
  1004. getHostInfoSuccessCallback: function (jsonData) {
  1005. var hosts = this.get('bootHosts'),
  1006. self = this,
  1007. repoWarnings = [], hostsRepoNames = [], hostsContext = [],
  1008. diskWarnings = [], hostsDiskContext = [], hostsDiskNames = [],
  1009. thpWarnings = [], thpContext = [], thpHostsNames = [];
  1010. // parse host checks warning
  1011. this.parseWarnings(jsonData);
  1012. this.set('isHostsWarningsLoaded', true);
  1013. hosts.forEach(function (_host) {
  1014. var host = (App.get('testMode')) ? jsonData.items[0] : jsonData.items.findProperty('Hosts.host_name', _host.name);
  1015. if (App.get('skipBootstrap')) {
  1016. self._setHostDataWithSkipBootstrap(_host);
  1017. }
  1018. else {
  1019. if (host) {
  1020. self._setHostDataFromLoadedHostInfo(_host, host);
  1021. var host_name = Em.get(host, 'Hosts.host_name');
  1022. var context = self.checkHostOSType(host.Hosts.os_type, host_name);
  1023. if (context) {
  1024. hostsContext.push(context);
  1025. hostsRepoNames.push(host_name);
  1026. }
  1027. var diskContext = self.checkHostDiskSpace(host_name, host.Hosts.disk_info);
  1028. if (diskContext) {
  1029. hostsDiskContext.push(diskContext);
  1030. hostsDiskNames.push(host_name);
  1031. }
  1032. // "Transparent Huge Pages" check
  1033. context = self.checkTHP(host_name, Em.get(host, 'Hosts.last_agent_env.transparentHugePage'));
  1034. if (context) {
  1035. thpContext.push(context);
  1036. thpHostsNames.push(host_name);
  1037. }
  1038. }
  1039. }
  1040. });
  1041. if (hostsContext.length > 0) { // repository warning exist
  1042. repoWarnings.push({
  1043. name: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.name'),
  1044. hosts: hostsContext,
  1045. hostsNames: hostsRepoNames,
  1046. category: 'repositories',
  1047. onSingleHost: false
  1048. });
  1049. }
  1050. if (hostsDiskContext.length > 0) { // disk space warning exist
  1051. diskWarnings.push({
  1052. name: Em.I18n.t('installer.step3.hostWarningsPopup.disk.name'),
  1053. hosts: hostsDiskContext,
  1054. hostsNames: hostsDiskNames,
  1055. category: 'disk',
  1056. onSingleHost: false
  1057. });
  1058. }
  1059. if (thpContext.length > 0) { // THP warning existed
  1060. thpWarnings.push({
  1061. name: Em.I18n.t('installer.step3.hostWarningsPopup.thp.name'),
  1062. hosts: thpContext,
  1063. hostsNames: thpHostsNames,
  1064. category: 'thp',
  1065. onSingleHost: false
  1066. });
  1067. }
  1068. this.set('repoCategoryWarnings', repoWarnings);
  1069. this.set('diskCategoryWarnings', diskWarnings);
  1070. this.set('thpCategoryWarnings', thpWarnings);
  1071. this.stopRegistration();
  1072. },
  1073. /**
  1074. * Set metrics to host object
  1075. * Used when <code>App.skipBootstrap</code> is true
  1076. * @param {Ember.Object} host
  1077. * @returns {object}
  1078. * @private
  1079. * @methos _setHostDataWithSkipBootstrap
  1080. */
  1081. _setHostDataWithSkipBootstrap: function(host) {
  1082. host.set('cpu', 2);
  1083. host.set('memory', ((parseInt(2000000))).toFixed(2));
  1084. host.set('disk_info', [
  1085. {"mountpoint": "/", "type": "ext4"},
  1086. {"mountpoint": "/grid/0", "type": "ext4"},
  1087. {"mountpoint": "/grid/1", "type": "ext4"},
  1088. {"mountpoint": "/grid/2", "type": "ext4"}
  1089. ]);
  1090. return host;
  1091. },
  1092. /**
  1093. * Set loaded metrics to host object
  1094. * @param {object} host
  1095. * @param {object} hostInfo
  1096. * @returns {object}
  1097. * @method _setHostDataFromLoadedHostInfo
  1098. * @private
  1099. */
  1100. _setHostDataFromLoadedHostInfo: function(host, hostInfo) {
  1101. host.set('cpu', Em.get(hostInfo, 'Hosts.cpu_count'));
  1102. host.set('memory', ((parseInt(Em.get(hostInfo, 'Hosts.total_mem')))).toFixed(2));
  1103. host.set('disk_info', Em.get(hostInfo, 'Hosts.disk_info').filter(function (h) {
  1104. return h.mountpoint != "/boot"
  1105. }));
  1106. host.set('os_type', Em.get(hostInfo, 'Hosts.os_type'));
  1107. host.set('os_arch', Em.get(hostInfo, 'Hosts.os_arch'));
  1108. host.set('ip', Em.get(hostInfo, 'Hosts.ip'));
  1109. return host;
  1110. },
  1111. /**
  1112. * Error-callback for hosts info request
  1113. * @method getHostInfoErrorCallback
  1114. */
  1115. getHostInfoErrorCallback: function () {
  1116. console.log('INFO: Getting host information(cpu_count and total_mem) from the server failed');
  1117. this.set('isHostsWarningsLoaded', true);
  1118. this.registerErrPopup(Em.I18n.t('installer.step3.hostInformation.popup.header'), Em.I18n.t('installer.step3.hostInformation.popup.body'));
  1119. },
  1120. /**
  1121. * Enable or disable submit/retry buttons according to hosts boot statuses
  1122. * @method stopRegistration
  1123. */
  1124. stopRegistration: function () {
  1125. this.set('isSubmitDisabled', !this.get('bootHosts').someProperty('bootStatus', 'REGISTERED'));
  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. });