step3_controller.js 68 KB

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