hostWarningPopupBody_view.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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.WizardStep3HostWarningPopupBody = Em.View.extend({
  22. templateName: require('templates/wizard/step3/step3_host_warnings_popup'),
  23. classNames: ['host-check'],
  24. bodyControllerBinding: 'App.router.wizardStep3Controller',
  25. /**
  26. * Listbox with host filters
  27. * @type {Ember.Select}
  28. */
  29. hostSelectView: Em.Select.extend({
  30. elementId: 'hosts-check-select',
  31. selectionBinding: "parentView.category",
  32. /**
  33. * Content has default value "All Hosts" to bind selection to category
  34. * @type {string[]}
  35. */
  36. content: ['All Hosts'],
  37. /**
  38. * List of filtered hostnames
  39. * @type {string[]}
  40. */
  41. hosts: function () {
  42. var warningsByHost = this.get('parentView.warningsByHost');
  43. if (Em.isNone(warningsByHost)) return [];
  44. return warningsByHost.mapProperty('name');
  45. }.property('parentView.warningsByHost'),
  46. /**
  47. * Is data loaded
  48. * @type {bool}
  49. */
  50. isLoaded: false,
  51. didInsertElement: function () {
  52. this.initContent();
  53. },
  54. /**
  55. * Check browser and set content for listbox
  56. * @method initContent
  57. */
  58. initContent: function () {
  59. this.set('isLoaded', false);
  60. //The lazy loading for select elements supported only by Firefox and Chrome
  61. var isBrowserSupported = $.browser.mozilla || ($.browser.safari && navigator.userAgent.indexOf('Chrome') !== -1);
  62. var isLazyLoading = isBrowserSupported && this.get('hosts').length > 100;
  63. this.set('isLazyLoading', isLazyLoading);
  64. if (isLazyLoading) {
  65. //select need at least 30 hosts to have scrollbar
  66. this.set('content', this.get('hosts').slice(0, 30));
  67. } else {
  68. this.set('content', this.get('hosts'));
  69. this.set('isLoaded', true);
  70. }
  71. }.observes('parentView.warningsByHost'),
  72. /**
  73. * On click start lazy loading
  74. * @method click
  75. */
  76. click: function () {
  77. if (!this.get('isLoaded') && this.get('isLazyLoading')) {
  78. //filter out hosts, which already pushed in select
  79. var source = this.get('hosts').filter(function (_host) {
  80. return !this.get('content').contains(_host);
  81. }, this).slice();
  82. lazyloading.run({
  83. destination: this.get('content'),
  84. source: source,
  85. context: this,
  86. initSize: 30,
  87. chunkSize: 200,
  88. delay: 50
  89. });
  90. }
  91. }
  92. }),
  93. /**
  94. * List of warnings grouped by host
  95. * Same to <code>bodyController.warningsByHost</code>
  96. * @type {Ember.Enumerable}
  97. */
  98. warningsByHost: Em.computed.alias('bodyController.warningsByHost'),
  99. /**
  100. * List of all warnings
  101. * Same to <code>bodyController.warnings</code>
  102. * @type {Ember.Enumerable}
  103. */
  104. warnings: Em.computed.alias('bodyController.warnings'),
  105. /**
  106. * Selected category
  107. * @type {string}
  108. */
  109. category: 'All Hosts',
  110. /**
  111. * List of warnings for selected <code>category</code>
  112. * @type {Ember.Enumerable}
  113. */
  114. categoryWarnings: function () {
  115. var warningsByHost = this.get('warningsByHost');
  116. if (Em.isNone(warningsByHost)) return [];
  117. var category = warningsByHost.findProperty('name', this.get('category'));
  118. return Em.isNone(category) ? [] : category.warnings || [];
  119. }.property('warningsByHost', 'category'),
  120. /**
  121. * List of warnings grouped by <code>category</code>
  122. * @type {Ember.Object[]}
  123. */
  124. content: function () {
  125. var hostCheckWarnings = this.get('bodyController.hostCheckWarnings');
  126. var repoCategoryWarnings = this.get('bodyController.repoCategoryWarnings');
  127. var diskCategoryWarnings = this.get('bodyController.diskCategoryWarnings');
  128. var jdkCategoryWarnings = this.get('bodyController.jdkCategoryWarnings') || [];
  129. var thpCategoryWarnings = this.get('bodyController.thpCategoryWarnings');
  130. var categoryWarnings = this.get('categoryWarnings');
  131. var warningsArray = [
  132. Em.Object.create({
  133. warnings: thpCategoryWarnings,
  134. title: Em.I18n.t('installer.step3.hostWarningsPopup.thp'),
  135. message: Em.I18n.t('installer.step3.hostWarningsPopup.thp.message'),
  136. type: Em.I18n.t('common.issues'),
  137. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.thp'),
  138. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.enabled'),
  139. category: 'thp'
  140. }),
  141. Em.Object.create({
  142. warnings: jdkCategoryWarnings,
  143. title: Em.I18n.t('installer.step3.hostWarningsPopup.jdk'),
  144. message: Em.I18n.t('installer.step3.hostWarningsPopup.jdk.message'),
  145. type: Em.I18n.t('common.issues'),
  146. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.jdk'),
  147. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  148. category: 'jdk'
  149. }),
  150. Em.Object.create({
  151. warnings: diskCategoryWarnings,
  152. title: Em.I18n.t('installer.step3.hostWarningsPopup.disk'),
  153. message: Em.I18n.t('installer.step3.hostWarningsPopup.disk.message'),
  154. type: Em.I18n.t('common.issues'),
  155. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.disk'),
  156. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  157. category: 'disk'
  158. }),
  159. Em.Object.create({
  160. warnings: repoCategoryWarnings,
  161. title: Em.I18n.t('installer.step3.hostWarningsPopup.repositories'),
  162. message: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.message'),
  163. type: Em.I18n.t('common.issues'),
  164. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.repositories'),
  165. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.invalid'),
  166. category: 'repositories'
  167. }),
  168. Em.Object.create({
  169. warnings: categoryWarnings.filterProperty('category', 'firewall'),
  170. title: Em.I18n.t('installer.step3.hostWarningsPopup.firewall'),
  171. message: Em.I18n.t('installer.step3.hostWarningsPopup.firewall.message'),
  172. type: Em.I18n.t('common.issues'),
  173. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.firewall'),
  174. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  175. category: 'firewall'
  176. }),
  177. Em.Object.create({
  178. warnings: categoryWarnings.filterProperty('category', 'processes'),
  179. title: Em.I18n.t('installer.step3.hostWarningsPopup.process'),
  180. message: Em.I18n.t('installer.step3.hostWarningsPopup.processes.message'),
  181. type: Em.I18n.t('common.process'),
  182. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.processes'),
  183. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  184. category: 'process'
  185. }),
  186. Em.Object.create({
  187. warnings: categoryWarnings.filterProperty('category', 'packages'),
  188. title: Em.I18n.t('installer.step3.hostWarningsPopup.package'),
  189. message: Em.I18n.t('installer.step3.hostWarningsPopup.packages.message'),
  190. type: Em.I18n.t('common.package'),
  191. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.packages'),
  192. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.installed'),
  193. category: 'package'
  194. }),
  195. Em.Object.create({
  196. warnings: categoryWarnings.filterProperty('category', 'fileFolders'),
  197. title: Em.I18n.t('installer.step3.hostWarningsPopup.fileAndFolder'),
  198. message: Em.I18n.t('installer.step3.hostWarningsPopup.fileFolders.message'),
  199. type: Em.I18n.t('common.path'),
  200. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.filesAndFolders'),
  201. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  202. category: 'fileFolders'
  203. }),
  204. Em.Object.create({
  205. warnings: categoryWarnings.filterProperty('category', 'services'),
  206. title: Em.I18n.t('installer.step3.hostWarningsPopup.service'),
  207. message: Em.I18n.t('installer.step3.hostWarningsPopup.services.message'),
  208. type: Em.I18n.t('common.service'),
  209. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.services'),
  210. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.notRunning'),
  211. category: 'service'
  212. }),
  213. Em.Object.create({
  214. warnings: categoryWarnings.filterProperty('category', 'users'),
  215. title: Em.I18n.t('installer.step3.hostWarningsPopup.user'),
  216. message: Em.I18n.t('installer.step3.hostWarningsPopup.users.message'),
  217. type: Em.I18n.t('common.user'),
  218. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.users'),
  219. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  220. category: 'user'
  221. }),
  222. Em.Object.create({
  223. warnings: categoryWarnings.filterProperty('category', 'misc'),
  224. title: Em.I18n.t('installer.step3.hostWarningsPopup.misc'),
  225. message: Em.I18n.t('installer.step3.hostWarningsPopup.misc.message'),
  226. type: Em.I18n.t('installer.step3.hostWarningsPopup.misc.umask'),
  227. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.misc'),
  228. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  229. category: 'misc'
  230. }),
  231. Em.Object.create({
  232. warnings: categoryWarnings.filterProperty('category', 'alternatives'),
  233. title: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives'),
  234. message: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives.message'),
  235. type: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives.umask'),
  236. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives.empty'),
  237. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  238. category: 'alternatives'
  239. }),
  240. Em.Object.create({
  241. warnings: categoryWarnings.filterProperty('category', 'reverseLookup'),
  242. title: Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup'),
  243. message: Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.message'),
  244. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.empty'),
  245. category: 'reverseLookup'
  246. }),
  247. Em.Object.create({
  248. warnings: hostCheckWarnings,
  249. title: Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.name'),
  250. message: Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.message'),
  251. type: Em.I18n.t('common.issues'),
  252. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.empty'),
  253. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.failed'),
  254. category: 'hostNameResolution'
  255. })
  256. ];
  257. warningsArray.forEach(function (warningType) {
  258. warningType.set('isCollapsed', true);
  259. warningType.get('warnings').forEach(function (warn) {
  260. var hosts = Em.get(warn, 'hosts');
  261. if (hosts) {
  262. var hostsList = hosts.length < 11 ? hosts.join('<br>') :
  263. hosts.slice(0, 10).join('<br>') + '<br> ' +
  264. Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  265. Em.set(warn, 'hostsList', hostsList);
  266. }
  267. });
  268. });
  269. return warningsArray;
  270. }.property('category', 'warningsByHost', 'bodyController.jdkCategoryWarnings', 'bodyController.repoCategoryWarnings', 'bodyController.diskCategoryWarnings', 'bodyController.hostCheckWarnings', 'bodyController.thpCategoryWarnings'),
  271. /**
  272. * Message with info about warnings
  273. * @return {string}
  274. */
  275. warningsNotice: function () {
  276. var issuesNumber = this.get('warnings.length') + this.get('bodyController.repoCategoryWarnings.length') + this.get('bodyController.diskCategoryWarnings.length')
  277. + this.get('bodyController.jdkCategoryWarnings.length') + this.get('bodyController.hostCheckWarnings.length') + this.get('bodyController.thpCategoryWarnings.length');
  278. this.set('totalWarningsCount', issuesNumber);
  279. var issues = issuesNumber + ' ' + (issuesNumber.length === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.issue') : Em.I18n.t('installer.step3.hostWarningsPopup.issues'));
  280. var hostsCnt = this.warningHostsNamesCount();
  281. var hosts = hostsCnt + ' ' + (hostsCnt === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.host') : Em.I18n.t('installer.step3.hostWarningsPopup.hosts'));
  282. return Em.I18n.t('installer.step3.hostWarningsPopup.summary').format(issues, hosts);
  283. }.property('warnings', 'warningsByHost', 'bodyController.jdkCategoryWarnings', 'bodyController.repoCategoryWarnings', 'bodyController.diskCategoryWarnings', 'bodyController.hostCheckWarnings', 'bodyController.diskCategoryWarnings'),
  284. /**
  285. * Detailed content to show it in new window
  286. * @return {string}
  287. */
  288. contentInDetails: function () {
  289. var content = this.get('content');
  290. var newContent = '';
  291. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.header') + new Date;
  292. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.hosts');
  293. newContent += this.get('hostNamesWithWarnings').join(' ');
  294. if (content.findProperty('category', 'thp').warnings.length) {
  295. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.thp');
  296. newContent += content.findProperty('category', 'thp').warnings[0].hostsLong.join(' ');
  297. }
  298. if (content.findProperty('category', 'jdk').warnings.length) {
  299. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.jdk');
  300. newContent += content.findProperty('category', 'jdk').warnings[0].hostsLong.join('<br>');
  301. }
  302. if (content.findProperty('category', 'disk').warnings.length) {
  303. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.disk');
  304. newContent += content.findProperty('category', 'disk').warnings[0].hostsLong.join('<br>');
  305. }
  306. if (content.findProperty('category', 'repositories').warnings.length) {
  307. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.repositories');
  308. newContent += content.findProperty('category', 'repositories').warnings[0].hostsLong.join('<br>');
  309. }
  310. if (content.findProperty('category', 'hostNameResolution').warnings.length) {
  311. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.hostNameResolution');
  312. newContent += content.findProperty('category', 'hostNameResolution').warnings[0].hostsLong.join('<br>');
  313. }
  314. if (content.findProperty('category', 'firewall').warnings.length) {
  315. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.firewall');
  316. newContent += content.findProperty('category', 'firewall').warnings.mapProperty('name').join('<br>');
  317. }
  318. if (content.findProperty('category', 'fileFolders').warnings.length) {
  319. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.fileFolders');
  320. newContent += content.findProperty('category', 'fileFolders').warnings.mapProperty('name').join(' ');
  321. }
  322. if (content.findProperty('category', 'reverseLookup').warnings.length) {
  323. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.reverseLookup');
  324. newContent += content.findProperty('category', 'reverseLookup').warnings[0].hostsLong.join(' ');
  325. }
  326. if (content.findProperty('category', 'process').warnings.length) {
  327. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.process');
  328. content.findProperty('category', 'process').warnings.forEach(function (process, i) {
  329. process.hosts.forEach(function (host, j) {
  330. if (!!i || !!j) {
  331. newContent += ',';
  332. }
  333. newContent += '(' + host + ',' + process.user + ',' + process.pid + ')';
  334. });
  335. });
  336. }
  337. if (content.findProperty('category', 'package').warnings.length) {
  338. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.package');
  339. newContent += content.findProperty('category', 'package').warnings.mapProperty('name').join(' ');
  340. }
  341. if (content.findProperty('category', 'service').warnings.length) {
  342. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.service');
  343. newContent += content.findProperty('category', 'service').warnings.mapProperty('name').join(' ');
  344. }
  345. if (content.findProperty('category', 'user').warnings.length) {
  346. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.user');
  347. newContent += content.findProperty('category', 'user').warnings.mapProperty('name').join(' ');
  348. }
  349. newContent += '</p>';
  350. return newContent;
  351. }.property('content', 'warningsByHost', 'bodyController.jdkCategoryWarnings', 'bodyController.repoCategoryWarnings', 'bodyController.diskCategoryWarnings', 'bodyController.hostCheckWarnings'),
  352. didInsertElement: function () {
  353. Em.run.next(this, function () {
  354. App.tooltip(this.$("[rel='HostsListTooltip']"), {html: true, placement: "right"});
  355. App.tooltip(this.$('#process .warning-name'), {html: true, placement: "top"});
  356. });
  357. }.observes('content'),
  358. /**
  359. * Show popup with selected hostnames
  360. * @param {object} hosts
  361. * @method showHostsPopup
  362. * @return {App.ModalPopup}
  363. */
  364. showHostsPopup: function (hosts) {
  365. $('.tooltip').hide();
  366. return App.ModalPopup.show({
  367. header: Em.I18n.t('installer.step3.hostWarningsPopup.allHosts'),
  368. bodyClass: Em.View.extend({
  369. hosts: hosts.context,
  370. template: Em.Handlebars.compile('<ul>{{#each host in view.hosts}}<li>{{host}}</li>{{/each}}</ul>')
  371. }),
  372. secondary: null
  373. });
  374. },
  375. /**
  376. * Open/Close selected category
  377. * @param {object} category
  378. * @method onToggleBlock
  379. */
  380. onToggleBlock: function (category) {
  381. this.$('#' + category.context.category).toggle('blind', 500);
  382. category.context.set("isCollapsed", !category.context.get("isCollapsed"));
  383. },
  384. /**
  385. * Generate number of hosts which had warnings, avoid duplicated host names in different warnings.
  386. * @method warningHostsNamesCount
  387. * @return {number}
  388. */
  389. warningHostsNamesCount: function () {
  390. var hostNameMap = Em.Object.create();
  391. if (Em.isNone(this.get('bodyController.warningsByHost'))) return 0;
  392. var warningsByHost = this.get('bodyController.warningsByHost').slice();
  393. warningsByHost.shift();
  394. warningsByHost.forEach(function (_host) {
  395. if (_host.warnings.length) {
  396. hostNameMap[_host.name] = true;
  397. }
  398. });
  399. var repoCategoryWarnings = this.get('bodyController.repoCategoryWarnings');
  400. var diskCategoryWarnings = this.get('bodyController.diskCategoryWarnings');
  401. var jdkCategoryWarnings = this.get('bodyController.jdkCategoryWarnings');
  402. var thpCategoryWarnings = this.get('bodyController.thpCategoryWarnings');
  403. var hostResolutionWarnings = this.get('bodyController.hostCheckWarnings');
  404. if (repoCategoryWarnings.length) {
  405. repoCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  406. if (!hostNameMap[_hostName]) {
  407. hostNameMap[_hostName] = true;
  408. }
  409. });
  410. }
  411. if (diskCategoryWarnings.length) {
  412. diskCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  413. if (!hostNameMap[_hostName]) {
  414. hostNameMap[_hostName] = true;
  415. }
  416. });
  417. }
  418. if (jdkCategoryWarnings && jdkCategoryWarnings.length) {
  419. jdkCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  420. if (!hostNameMap[_hostName]) {
  421. hostNameMap[_hostName] = true;
  422. }
  423. });
  424. }
  425. if (hostResolutionWarnings && hostResolutionWarnings.length) {
  426. hostResolutionWarnings[0].hostsNames.forEach(function (_hostName) {
  427. if (!hostNameMap[_hostName]) {
  428. hostNameMap[_hostName] = true;
  429. }
  430. });
  431. }
  432. if (thpCategoryWarnings.length) {
  433. thpCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  434. if (!hostNameMap[_hostName]) {
  435. hostNameMap[_hostName] = true;
  436. }
  437. });
  438. }
  439. this.set('hostNamesWithWarnings', Em.keys(hostNameMap));
  440. return Em.keys(hostNameMap).length;
  441. },
  442. /**
  443. * Open new browser tab with detailed content
  444. * @method openWarningsInDialog
  445. */
  446. openWarningsInDialog: function () {
  447. var newWindow = window.open('');
  448. var newDocument = newWindow.document;
  449. newDocument.write(this.get('contentInDetails'));
  450. newWindow.focus();
  451. }
  452. });