Code coverage report for app/views/common/rolling_restart_view.js

Statements: 81.82% (45 / 55)      Branches: 72.41% (21 / 29)      Functions: 66.67% (6 / 9)      Lines: 81.82% (45 / 55)      Ignored: none     

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