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.hdfs.server.namenode.ha;
19 
20 import java.io.Closeable;
21 import java.io.IOException;
22 import java.net.InetSocketAddress;
23 import java.net.URI;
24 
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
27 import org.apache.hadoop.io.retry.FailoverProxyProvider;
28 import org.apache.hadoop.ipc.RPC;
29 import org.apache.hadoop.security.UserGroupInformation;
30 
31 import com.google.common.base.Preconditions;
32 
33 /**
34  * A NNFailoverProxyProvider implementation which wrapps old implementations
35  * directly implementing the {@link FailoverProxyProvider} interface.
36  *
37  * It is assumed that the old impelmentation is using logical URI.
38  */
39 public class WrappedFailoverProxyProvider<T> extends
40     AbstractNNFailoverProxyProvider<T> {
41   private final FailoverProxyProvider<T> proxyProvider;
42 
43   /**
44    * Wrap the given instance of an old FailoverProxyProvider.
45    */
WrappedFailoverProxyProvider(FailoverProxyProvider<T> provider)46   public WrappedFailoverProxyProvider(FailoverProxyProvider<T> provider) {
47     proxyProvider = provider;
48   }
49 
50   @Override
getInterface()51   public Class<T> getInterface() {
52     return proxyProvider.getInterface();
53   }
54 
55   @Override
getProxy()56   public synchronized ProxyInfo<T> getProxy() {
57     return proxyProvider.getProxy();
58   }
59 
60   @Override
performFailover(T currentProxy)61   public void performFailover(T currentProxy) {
62     proxyProvider.performFailover(currentProxy);
63   }
64 
65   /**
66    * Close the proxy,
67    */
68   @Override
close()69   public synchronized void close() throws IOException {
70     proxyProvider.close();
71   }
72 
73   /**
74    * Assume logical URI is used for old proxy provider implementations.
75    */
76   @Override
useLogicalURI()77   public boolean useLogicalURI() {
78     return true;
79   }
80 }
81