rolling_restart_view.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. var numberUtils = require('utils/number_utils');
  19. /**
  20. * View content of the rolling restart dialog.
  21. *
  22. * Callers provide the context in which this dialog is invoked.
  23. */
  24. App.RollingRestartView = Em.View.extend({
  25. templateName : require('templates/common/rolling_restart_view'),
  26. /**
  27. * Component name for components that should be restarted
  28. * @type {String}
  29. */
  30. hostComponentName : null,
  31. /**
  32. * Service name for components that should be restarted
  33. * @type {String}
  34. */
  35. serviceName : null,
  36. /**
  37. * If service is in Maintenance Mode
  38. * @type {bool}
  39. */
  40. isServiceInMM: false,
  41. /**
  42. * If true service will be put in Maintenance mode before rolling restart
  43. * @type {bool}
  44. */
  45. turnOnMm: false,
  46. /**
  47. * Restart only components with <code>staleConfigs</code>
  48. * @type {bool}
  49. */
  50. staleConfigsOnly : false,
  51. /**
  52. * We should do rolling restart for components if we run
  53. * restart for service and service is in Maintenance mode
  54. * @type {bool}
  55. */
  56. skipMaintenance: false,
  57. /**
  58. * Count of host components in one batch
  59. * @type {Number}
  60. */
  61. batchSize : -1,
  62. /**
  63. * Delay between batches
  64. * @type {Number}
  65. */
  66. interBatchWaitTimeSeconds : -1,
  67. /**
  68. * @type {Number}
  69. */
  70. tolerateSize : -1,
  71. /**
  72. * Shows if all needed info is loaded and initialized
  73. * @type {Bool}
  74. */
  75. isLoaded: false,
  76. /**
  77. * List of error in batch-request properties
  78. * @type {Array}
  79. */
  80. errors : [],
  81. /**
  82. * Set initial values for batch-request properties
  83. */
  84. initialize : function() {
  85. if (this.get('batchSize') == -1 && this.get('interBatchWaitTimeSeconds') == -1 && this.get('tolerateSize') == -1) {
  86. var restartCount = this.get('restartHostComponents.length');
  87. var batchSize = 1;
  88. if (restartCount > 10) {
  89. batchSize = Math.ceil(restartCount / 10);
  90. }
  91. var tolerateCount = batchSize;
  92. this.set('batchSize', batchSize);
  93. this.set('tolerateSize', tolerateCount);
  94. this.set('interBatchWaitTimeSeconds', 120);
  95. this.set('isLoaded', true);
  96. }
  97. },
  98. /**
  99. * Validate batch-request properties
  100. * List of errors is saved to <code>errors</code>
  101. */
  102. validate : function() {
  103. var displayName = this.get('hostComponentDisplayName');
  104. var totalCount = this.get('restartHostComponents.length');
  105. var bs = this.get('batchSize');
  106. var ts = this.get('tolerateSize');
  107. var wait = this.get('interBatchWaitTimeSeconds');
  108. var errors = [];
  109. if (totalCount < 1) {
  110. errors.push(Em.I18n.t('rollingrestart.dialog.msg.noRestartHosts').format(displayName));
  111. } else {
  112. var bsError = numberUtils.validateInteger(bs, 1, totalCount);
  113. var tsError = numberUtils.validateInteger(ts, 0, totalCount);
  114. if (bsError != null) {
  115. errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.batchsize').format(bsError));
  116. }
  117. if (tsError != null) {
  118. errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.toleratesize').format(tsError));
  119. }
  120. }
  121. var waitError = numberUtils.validateInteger(wait, 0, NaN);
  122. if (waitError != null) {
  123. errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.waitTime').format(waitError));
  124. }
  125. this.set('errors', errors);
  126. }.observes('batchSize', 'interBatchWaitTimeSeconds', 'tolerateSize', 'restartHostComponents', 'hostComponentDisplayName'),
  127. /**
  128. * Formatted <code>hostComponentName</code>
  129. * @type {String}
  130. */
  131. hostComponentDisplayName : function() {
  132. return App.format.role(this.get('hostComponentName'));
  133. }.property('hostComponentName'),
  134. /**
  135. * List of all host components
  136. * @type {Array}
  137. */
  138. allHostComponents : [],
  139. /**
  140. * List of host components without components in out-of-service state
  141. * @type {Array}
  142. */
  143. nonMaintainanceHostComponents : function() {
  144. return this.get('allHostComponents').filterProperty('passiveState', 'OFF')
  145. }.property('allHostComponents', 'allHostComponents.@each.passiveState'),
  146. /**
  147. * List of host components with host in Maintenance mode
  148. * @type {Array}
  149. */
  150. componentsWithMaintenanceHost: function() {
  151. return this.get('allHostComponents').filterProperty('hostPassiveState', 'ON');
  152. }.property('allHostComponents', 'allHostComponents.@each.hostPassiveState'),
  153. /**
  154. * List of host components without components in out-of-service state
  155. * If <code>staleConfigsOnly</code> is true, components with <code>staleConfigs</code> = false are also filtered
  156. * @type {Array}
  157. */
  158. restartHostComponents: function () {
  159. var hostComponents = (this.get('skipMaintenance')) ? this.get('allHostComponents') : this.get('nonMaintainanceHostComponents');
  160. if (this.get('staleConfigsOnly')) {
  161. hostComponents = hostComponents.filterProperty('staleConfigs');
  162. }
  163. return hostComponents;
  164. }.property('nonMaintainanceHostComponents', 'staleConfigsOnly'),
  165. /**
  166. * @type {String}
  167. */
  168. suggestTurnOnMaintenanceMsg : function() {
  169. if (!this.get('isServiceInMM')) {
  170. return Em.I18n.t('rollingrestart.dialog.msg.serviceNotInMM').format(this.get('serviceName'));
  171. } else {
  172. return null;
  173. }
  174. }.property('isServiceInMM'),
  175. /**
  176. * @type {String}
  177. */
  178. restartMessage : function() {
  179. return Em.I18n.t('rollingrestart.dialog.msg.restart').format(this.get('hostComponentDisplayName'))
  180. }.property('hostComponentDisplayName'),
  181. /**
  182. * @type {String}
  183. */
  184. maintainanceMessage : function() {
  185. var count = this.get('componentsWithMaintenanceHost.length');
  186. if (count > 0) {
  187. var name = this.get('hostComponentDisplayName');
  188. if (count > 1) {
  189. return Em.I18n.t('rollingrestart.dialog.msg.maintainance.plural').format(count, name)
  190. }
  191. return Em.I18n.t('rollingrestart.dialog.msg.maintainance').format(count, name)
  192. }
  193. return null;
  194. }.property('componentsWithMaintenanceHost', 'hostComponentDisplayName'),
  195. /**
  196. * @type {String}
  197. */
  198. batchSizeMessage : function() {
  199. return Em.I18n.t('rollingrestart.dialog.msg.componentsAtATime').format(this.get('hostComponentDisplayName'));
  200. }.property('hostComponentDisplayName'),
  201. /**
  202. * @type {String}
  203. */
  204. staleConfigsOnlyMessage : function() {
  205. return Em.I18n.t('rollingrestart.dialog.msg.staleConfigsOnly').format(this.get('hostComponentDisplayName'));
  206. }.property('hostComponentDisplayName')
  207. });