versions_view.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 stringUtils = require('utils/string_utils');
  20. App.MainAdminStackVersionsView = Em.View.extend({
  21. templateName: require('templates/main/admin/stack_upgrade/versions'),
  22. /**
  23. * update timer
  24. * @type {number|null}
  25. * @default null
  26. */
  27. updateTimer: null,
  28. /**
  29. * @type {Array}
  30. */
  31. categories: [
  32. Em.Object.create({
  33. labelKey: 'admin.stackVersions.filter.all',
  34. value: '',
  35. isSelected: true
  36. }),
  37. Em.Object.create({
  38. labelKey: 'admin.stackVersions.filter.notInstalled',
  39. value: 'NOT_INSTALLED',
  40. isSelected: false
  41. }),
  42. Em.Object.create({
  43. labelKey: 'admin.stackVersions.filter.installed',
  44. value: 'INSTALLED',
  45. isSelected: false
  46. }),
  47. Em.Object.create({
  48. labelKey: 'admin.stackVersions.filter.upgradeReady',
  49. value: 'UPGRADE_READY',
  50. isSelected: false
  51. }),
  52. Em.Object.create({
  53. labelKey: 'admin.stackVersions.filter.current',
  54. value: 'CURRENT',
  55. isSelected: false
  56. })
  57. ],
  58. didInsertElement: function () {
  59. this.observesCategories();
  60. },
  61. /**
  62. * update categories labels
  63. */
  64. observesCategories: function() {
  65. var versions = this.get('versions');
  66. this.get('categories').forEach(function (category) {
  67. category.set('label', Em.I18n.t(category.labelKey).format(this.filterBy(versions, category).length));
  68. }, this);
  69. }.observes('versions.@each.status'),
  70. /**
  71. * select category
  72. * @param event
  73. */
  74. selectCategory: function (event) {
  75. this.get('categories').filterProperty('isSelected').setEach('isSelected', false);
  76. event.context.set('isSelected', true);
  77. },
  78. /**
  79. * @type {object}
  80. */
  81. selectedCategory: function(){
  82. return this.get('categories').findProperty('isSelected');
  83. }.property('categories.@each.isSelected'),
  84. /**
  85. * @type {Em.Array}
  86. */
  87. repoVersions: App.RepositoryVersion.find(),
  88. /**
  89. * @type {Em.Array}
  90. */
  91. stackVersions: App.StackVersion.find(),
  92. /**
  93. * formatted versions
  94. * @type {Array}
  95. */
  96. versions: function () {
  97. var versions = this.get('repoVersions').map(function (version) {
  98. var versionFormatted = Em.Object.create({
  99. id: version.get('id'),
  100. displayName: version.get('displayName'),
  101. repositoryVersion: version.get('repositoryVersion'),
  102. stackVersionType: version.get('stackVersionType'),
  103. stackVersionNumber: version.get('stackVersionNumber'),
  104. status: 'INIT',
  105. notInstalledHosts: [],
  106. installedHosts: [],
  107. currentHosts: []
  108. });
  109. if (version.get('stackVersion')) {
  110. versionFormatted.set('status', version.get('stackVersion.state'));
  111. versionFormatted.set('notInstalledHosts', version.get('stackVersion.notInstalledHosts'));
  112. versionFormatted.set('installedHosts', version.get('stackVersion.installedHosts'));
  113. versionFormatted.set('currentHosts', version.get('stackVersion.currentHosts'));
  114. }
  115. return versionFormatted;
  116. });
  117. versions.sort(function (a, b) {
  118. return stringUtils.compareVersions(a.get('repositoryVersion'), b.get('repositoryVersion'));
  119. });
  120. return versions;
  121. }.property('repoVersions.length', 'stackVersions.@each.state'),
  122. /**
  123. * @type {Array}
  124. */
  125. filteredVersions: function () {
  126. return this.filterBy(this.get('versions'), this.get('selectedCategory'))
  127. }.property('selectedCategory', 'versions.@each.status'),
  128. /**
  129. * filter versions by category
  130. * @param versions
  131. * @param filter
  132. * @return {Array}
  133. */
  134. filterBy: function (versions, filter) {
  135. var currentVersion = this.get('controller.currentVersion');
  136. if (filter && filter.get('value') && this.get('controller.isLoaded')) {
  137. return versions.filter(function (version) {
  138. if (version.get('status') === 'INSTALLED' && filter.get('value') === 'UPGRADE_READY') {
  139. return stringUtils.compareVersions(version.get('repositoryVersion'), Em.get(currentVersion, 'repository_version')) === 1;
  140. } else if (filter.get('value') === 'NOT_INSTALLED') {
  141. return ['INIT', 'INSTALL_FAILED', 'INSTALLING', 'OUT_OF_SYNC'].contains(version.get('status'));
  142. } else {
  143. return version.get('status') === filter.get('value');
  144. }
  145. }, this);
  146. }
  147. return versions;
  148. },
  149. /**
  150. * route to versions in Admin View
  151. */
  152. goToVersions: function () {
  153. App.showConfirmationPopup(function () {
  154. window.location.replace('/views/ADMIN_VIEW/1.0.0/INSTANCE/#/stackVersions');
  155. },
  156. Em.I18n.t('admin.stackVersions.manageVersions.popup.body'),
  157. null,
  158. Em.I18n.t('admin.stackVersions.manageVersions'));
  159. },
  160. /**
  161. * load ClusterStackVersions data
  162. */
  163. willInsertElement: function () {
  164. this.doPolling();
  165. },
  166. /**
  167. * stop polling upgrade state
  168. */
  169. willDestroyElement: function () {
  170. clearTimeout(this.get('updateTimer'));
  171. },
  172. /**
  173. * poll Upgrade state
  174. */
  175. doPolling: function () {
  176. var self = this;
  177. this.set('updateTimer', setTimeout(function () {
  178. //skip call if Upgrade wizard opened
  179. if (App.router.get('updateController').get('isWorking')) {
  180. self.get('controller').load().done(function () {
  181. self.set('controller.isLoaded', true);
  182. self.doPolling();
  183. });
  184. }
  185. }, App.bgOperationsUpdateInterval));
  186. }
  187. });