stack_and_upgrade_view.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.MainAdminStackAndUpgradeView = Em.View.extend({
  21. templateName: require('templates/main/admin/stack_and_upgrade'),
  22. /**
  23. * update timer
  24. * @type {number|null}
  25. * @default null
  26. */
  27. updateTimer: null,
  28. /**
  29. * label with number of HEALTHY hosts
  30. * @type {String}
  31. */
  32. hostsOnlineLabel: function () {
  33. var hostsCountMap = App.router.get('mainHostController.hostsCountMap');
  34. return Em.I18n.t('admin.stackUpgrade.hostsOnline').format(hostsCountMap.HEALTHY, hostsCountMap.TOTAL);
  35. }.property('App.router.mainHostController.hostsCountMap'),
  36. /**
  37. * label that depict current upgrade process state
  38. * @type {String}
  39. */
  40. upgradeStateLabel: function () {
  41. switch (App.get('upgradeState')) {
  42. case 'INIT':
  43. return (this.get('controller.targetVersions.length') > 0) ? Em.I18n.t('admin.stackUpgrade.state.available') : "";
  44. case 'PENDING':
  45. case 'IN_PROGRESS':
  46. return Em.I18n.t('admin.stackUpgrade.state.inProgress');
  47. case 'STOPPED':
  48. return Em.I18n.t('admin.stackUpgrade.state.stopped');
  49. case 'COMPLETED':
  50. return Em.I18n.t('admin.stackUpgrade.state.completed');
  51. default:
  52. return "";
  53. }
  54. }.property('App.upgradeState', 'controller.targetVersions'),
  55. /**
  56. * load ClusterStackVersions data
  57. */
  58. willInsertElement: function () {
  59. var self = this;
  60. if (App.get('supports.stackUpgrade')) {
  61. self.get('controller').loadVersionsInfo();
  62. self.doPolling();
  63. }
  64. },
  65. /**
  66. * stop polling upgrade state
  67. */
  68. willDestroyElement: function () {
  69. clearTimeout(this.get('updateTimer'));
  70. },
  71. /**
  72. * poll upgrade state,
  73. */
  74. doPolling: function () {
  75. var self = this;
  76. this.set('updateTimer', setTimeout(function () {
  77. self.get('controller').loadUpgradeData(true);
  78. self.doPolling();
  79. }, App.bgOperationsUpdateInterval));
  80. },
  81. /**
  82. * box that display info about current version
  83. * @type {Em.View}
  84. */
  85. sourceVersionView: App.UpgradeVersionBoxView.extend({
  86. version: function () {
  87. return this.get('controller.currentVersion');
  88. }.property('controller.currentVersion'),
  89. btnClass: 'btn-danger',
  90. /**
  91. * method of controller called on click of source version button
  92. * @type {string}
  93. * @default null
  94. */
  95. method: null,
  96. /**
  97. * label of source version button
  98. * @type {string}
  99. */
  100. label: "",
  101. buttonObserver: function () {
  102. this.set('method', App.get('upgradeState') !== 'INIT' && 'downgrade');
  103. this.set('label', App.get('upgradeState') !== 'INIT' && Em.I18n.t('common.downgrade'));
  104. }.observes('App.upgradeState'),
  105. hostsCount: function () {
  106. return this.get('version.host_states.CURRENT.length');
  107. }.property('version.host_states.CURRENT.length')
  108. }),
  109. /**
  110. * box that display info about target versions
  111. * @type {Em.View}
  112. */
  113. targetVersionView: App.UpgradeVersionBoxView.extend({
  114. /**
  115. * method of controller called on click of target version button
  116. * @type {string}
  117. * @default null
  118. */
  119. method: null,
  120. /**
  121. * label of target version button
  122. * @type {string}
  123. */
  124. label: "",
  125. versions: function () {
  126. return this.get('controller.targetVersions');
  127. }.property('controller.targetVersions'),
  128. btnClass: 'btn-success',
  129. versionName: function () {
  130. if (this.get('versions.length') === 0) return Em.I18n.t('admin.stackUpgrade.state.notAvailable');
  131. return this.get('controller.upgradeVersion');
  132. }.property('controller.upgradeVersion', 'showSelect'),
  133. showSelect: function () {
  134. return this.get('versions.length') > 0 && App.get('upgradeState') === 'INIT';
  135. }.property('versions.length', 'App.upgradeState'),
  136. /**
  137. * fix for Ember.Select
  138. * if Ember.Select initiated with empty content then after content is populated no option selected
  139. */
  140. initSelect: function () {
  141. if (this.get('versions.length') > 0) this.set('version', this.get('versionsSelectContent')[0]);
  142. }.observes('versions.length'),
  143. version: null,
  144. versionsSelectContent: function () {
  145. return this.get('versions').map(function (version) {
  146. return {
  147. label: version.repository_name,
  148. value: version.repository_version
  149. }
  150. });
  151. }.property('versions.length'),
  152. /**
  153. * button properties:
  154. * - method of controller which will be called on click <code>method</code>
  155. * - label <code>label</code>
  156. * @type {Object}
  157. */
  158. buttonObserver: function () {
  159. var method = null,
  160. label = "",
  161. versions = this.get('versions');
  162. switch (App.get('upgradeState')) {
  163. case 'INIT':
  164. if (this.get('versions.length') > 0) {
  165. label = Em.I18n.t('common.upgrade');
  166. method = 'runPreUpgradeCheck';
  167. }
  168. break;
  169. case 'PENDING':
  170. case 'IN_PROGRESS':
  171. label = Em.I18n.t('admin.stackUpgrade.state.upgrading');
  172. method = 'openUpgradeDialog';
  173. break;
  174. case 'STOPPED':
  175. label = Em.I18n.t('admin.stackUpgrade.state.resume');
  176. method = 'resumeUpgrade';
  177. break;
  178. case 'COMPLETED':
  179. label = Em.I18n.t('common.finalize');
  180. method = 'finalize';
  181. break;
  182. }
  183. this.set('method', method);
  184. this.set('label', label);
  185. }.observes('versions.length', 'App.upgradeState')
  186. })
  187. });