Code coverage report for app/views/main/host/details/host_component_views/regionserver_view.js

Statements: 84% (21 / 25)      Branches: 94.12% (16 / 17)      Functions: 62.5% (5 / 8)      Lines: 84% (21 / 25)      Ignored: none     

All files » app/views/main/host/details/host_component_views/ » regionserver_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    1                                     1   1                                             12     12 10               10 8 2 1 1 1     2                 24   11   24       12   6 6   6 6        
'use strict';
 
;require.register("views/main/host/details/host_component_views/regionserver_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');
 
  App.RegionServerComponentView = App.HostComponentView.extend(App.Decommissionable, {
 
    componentForCheckDecommission: 'HBASE_MASTER',
 
    setDesiredAdminState: function setDesiredAdminState(desiredAdminState) {
      this.getRSDecommissionStatus(desiredAdminState);
    },
 
    getRSDecommissionStatus: function getRSDecommissionStatus(desiredAdminState) {
      var hostName = App.HBaseService.find('HBASE').get('master.hostName');
      App.ajax.send({
        name: 'host.host_component.decommission_status_regionserver',
        sender: this,
        data: {
          hostName: hostName,
          desiredAdminState: desiredAdminState
        },
        success: 'getRSDecommissionStatusSuccessCallback',
        error: 'getRSDecommissionStatusErrorCallback'
      });
    },
 
    getRSDecommissionStatusSuccessCallback: function getRSDecommissionStatusSuccessCallback(data, opt, params) {
      var desiredAdminState = params.desiredAdminState,
          hostName = this.get('content.hostName');
 
      if (data) {
        var liveRSHostsMetrics = Em.get(data, 'items.0.metrics.hbase.master.liveRegionServersHosts'),
            deadRSHostsMetrics = Em.get(data, 'items.0.metrics.hbase.master.deadRegionServersHosts'),
            liveRSHosts = this.parseRegionServersHosts(liveRSHostsMetrics),
            deadRSHosts = this.parseRegionServersHosts(deadRSHostsMetrics),
            isLiveRS = liveRSHosts.contains(hostName),
            isDeadRS = deadRSHosts.contains(hostName),
            isInServiceDesired = desiredAdminState === 'INSERVICE',
            isDecommissionedDesired = desiredAdminState === 'DECOMMISSIONED';
        if (liveRSHosts.length + deadRSHosts.length === 0 || isInServiceDesired && isLiveRS || isDecommissionedDesired && isDeadRS) {
          this.setDesiredAdminStateDefault(desiredAdminState);
        } else if (isInServiceDesired) {
          this.setStatusAs('RS_DECOMMISSIONED');
        } else Eif (isDecommissionedDesired) {
          this.setStatusAs('INSERVICE');
        }
      } else {
        this.setDesiredAdminStateDefault(desiredAdminState);
      }
    },
 
    getRSDecommissionStatusErrorCallback: function getRSDecommissionStatusErrorCallback(request, ajaxOptions, error, opt, params) {
      this.setDesiredAdminStateDefault(params.desiredAdminState);
    },
 
    parseRegionServersHosts: function parseRegionServersHosts(str) {
      var items = str ? str.split(';') : [],
          hosts = items.map(function (item) {
        return item.split(',')[0];
      });
      return hosts;
    },
 
    setDesiredAdminStateDefault: function setDesiredAdminStateDefault(desiredAdminState) {
      switch (desiredAdminState) {
        case 'INSERVICE':
          this.setStatusAs(desiredAdminState);
          break;
        case 'DECOMMISSIONED':
          this.setStatusAs('RS_DECOMMISSIONED');
          break;
      }
    }
  });
});