rolling_restart_view.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /**
  19. * View content of the rolling restart dialog.
  20. *
  21. * Callers provide the context in which this dialog is invoked.
  22. */
  23. App.RollingRestartView = Em.View.extend({
  24. templateName : require('templates/common/rolling_restart_view'),
  25. hostComponentName : null,
  26. staleConfigsOnly : false,
  27. batchSize : -1,
  28. interBatchWaitTimeSeconds : -1,
  29. tolerateSize : -1,
  30. errors : null,
  31. initialize : function() {
  32. if (this.get('batchSize') == -1 && this.get('interBatchWaitTimeSeconds') == -1 && this.get('tolerateSize') == -1) {
  33. var restartCount = this.get('restartHostComponents');
  34. var batchSize = 1;
  35. if (restartCount > 10) {
  36. batchSize = Math.ceil(restartCount / 10);
  37. }
  38. var tolerateCount = batchSize;
  39. this.set('batchSize', batchSize);
  40. this.set('tolerateSize', tolerateCount);
  41. this.set('interBatchWaitTimeSeconds', 120);
  42. }
  43. },
  44. validate : function() {
  45. var displayName = this.get('hostComponentDisplayName');
  46. var totalCount = this.get('restartHostComponents.length');
  47. var bs = this.get('batchSize');
  48. var ts = this.get('tolerateSize');
  49. var wait = this.get('interBatchWaitTimeSeconds');
  50. var errors = [];
  51. if (totalCount < 1) {
  52. errors.push(Em.I18n.t('rollingrestart.dialog.msg.noRestartHosts').format(displayName));
  53. } else {
  54. if (!bs) {
  55. errors.push(Em.I18n.t('rollingrestart.dialog.err.empty.batchsize'));
  56. } else if (bs > totalCount || bs < 0) {
  57. errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.batchsize').format(totalCount));
  58. }
  59. if (!ts) {
  60. errors.push(Em.I18n.t('rollingrestart.dialog.err.empty.waittime'));
  61. } else if (ts < 0) {
  62. errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.toleratesize'));
  63. }
  64. }
  65. if (!wait) {
  66. errors.push(Em.I18n.t('rollingrestart.dialog.err.empty.tolerate'));
  67. } else if (wait < 0) {
  68. errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.waitTime'));
  69. }
  70. if (errors.length < 1) {
  71. errors = null;
  72. }
  73. this.set('errors', errors);
  74. }.observes('batchSize', 'interBatchWaitTimeSeconds', 'tolerateSize', 'restartHostComponents', 'hostComponentDisplayName'),
  75. hostComponentDisplayName : function() {
  76. return App.format.role(this.get('hostComponentName'));
  77. }.property('hostComponentName'),
  78. allHostComponents : function() {
  79. return App.HostComponent.find().filterProperty('componentName', this.get('hostComponentName'));
  80. }.property('hostComponentName'),
  81. nonMaintainanceHostComponents : function() {
  82. var hostComponents = this.get('allHostComponents');
  83. hostComponents = hostComponents.filter(function(item) {
  84. if (item.get('workStatus') !== App.HostComponentStatus.maintenance) {
  85. return true;
  86. }
  87. });
  88. return hostComponents;
  89. }.property('allHostComponents', 'allHostComponents.@each.workStatus'),
  90. restartHostComponents : function() {
  91. var hostComponents = this.get('nonMaintainanceHostComponents');
  92. if (this.get('staleConfigsOnly')) {
  93. hostComponents = hostComponents.filterProperty('staleConfigs', true);
  94. }
  95. return hostComponents;
  96. }.property('nonMaintainanceHostComponents', 'staleConfigsOnly'),
  97. restartMessage : function() {
  98. var rhc = this.get('restartHostComponents.length');
  99. if (rhc > 1) {
  100. return Em.I18n.t('rollingrestart.dialog.msg.restart.plural').format(rhc, this.get('hostComponentDisplayName'))
  101. }
  102. return Em.I18n.t('rollingrestart.dialog.msg.restart').format(rhc, this.get('hostComponentDisplayName'))
  103. }.property('restartHostComponents', 'hostComponentDisplayName'),
  104. maintainanceMessage : function() {
  105. var allCount = this.get('allHostComponents.length');
  106. var nonMaintainCount = this.get('nonMaintainanceHostComponents.length');
  107. var count = allCount - nonMaintainCount;
  108. if (count > 0) {
  109. var name = this.get('hostComponentDisplayName');
  110. if (count > 1) {
  111. return Em.I18n.t('rollingrestart.dialog.msg.maintainance.plural').format(count, name)
  112. }
  113. return Em.I18n.t('rollingrestart.dialog.msg.maintainance').format(count, name)
  114. }
  115. return null;
  116. }.property('allHostComponents', 'nonMaintainanceHostComponents', 'hostComponentDisplayName'),
  117. batchSizeMessage : function() {
  118. return Em.I18n.t('rollingrestart.dialog.msg.componentsAtATime').format(this.get('hostComponentDisplayName'));
  119. }.property('hostComponentDisplayName'),
  120. staleConfigsOnlyMessage : function() {
  121. return Em.I18n.t('rollingrestart.dialog.msg.staleConfigsOnly').format(this.get('hostComponentDisplayName'));
  122. }.property('hostComponentDisplayName')
  123. });