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.hbase.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 long getSplitPlanCount() {
44      return master.getSplitPlanCount();
45    }
46  
47    @Override
48    public long getMergePlanCount() {
49      return master.getMergePlanCount();
50    }
51  
52    @Override
53    public String getClusterId() {
54      return master.getClusterId();
55    }
56  
57    @Override
58    public String getZookeeperQuorum() {
59      ZooKeeperWatcher zk = master.getZooKeeper();
60      if (zk == null) {
61        return "";
62      }
63      return zk.getQuorum();
64    }
65  
66    @Override
67    public String[] getCoprocessors() {
68      return master.getMasterCoprocessors();
69    }
70  
71    @Override
72    public long getStartTime() {
73      return master.getMasterStartTime();
74    }
75  
76    @Override
77    public long getActiveTime() {
78      return master.getMasterActiveTime();
79    }
80  
81    @Override
82    public String getRegionServers() {
83      ServerManager serverManager = this.master.getServerManager();
84      if (serverManager == null) {
85        return "";
86      }
87      return StringUtils.join(serverManager.getOnlineServers().keySet(), ";");
88    }
89    
90    @Override
91    public int getNumRegionServers() {
92      ServerManager serverManager = this.master.getServerManager();
93      if (serverManager == null) {
94        return 0;
95      }
96      return serverManager.getOnlineServers().size();
97    }
98  
99    @Override
100   public String getDeadRegionServers() {
101     ServerManager serverManager = this.master.getServerManager();
102     if (serverManager == null) {
103       return "";
104     }
105     return StringUtils.join(serverManager.getDeadServers().copyServerNames(), ";");
106   }
107 
108   
109   @Override
110   public int getNumDeadRegionServers() {
111     ServerManager serverManager = this.master.getServerManager();
112     if (serverManager == null) {
113       return 0;
114     }
115     return serverManager.getDeadServers().size();
116   }
117 
118   @Override
119   public String getServerName() {
120     ServerName serverName = master.getServerName();
121     if (serverName == null) {
122       return "";
123     }
124     return serverName.getServerName();
125   }
126 
127   @Override
128   public boolean getIsActiveMaster() {
129     return master.isActiveMaster();
130   }
131 
132   @Override
133   public long getNumWALFiles() {
134     return master.getNumWALFiles();
135   }
136 
137 }