001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.hadoop.hdfs.server.namenode.ha;
019
020 import java.io.Closeable;
021 import java.io.IOException;
022 import java.net.InetSocketAddress;
023 import java.net.URI;
024
025 import org.apache.hadoop.conf.Configuration;
026 import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
027 import org.apache.hadoop.io.retry.FailoverProxyProvider;
028 import org.apache.hadoop.ipc.RPC;
029 import org.apache.hadoop.security.UserGroupInformation;
030
031 import com.google.common.base.Preconditions;
032
033 /**
034 * A NNFailoverProxyProvider implementation which wrapps old implementations
035 * directly implementing the {@link FailoverProxyProvider} interface.
036 *
037 * It is assumed that the old impelmentation is using logical URI.
038 */
039 public class WrappedFailoverProxyProvider<T> extends
040 AbstractNNFailoverProxyProvider<T> {
041 private final FailoverProxyProvider<T> proxyProvider;
042
043 /**
044 * Wrap the given instance of an old FailoverProxyProvider.
045 */
046 public WrappedFailoverProxyProvider(FailoverProxyProvider<T> provider) {
047 proxyProvider = provider;
048 }
049
050 @Override
051 public Class<T> getInterface() {
052 return proxyProvider.getInterface();
053 }
054
055 @Override
056 public synchronized ProxyInfo<T> getProxy() {
057 return proxyProvider.getProxy();
058 }
059
060 @Override
061 public void performFailover(T currentProxy) {
062 proxyProvider.performFailover(currentProxy);
063 }
064
065 /**
066 * Close the proxy,
067 */
068 @Override
069 public synchronized void close() throws IOException {
070 proxyProvider.close();
071 }
072
073 /**
074 * Assume logical URI is used for old proxy provider implementations.
075 */
076 @Override
077 public boolean useLogicalURI() {
078 return true;
079 }
080 }