step3_view.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. App.WizardStep3View = App.TableView.extend({
  21. templateName: require('templates/wizard/step3'),
  22. /**
  23. * List of hosts
  24. * Same to <code>controller.hosts</code>
  25. * @type {Ember.Enumerable}
  26. */
  27. content: [],
  28. contentObserver: function() {
  29. this.set('content', []);
  30. lazyLoading.run({
  31. initSize: 20,
  32. chunkSize: 50,
  33. delay: 50,
  34. destination: this.get('content'),
  35. source: this.get('controller.hosts'),
  36. context: this
  37. });
  38. }.observes('controller.hosts.length'),
  39. /**
  40. * Message with info about registration result
  41. * @type {string}
  42. */
  43. message:'',
  44. /**
  45. * Text to link for hosts' warnings popup
  46. * @type {string}
  47. */
  48. linkText: '',
  49. /**
  50. * Registration status
  51. * @type {string}
  52. */
  53. status: '',
  54. /**
  55. * Active category
  56. * @type {string}
  57. */
  58. selectedCategory: function() {
  59. return this.get('categories').findProperty('isActive');
  60. }.property('categories.@each.isActive'),
  61. /**
  62. * Number of visible hosts on page
  63. * @type {string}
  64. */
  65. displayLength: "25",
  66. /**
  67. * All checkboxes on page are checked
  68. * @type {bool}
  69. */
  70. pageChecked: false,
  71. isLoaded: false,
  72. /**
  73. * bootStatus category object
  74. * @type {Ember.Object}
  75. */
  76. categoryObject: Em.Object.extend({
  77. hostsCount: 0,
  78. label: function () {
  79. return "%@ (%@)".fmt(this.get('value'), this.get('hostsCount'));
  80. }.property('value', 'hostsCount'),
  81. isActive: false,
  82. itemClass: function () {
  83. return this.get('isActive') ? 'active' : '';
  84. }.property('isActive')
  85. }),
  86. /**
  87. * List of bootStatus categories
  88. * @type {categoryObject[]}
  89. */
  90. categories: function () {
  91. return [
  92. this.categoryObject.create({value: Em.I18n.t('common.all'), hostsBootStatus: 'ALL', isActive: true}),
  93. this.categoryObject.create({value: Em.I18n.t('installer.step3.hosts.status.installing'), hostsBootStatus: 'RUNNING'}),
  94. this.categoryObject.create({value: Em.I18n.t('installer.step3.hosts.status.registering'), hostsBootStatus: 'REGISTERING'}),
  95. this.categoryObject.create({value: Em.I18n.t('common.success'), hostsBootStatus: 'REGISTERED' }),
  96. this.categoryObject.create({value: Em.I18n.t('common.fail'), hostsBootStatus: 'FAILED', last: true })
  97. ];
  98. }.property(),
  99. didInsertElement: function () {
  100. this.get('controller').loadStep();
  101. },
  102. /**
  103. * Select checkboxes of hosts on page
  104. * @method onPageChecked
  105. */
  106. onPageChecked: function () {
  107. if (this.get('selectionInProgress')) return;
  108. this.get('pageContent').setEach('isChecked', this.get('pageChecked'));
  109. }.observes('pageChecked'),
  110. /**
  111. * Select checkboxes of all hosts
  112. * @method selectAll
  113. */
  114. selectAll: function () {
  115. this.get('content').setEach('isChecked', true);
  116. },
  117. /**
  118. * Reset checkbox of all hosts
  119. * @method unSelectAll
  120. */
  121. unSelectAll: function() {
  122. this.get('content').setEach('isChecked', false);
  123. },
  124. /**
  125. * Call <code>watchSelection</code> only once
  126. * @method watchSelectionOnce
  127. */
  128. watchSelectionOnce: function () {
  129. Em.run.once(this, 'watchSelection');
  130. }.observes('content.@each.isChecked', 'pageContent'),
  131. /**
  132. * Watch selection and calculate such flags as:
  133. * <ul>
  134. * <li>noHostsSelected</li>
  135. * <li>selectedHostsCount</li>
  136. * <li>pageChecked</li>
  137. * </ul>
  138. * @method watchSelection
  139. */
  140. watchSelection: function() {
  141. this.set('selectionInProgress', true);
  142. this.set('pageChecked', !!this.get('pageContent.length') && this.get('pageContent').everyProperty('isChecked', true));
  143. this.set('selectionInProgress', false);
  144. var noHostsSelected = true;
  145. var selectedHostsCount = 0;
  146. this.get('content').forEach(function(host){
  147. selectedHostsCount += host.get('isChecked') ? 1 : 0;
  148. noHostsSelected = (noHostsSelected) ? !host.get('isChecked') : noHostsSelected;
  149. });
  150. this.set('noHostsSelected', noHostsSelected);
  151. this.set('selectedHostsCount', selectedHostsCount);
  152. },
  153. /**
  154. * Call filters and counters one time
  155. * @method hostBootStatusObserver
  156. */
  157. hostBootStatusObserver: function(){
  158. Em.run.once(this, 'countCategoryHosts');
  159. Em.run.once(this, 'filter');
  160. Em.run.once(this, 'monitorStatuses');
  161. }.observes('content.@each.bootStatus'),
  162. /**
  163. * Calculate host count grouped by <code>bootStatus</code>
  164. * @method countCategoryHosts
  165. */
  166. countCategoryHosts: function () {
  167. var counters = {
  168. "RUNNING": 0,
  169. "REGISTERING": 0,
  170. "REGISTERED": 0,
  171. "FAILED": 0
  172. };
  173. this.get('content').forEach(function (host) {
  174. if (!Em.isNone(counters[host.get('bootStatus')])) {
  175. counters[host.get('bootStatus')]++;
  176. }
  177. }, this);
  178. counters["ALL"] = this.get('content.length');
  179. this.get('categories').forEach(function(category) {
  180. category.set('hostsCount', counters[category.get('hostsBootStatus')]);
  181. }, this);
  182. },
  183. /**
  184. * Filter hosts by category
  185. * @method filter
  186. */
  187. filter: function () {
  188. var self = this;
  189. Em.run.next(function () {
  190. self.doFilter();
  191. });
  192. }.observes('selectedCategory'),
  193. /**
  194. * Real filter-method
  195. * Called from <code>filter</code> in Em.run.next-wrapper
  196. * @method doFilter
  197. */
  198. doFilter: function() {
  199. var result = [];
  200. var selectedCategory = this.get('selectedCategory');
  201. if (!selectedCategory || selectedCategory.get('hostsBootStatus') === 'ALL') {
  202. result = this.get('content');
  203. } else {
  204. result = this.get('content').filterProperty('bootStatus', this.get('selectedCategory.hostsBootStatus'));
  205. }
  206. this.set('filteredContent', result);
  207. },
  208. /**
  209. * Trigger on Category click
  210. * @param {Object} event
  211. * @method selectCategory
  212. */
  213. selectCategory: function (event) {
  214. var categoryStatus = event.context.get('hostsBootStatus');
  215. this.get('categories').forEach(function (category) {
  216. category.set('isActive', (category.get('hostsBootStatus') === categoryStatus));
  217. });
  218. this.watchSelection();
  219. },
  220. /**
  221. * Select "All" hosts category
  222. * run registration of failed hosts again
  223. * @method retrySelectedHosts
  224. */
  225. retrySelectedHosts: function () {
  226. var eventObject = {context: Em.Object.create({hostsBootStatus: 'ALL'})};
  227. this.selectCategory(eventObject);
  228. this.get('controller').retrySelectedHosts();
  229. },
  230. /**
  231. * Update <code>status</code>, <code>linkText</code>, <code>message</code> according to hosts statuses
  232. * @method monitorStatuses
  233. */
  234. monitorStatuses: function() {
  235. var hosts = this.get('controller.bootHosts');
  236. var failedHosts = hosts.filterProperty('bootStatus', 'FAILED').length;
  237. if (hosts.length === 0) {
  238. this.set('status', 'alert-warn');
  239. this.set('linkText', '');
  240. this.set('message', Em.I18n.t('installer.step3.warnings.missingHosts'));
  241. }
  242. else {
  243. if (!this.get('controller.isWarningsLoaded')) {
  244. this.set('status', 'alert-info');
  245. this.set('linkText', '');
  246. this.set('message', Em.I18n.t('installer.step3.warning.loading'));
  247. }
  248. else {
  249. if (this.get('controller.isHostHaveWarnings') || this.get('controller.repoCategoryWarnings.length') || this.get('controller.diskCategoryWarnings.length') || this.get('controller.jdkCategoryWarnings.length') || this.get('controller.hostCheckWarnings.length')) {
  250. this.set('status', 'alert-warn');
  251. this.set('linkText', Em.I18n.t('installer.step3.warnings.linkText'));
  252. this.set('message', Em.I18n.t('installer.step3.warnings.fails').format(hosts.length - failedHosts));
  253. }
  254. else {
  255. this.set('status', 'alert-success');
  256. this.set('linkText', Em.I18n.t('installer.step3.noWarnings.linkText'));
  257. if (failedHosts == 0) {
  258. // all are ok
  259. this.set('message', Em.I18n.t('installer.step3.warnings.noWarnings').format(hosts.length));
  260. }
  261. else {
  262. if (failedHosts == hosts.length) {
  263. // all failed
  264. this.set('status', 'alert-warn');
  265. this.set('linkText', '');
  266. this.set('message', Em.I18n.t('installer.step3.warnings.allFailed').format(failedHosts));
  267. }
  268. else {
  269. // some failed
  270. this.set('message', Em.I18n.t('installer.step3.warnings.someWarnings').format((hosts.length - failedHosts), failedHosts));
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }.observes('controller.isWarningsLoaded','controller.hostCheckWarnings', 'controller.isHostHaveWarnings', 'controller.repoCategoryWarnings', 'controller.diskCategoryWarnings', 'controller.jdkCategoryWarnings')
  277. });
  278. //todo: move it inside WizardStep3View
  279. App.WizardHostView = Em.View.extend({
  280. tagName: 'tr',
  281. classNameBindings: ['hostInfo.bootStatus'],
  282. /**
  283. * Host from parent view
  284. * @type {Object}
  285. */
  286. hostInfo: null,
  287. /**
  288. * @type {bool}
  289. */
  290. isRetryable: function() {
  291. // return ['FAILED'].contains(this.get('hostInfo.bootStatus'));
  292. return false;
  293. }.property('hostInfo.bootStatus'),
  294. /**
  295. * Remove selected host
  296. * @method remove
  297. */
  298. remove: function () {
  299. this.get('controller').removeHost(this.get('hostInfo'));
  300. },
  301. /**
  302. * Retry register selected host
  303. * @method retry
  304. */
  305. retry: function() {
  306. this.get('controller').retryHost(this.get('hostInfo'));
  307. }
  308. });