View Javadoc

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  package org.apache.hadoop.hbase.master;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.apache.hadoop.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.ServerName;
23  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
24  
25  /**
26   * Impl for exposing HMaster Information through JMX
27   */
28  @InterfaceAudience.Private
29  public class MetricsMasterWrapperImpl implements MetricsMasterWrapper {
30  
31    private final HMaster master;
32  
33    public MetricsMasterWrapperImpl(final HMaster master) {
34      this.master = master;
35    }
36  
37    @Override
38    public double getAverageLoad() {
39      return master.getAverageLoad();
40    }
41  
42    @Override
43    public String getClusterId() {
44      return master.getClusterId();
45    }
46  
47    @Override
48    public String getZookeeperQuorum() {
49      ZooKeeperWatcher zk = master.getZooKeeper();
50      if (zk == null) {
51        return "";
52      }
53      return zk.getQuorum();
54    }
55  
56    @Override
57    public String[] getCoprocessors() {
58      return master.getMasterCoprocessors();
59    }
60  
61    @Override
62    public long getStartTime() {
63      return master.getMasterStartTime();
64    }
65  
66    @Override
67    public long getActiveTime() {
68      return master.getMasterActiveTime();
69    }
70  
71    @Override
72    public String getRegionServers() {
73      ServerManager serverManager = this.master.getServerManager();
74      if (serverManager == null) {
75        return "";
76      }
77      return StringUtils.join(serverManager.getOnlineServers().keySet(), ";");
78    }
79    
80    @Override
81    public int getNumRegionServers() {
82      ServerManager serverManager = this.master.getServerManager();
83      if (serverManager == null) {
84        return 0;
85      }
86      return serverManager.getOnlineServers().size();
87    }
88  
89    @Override
90    public String getDeadRegionServers() {
91      ServerManager serverManager = this.master.getServerManager();
92      if (serverManager == null) {
93        return "";
94      }
95      return StringUtils.join(serverManager.getDeadServers().copyServerNames(), ";");
96    }
97  
98    
99    @Override
100   public int getNumDeadRegionServers() {
101     ServerManager serverManager = this.master.getServerManager();
102     if (serverManager == null) {
103       return 0;
104     }
105     return serverManager.getDeadServers().size();
106   }
107 
108   @Override
109   public String getServerName() {
110     ServerName serverName = master.getServerName();
111     if (serverName == null) {
112       return "";
113     }
114     return serverName.getServerName();
115   }
116 
117   @Override
118   public boolean getIsActiveMaster() {
119     return master.isActiveMaster();
120   }
121 }