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;
19  
20  import java.io.IOException;
21  import java.net.InetSocketAddress;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.ConcurrentSkipListMap;
26  
27  import org.apache.hadoop.conf.Configuration;
28  import org.apache.hadoop.fs.FileSystem;
29  import org.apache.hadoop.hbase.catalog.CatalogTracker;
30  import org.apache.hadoop.hbase.executor.ExecutorService;
31  import org.apache.hadoop.hbase.fs.HFileSystem;
32  import org.apache.hadoop.hbase.ipc.RpcServerInterface;
33  import org.apache.hadoop.hbase.master.TableLockManager;
34  import org.apache.hadoop.hbase.master.TableLockManager.NullTableLockManager;
35  import org.apache.hadoop.hbase.regionserver.CompactionRequestor;
36  import org.apache.hadoop.hbase.regionserver.FlushRequester;
37  import org.apache.hadoop.hbase.regionserver.HRegion;
38  import org.apache.hadoop.hbase.regionserver.Leases;
39  import org.apache.hadoop.hbase.regionserver.RegionServerAccounting;
40  import org.apache.hadoop.hbase.regionserver.RegionServerServices;
41  import org.apache.hadoop.hbase.regionserver.wal.HLog;
42  import org.apache.hadoop.hbase.util.Bytes;
43  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
44  import org.apache.zookeeper.KeeperException;
45  
46  /**
47   * Basic mock region server services.  Should only be instantiated by HBaseTestingUtility.b
48   */
49  class MockRegionServerServices implements RegionServerServices {
50    private final Map<String, HRegion> regions = new HashMap<String, HRegion>();
51    private boolean stopping = false;
52    private final ConcurrentSkipListMap<byte[], Boolean> rit =
53      new ConcurrentSkipListMap<byte[], Boolean>(Bytes.BYTES_COMPARATOR);
54    private HFileSystem hfs = null;
55    private ZooKeeperWatcher zkw = null;
56    private ServerName serverName = null;
57    private RpcServerInterface rpcServer = null;
58    private volatile boolean abortRequested;
59  
60    MockRegionServerServices(ZooKeeperWatcher zkw) {
61      this.zkw = zkw;
62    }
63    
64    MockRegionServerServices(ZooKeeperWatcher zkw, ServerName serverName) {
65      this.zkw = zkw;
66      this.serverName = serverName;
67    }
68  
69    MockRegionServerServices(){
70      this(null);
71    }
72  
73    @Override
74    public boolean removeFromOnlineRegions(HRegion r, ServerName destination) {
75      return this.regions.remove(r.getRegionInfo().getEncodedName()) != null;
76    }
77  
78    @Override
79    public HRegion getFromOnlineRegions(String encodedRegionName) {
80      return this.regions.get(encodedRegionName);
81    }
82  
83    public List<HRegion> getOnlineRegions(TableName tableName) throws IOException {
84      return null;
85    }
86  
87    @Override
88    public void addToOnlineRegions(HRegion r) {
89      this.regions.put(r.getRegionInfo().getEncodedName(), r);
90    }
91  
92    @Override
93    public void postOpenDeployTasks(HRegion r, CatalogTracker ct)
94        throws KeeperException, IOException {
95      addToOnlineRegions(r);
96    }
97  
98    @Override
99    public boolean isStopping() {
100     return this.stopping;
101   }
102 
103   @Override
104   public RpcServerInterface getRpcServer() {
105     return rpcServer;
106   }
107 
108   public void setRpcServer(RpcServerInterface rpc) {
109     this.rpcServer = rpc;
110   }
111   
112   @Override
113   public ConcurrentSkipListMap<byte[], Boolean> getRegionsInTransitionInRS() {
114     return rit;
115   }
116 
117   @Override
118   public FlushRequester getFlushRequester() {
119     return null;
120   }
121 
122   @Override
123   public CompactionRequestor getCompactionRequester() {
124     return null;
125   }
126 
127   @Override
128   public CatalogTracker getCatalogTracker() {
129     return null;
130   }
131 
132   @Override
133   public ZooKeeperWatcher getZooKeeper() {
134     return zkw;
135   }
136 
137   public RegionServerAccounting getRegionServerAccounting() {
138     return null;
139   }
140 
141   @Override
142   public TableLockManager getTableLockManager() {
143     return new NullTableLockManager();
144   }
145 
146   @Override
147   public ServerName getServerName() {
148     return this.serverName;
149   }
150 
151   @Override
152   public Configuration getConfiguration() {
153     return null;
154   }
155 
156   @Override
157   public void abort(String why, Throwable e) {
158     this.abortRequested = true;
159     stop(why);
160   }
161 
162   @Override
163   public void stop(String why) {
164     //no-op
165   }
166 
167   @Override
168   public boolean isStopped() {
169     return false;
170   }
171 
172   @Override
173   public boolean isAborted() {
174     return this.abortRequested;
175   }
176 
177   @Override
178   public HFileSystem getFileSystem() {
179     return this.hfs;
180   }
181 
182   public void setFileSystem(FileSystem hfs) {
183     this.hfs = (HFileSystem)hfs;
184   }
185 
186   @Override
187   public Leases getLeases() {
188     return null;
189   }
190 
191   @Override
192   public HLog getWAL(HRegionInfo regionInfo) throws IOException {
193     // TODO Auto-generated method stub
194     return null;
195   }
196 
197   @Override
198   public ExecutorService getExecutorService() {
199     return null;
200   }
201 
202   @Override
203   public void updateRegionFavoredNodesMapping(String encodedRegionName,
204       List<org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ServerName> favoredNodes) {
205   }
206 
207   @Override
208   public InetSocketAddress[] getFavoredNodesForRegion(String encodedRegionName) {
209     return null;
210   }
211 
212   @Override
213   public Map<String, HRegion> getRecoveringRegions() {
214     // TODO Auto-generated method stub
215     return null;
216   }
217 }