step9_view.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 date = require('utils/date/date');
  20. App.WizardStep9View = App.TableView.extend({
  21. templateName: require('templates/wizard/step9'),
  22. /**
  23. * Overall progress-bar color
  24. * @type {string}
  25. */
  26. barColor: '',
  27. /**
  28. * Overall result message
  29. * @type {string}
  30. */
  31. resultMsg: '',
  32. /**
  33. * Overall message color
  34. * @type {string}
  35. */
  36. resultMsgColor: '',
  37. /**
  38. * When progress is 100, step is completed
  39. * @type {bool}
  40. */
  41. isStepCompleted: Em.computed.equal('controller.progress', '100'),
  42. /**
  43. * Number of visible hosts
  44. * @type {string}
  45. */
  46. displayLength: "25",
  47. /**
  48. * Same to <code>controller.hosts</code>
  49. * @type {object[]}
  50. */
  51. content: function () {
  52. return this.get('controller.hosts');
  53. }.property('controller.hosts'),
  54. /**
  55. * Active category
  56. * @type {Ember.Object}
  57. */
  58. selectedCategory: Em.computed.findBy('categories', 'isActive', true),
  59. /**
  60. * Ember Object category. This object also contains
  61. * <code>
  62. * hostStatus: {String} A valid status of a host.
  63. * Used to filter hosts in that status.
  64. * hostsCount: {Int} Dynamic count of hosts displayed in the category label
  65. * label : {String} status and hosts in that status displayed which consists as a category on the page
  66. * isActive: {boolean} Gets set when the category is selected/clicked by the user
  67. * itemClass: {computed property} Binds the category link to active class when user clicks on the link
  68. * </code>
  69. */
  70. categoryObject: Em.Object.extend({
  71. hostsCount: 0,
  72. label: Em.computed.format('{0} ({1})', 'value', 'hostsCount'),
  73. isActive: false,
  74. itemClass: Em.computed.ifThenElse('isActive', 'active', '')
  75. }),
  76. /**
  77. * Domputed property creates the category objects on the load of the page and sets 'All' as the active category
  78. * @Returns {Em.Object[]} All created categories which are binded and iterated in the template
  79. */
  80. categories: function () {
  81. return [
  82. this.categoryObject.create({value: Em.I18n.t('common.all'), hostStatus: 'all', isActive: true}),
  83. this.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.inProgress'), hostStatus: 'inProgress'}),
  84. this.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.warning'), hostStatus: 'warning'}),
  85. this.categoryObject.create({value: Em.I18n.t('common.success'), hostStatus: 'success'}),
  86. this.categoryObject.create({value: Em.I18n.t('common.fail'), hostStatus: 'failed', last: true })
  87. ];
  88. }.property(),
  89. /**
  90. * True if <code>controller.hostsWithHeartbeatLost</code> contains some values
  91. * @type {bool}
  92. */
  93. isHostHeartbeatLost: Em.computed.bool('controller.hostsWithHeartbeatLost.length'),
  94. /**
  95. * Css-string to overall progress-bar width-property
  96. * @type {string}
  97. */
  98. barWidth: Em.computed.format('width: {0}%;', 'controller.progress'),
  99. /**
  100. * Filter hosts info shown up on bottom of the box. Set by filter function, when 'seletedCategory' changed
  101. * @type {string}
  102. */
  103. filteredHostsInfo: '',
  104. /**
  105. * Message for overall progress
  106. * @type {string}
  107. */
  108. progressMessage: Em.computed.i18nFormat('installer.step9.overallProgress', 'controller.progress'),
  109. /**
  110. * Run <code>countCategoryHosts</code>, <code>filter</code> only once
  111. * @method hostStatusObserver
  112. */
  113. hostStatusObserver: function(){
  114. Em.run.once(this, 'countCategoryHosts');
  115. Em.run.once(this, 'filter');
  116. }.observes('content.@each.status'),
  117. /**
  118. * Count each category hosts to update label
  119. * @method countCategoryHosts
  120. */
  121. countCategoryHosts: function () {
  122. var counters = {
  123. "info": 0,
  124. "pending": 0,
  125. "in_progress": 0,
  126. "heartbeat_lost": 0,
  127. "warning": 0,
  128. "success": 0,
  129. "failed": 0
  130. };
  131. this.get('content').forEach(function (host) {
  132. if (counters[host.get('status')] !== undefined) {
  133. counters[host.get('status')]++;
  134. }
  135. }, this);
  136. counters["all"] = this.get('content.length');
  137. counters["inProgress"] = counters["info"] + counters["pending"] + counters["in_progress"];
  138. counters["failed"] += counters["heartbeat_lost"];
  139. this.get('categories').forEach(function(category) {
  140. category.set('hostsCount', counters[category.get('hostStatus')]);
  141. }, this);
  142. },
  143. /**
  144. * Filter hosts by category
  145. * @method filter
  146. */
  147. filter: function () {
  148. var self = this;
  149. Em.run.next(function () {
  150. self.doFilter();
  151. });
  152. }.observes('selectedCategory'),
  153. /**
  154. * Real filter-method
  155. * Called from <code>filter</code> in Em.run.next-wrapper
  156. * @method doFilter
  157. */
  158. doFilter: function() {
  159. var result = [];
  160. var content = this.get('content');
  161. var selectedCategory = this.get('selectedCategory');
  162. if (!selectedCategory || selectedCategory.get('hostStatus') === 'all') {
  163. result = content;
  164. } else if (selectedCategory.get('hostStatus') == 'inProgress') {
  165. result = content.filter(function (_host) {
  166. return (_host.get('status') == 'info' || _host.get('status') == 'pending' || _host.get('status') == 'in_progress');
  167. });
  168. } else if (selectedCategory.get('hostStatus') == 'failed') {
  169. result = content.filter(function (_host) {
  170. return (_host.get('status') == 'failed' || _host.get('status') == 'heartbeat_lost');
  171. });
  172. } else {
  173. result = content.filterProperty('status', selectedCategory.get('hostStatus'));
  174. }
  175. this.set('filteredContent', result);
  176. this.set('filteredHostsInfo', Em.I18n.t('installer.step9.hosts.filteredHostsInfo').format(result.get('length'), content.get('length')));
  177. },
  178. /**
  179. * On click handler for 'show all' link
  180. * @method showAllHosts
  181. */
  182. showAllHosts: function () {
  183. this.get('categories').forEach(function (category) {
  184. category.set('isActive', (category.get('hostStatus') === 'all'));
  185. });
  186. },
  187. /**
  188. * Trigger on Category click
  189. * @param {Object} event
  190. * @method selectCategory
  191. */
  192. selectCategory: function (event) {
  193. var categoryStatus = event.context.get('hostStatus');
  194. this.get('categories').forEach(function (category) {
  195. category.set('isActive', (category.get('hostStatus') === categoryStatus));
  196. });
  197. },
  198. didInsertElement: function () {
  199. this.onStatus();
  200. this.get('controller').navigateStep();
  201. App.get('router').set('transitionInProgress', false);
  202. },
  203. /**
  204. * Set <code>resultMsg</code>, <code>resultMsg</code>, <code>resultMsgColor</code> according to
  205. * <code>controller.status</code>, <code>controller.startCallFailed</code>, <code>isHostHeartbeatLost</code>
  206. * @method onStatus
  207. */
  208. onStatus: function () {
  209. if (this.get('controller.status') === 'info') {
  210. this.set('resultMsg', '');
  211. this.set('barColor', 'progress-info');
  212. } else if (this.get('controller.status') === 'warning') {
  213. this.set('barColor', 'progress-warning');
  214. this.set('resultMsg', Em.I18n.t('installer.step9.status.warning'));
  215. this.set('resultMsgColor', 'alert-warning');
  216. } else if (this.get('controller.status') === 'failed') {
  217. this.set('barColor', 'progress-danger');
  218. this.set('resultMsgColor', 'alert-error');
  219. if (this.get('isHostHeartbeatLost')) {
  220. // When present requests succeeds but some host components are in UNKNOWN or INSTALL_FAILED state and
  221. // hosts are in HEARTBEAT_LOST state
  222. this.set('resultMsg', Em.I18n.t('installer.step9.status.hosts.heartbeat_lost').format(this.get('controller.hostsWithHeartbeatLost').length));
  223. } else if (this.get('controller.startCallFailed')) {
  224. this.set('resultMsg', Em.I18n.t('installer.step9.status.start.services.failed'));
  225. } else {
  226. this.set('resultMsg', Em.I18n.t('installer.step9.status.failed'));
  227. }
  228. } else if (this.get('controller.status') === 'success') {
  229. this.set('barColor', 'progress-success');
  230. this.set('resultMsg', this.get('controller.content.cluster.status') === 'START_SKIPPED' ? Em.I18n.t('installer.step9.status.skipStartSuccess') : Em.I18n.t('installer.step9.status.success'));
  231. this.set('resultMsgColor', 'alert-success');
  232. }
  233. }.observes('controller.status', 'controller.content.cluster.status', 'controller.startCallFailed','isHostHeartbeatLost'),
  234. /**
  235. * Show popup with info about failed hosts
  236. * @return {App.ModalPopup}
  237. * @method hostWithInstallFailed
  238. */
  239. hostWithInstallFailed: function () {
  240. var controller = this.get('controller');
  241. return App.ModalPopup.show({
  242. header: Em.I18n.t('installer.step9.host.heartbeat_lost.header'),
  243. classNames: ['sixty-percent-width-modal'],
  244. autoHeight: false,
  245. secondary: null,
  246. bodyClass: Em.View.extend({
  247. templateName: require('templates/wizard/step9/step9_install_host_popup'),
  248. c: controller,
  249. failedHosts: function () {
  250. return controller.get('hostsWithHeartbeatLost');
  251. }.property()
  252. })
  253. });
  254. }
  255. });
  256. function hostStatus(statuses) {
  257. return Em.computed('isHostCompleted', 'obj.status', function () {
  258. statuses = Em.makeArray(statuses);
  259. return this.get('isHostCompleted') && statuses.contains(this.get('obj.status'));
  260. });
  261. }
  262. App.HostStatusView = Em.View.extend({
  263. tagName: 'tr',
  264. /**
  265. * Current host
  266. * @type {Em.Object}
  267. */
  268. obj: null,
  269. /**
  270. * wizardStep9Controller
  271. * @type {App.WizardStep9Controller}
  272. */
  273. controller: null,
  274. /**
  275. * Progress-bar color for current host
  276. * @type {string}
  277. */
  278. barColor: '',
  279. /**
  280. * Css-string to progress-bar width-property
  281. * @type {string}
  282. */
  283. barWidth: Em.computed.format('width: {0}%;','obj.progress'),
  284. /**
  285. * Is current host failed
  286. * @type {bool}
  287. */
  288. isFailed: hostStatus(['failed', 'heartbeat_lost']),
  289. /**
  290. * Is current host successfully installed
  291. * @type {bool}
  292. */
  293. isSuccess: hostStatus('success'),
  294. /**
  295. * Current host has warnings
  296. * @type {bool}
  297. */
  298. isWarning: hostStatus('warning'),
  299. /**
  300. * Current host completed all its tasks
  301. * @type {bool}
  302. */
  303. isHostCompleted: function () {
  304. return this.get('obj.progress') == 100;
  305. }.property('obj.progress'),
  306. didInsertElement: function () {
  307. this.onStatus();
  308. },
  309. /**
  310. * Set <code>barColor</code>, <code>obj.progress</code>, <code>obj.message</code> according to
  311. * <code>obj.status</code>, <code>obj.progress</code>, <code>controller.progress</code>
  312. * @method onStatus
  313. */
  314. onStatus: function () {
  315. if (this.get('obj.status') === 'info') {
  316. this.set('barColor', 'progress-info');
  317. } else if (this.get('obj.status') === 'warning') {
  318. this.set('barColor', 'progress-warning');
  319. if (this.get('obj.progress') === '100') {
  320. this.set('obj.message', Em.I18n.t('installer.step9.host.status.warning'));
  321. }
  322. } else if (this.get('obj.status') === 'failed') {
  323. this.set('barColor', 'progress-danger');
  324. if (this.get('obj.progress') === '100') {
  325. this.set('obj.message', Em.I18n.t('installer.step9.host.status.failed'));
  326. }
  327. } else if (this.get('obj.status') === 'heartbeat_lost') {
  328. this.set('barColor', 'progress-danger');
  329. if (this.get('obj.progress') === '100') {
  330. this.set('obj.message', Em.I18n.t('installer.step9.host.heartbeat_lost'));
  331. }
  332. } else if (this.get('obj.status') === 'success' && this.get('isHostCompleted') && parseInt(this.get('controller.progress')) > 34) {
  333. this.set('barColor', 'progress-success');
  334. this.set('obj.message', Em.I18n.t('installer.step9.host.status.success'));
  335. }
  336. }.observes('obj.status', 'obj.progress', 'controller.progress'),
  337. /**
  338. * Show popup with host logs
  339. * @return {App.ModalPopup}
  340. * @method hostLogPopup
  341. */
  342. hostLogPopup: function () {
  343. var controller = this.get('controller');
  344. var host = this.get('obj');
  345. return App.ModalPopup.show({
  346. header: host.get('name'),
  347. classNames: ['sixty-percent-width-modal'],
  348. autoHeight: false,
  349. secondary: null,
  350. /**
  351. * Current host
  352. * @type {Em.Object}
  353. */
  354. host: host,
  355. /**
  356. * wizardStep9Controller
  357. * @type {App.WizardStep9Controller}
  358. */
  359. c: controller,
  360. onClose: function () {
  361. this.set('c.currentOpenTaskId', 0);
  362. this.hide();
  363. },
  364. bodyClass: App.WizardStep9HostLogPopupBodyView
  365. });
  366. }
  367. });