org.apache.hadoop.hdfs
Class HAUtil

java.lang.Object
  extended by org.apache.hadoop.hdfs.HAUtil

public class HAUtil
extends Object


Method Summary
static org.apache.hadoop.io.Text buildTokenServiceForLogicalUri(URI uri)
          Get the service name used in the delegation token for the given logical HA service.
static void cloneDelegationTokenForLogicalUri(org.apache.hadoop.security.UserGroupInformation ugi, URI haUri, Collection<InetSocketAddress> nnAddrs)
          Locate a delegation token associated with the given HA cluster URI, and if one is found, clone it to also represent the underlying namenode address.
static InetSocketAddress getAddressOfActive(org.apache.hadoop.fs.FileSystem fs)
          Get the internet address of the currently-active NN.
static org.apache.hadoop.conf.Configuration getConfForOtherNode(org.apache.hadoop.conf.Configuration myConf)
          Given the configuration for this node, return a Configuration object for the other node in an HA setup.
static String getNameNodeId(org.apache.hadoop.conf.Configuration conf, String nsId)
          Get the namenode Id by matching the addressKey with the the address of the local node.
static String getNameNodeIdFromAddress(org.apache.hadoop.conf.Configuration conf, InetSocketAddress address, String... keys)
          Similar to DFSUtil.getNameServiceIdFromAddress(Configuration, InetSocketAddress, String...)
static String getNameNodeIdOfOtherNode(org.apache.hadoop.conf.Configuration conf, String nsId)
          Get the NN ID of the other node in an HA setup.
static URI getServiceUriFromToken(org.apache.hadoop.security.token.Token<org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier> token)
          Parse the HDFS URI out of the provided token.
static boolean isHAEnabled(org.apache.hadoop.conf.Configuration conf, String nsId)
          Returns true if HA for namenode is configured for the given nameservice
static boolean isLogicalUri(org.apache.hadoop.conf.Configuration conf, URI nameNodeUri)
           
static boolean isTokenForLogicalUri(org.apache.hadoop.security.token.Token<org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier> token)
           
static void setAllowStandbyReads(org.apache.hadoop.conf.Configuration conf, boolean val)
           
static boolean shouldAllowStandbyReads(org.apache.hadoop.conf.Configuration conf)
          This is used only by tests at the moment.
static boolean usesSharedEditsDir(org.apache.hadoop.conf.Configuration conf)
          Returns true if HA is using a shared edits directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isHAEnabled

public static boolean isHAEnabled(org.apache.hadoop.conf.Configuration conf,
                                  String nsId)
Returns true if HA for namenode is configured for the given nameservice

Parameters:
conf - Configuration
nsId - nameservice, or null if no federated NS is configured
Returns:
true if HA is configured in the configuration; else false.

usesSharedEditsDir

public static boolean usesSharedEditsDir(org.apache.hadoop.conf.Configuration conf)
Returns true if HA is using a shared edits directory.

Parameters:
conf - Configuration
Returns:
true if HA config is using a shared edits dir, false otherwise.

getNameNodeId

public static String getNameNodeId(org.apache.hadoop.conf.Configuration conf,
                                   String nsId)
Get the namenode Id by matching the addressKey with the the address of the local node. If DFSConfigKeys.DFS_HA_NAMENODE_ID_KEY is not specifically configured, this method determines the namenode Id by matching the local node's address with the configured addresses. When a match is found, it returns the namenode Id from the corresponding configuration key.

Parameters:
conf - Configuration
Returns:
namenode Id on success, null on failure.
Throws:
org.apache.hadoop.HadoopIllegalArgumentException - on error

getNameNodeIdFromAddress

public static String getNameNodeIdFromAddress(org.apache.hadoop.conf.Configuration conf,
                                              InetSocketAddress address,
                                              String... keys)
Similar to DFSUtil.getNameServiceIdFromAddress(Configuration, InetSocketAddress, String...)


getNameNodeIdOfOtherNode

public static String getNameNodeIdOfOtherNode(org.apache.hadoop.conf.Configuration conf,
                                              String nsId)
Get the NN ID of the other node in an HA setup.

Parameters:
conf - the configuration of this node
Returns:
the NN ID of the other node in this nameservice

getConfForOtherNode

public static org.apache.hadoop.conf.Configuration getConfForOtherNode(org.apache.hadoop.conf.Configuration myConf)
Given the configuration for this node, return a Configuration object for the other node in an HA setup.

Parameters:
myConf - the configuration of this node
Returns:
the configuration of the other node in an HA setup

shouldAllowStandbyReads

public static boolean shouldAllowStandbyReads(org.apache.hadoop.conf.Configuration conf)
This is used only by tests at the moment.

Returns:
true if the NN should allow read operations while in standby mode.

setAllowStandbyReads

public static void setAllowStandbyReads(org.apache.hadoop.conf.Configuration conf,
                                        boolean val)

isLogicalUri

public static boolean isLogicalUri(org.apache.hadoop.conf.Configuration conf,
                                   URI nameNodeUri)
Returns:
true if the given nameNodeUri appears to be a logical URI. This is the case if there is a failover proxy provider configured for it in the given configuration.

getServiceUriFromToken

public static URI getServiceUriFromToken(org.apache.hadoop.security.token.Token<org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier> token)
                                  throws IOException
Parse the HDFS URI out of the provided token.

Throws:
IOException - if the token is invalid

buildTokenServiceForLogicalUri

public static org.apache.hadoop.io.Text buildTokenServiceForLogicalUri(URI uri)
Get the service name used in the delegation token for the given logical HA service.

Parameters:
uri - the logical URI of the cluster
Returns:
the service name

isTokenForLogicalUri

public static boolean isTokenForLogicalUri(org.apache.hadoop.security.token.Token<org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier> token)
Returns:
true if this token corresponds to a logical nameservice rather than a specific namenode.

cloneDelegationTokenForLogicalUri

public static void cloneDelegationTokenForLogicalUri(org.apache.hadoop.security.UserGroupInformation ugi,
                                                     URI haUri,
                                                     Collection<InetSocketAddress> nnAddrs)
Locate a delegation token associated with the given HA cluster URI, and if one is found, clone it to also represent the underlying namenode address.

Parameters:
ugi - the UGI to modify
haUri - the logical URI for the cluster
nnAddrs - collection of NNs in the cluster to which the token applies

getAddressOfActive

public static InetSocketAddress getAddressOfActive(org.apache.hadoop.fs.FileSystem fs)
                                            throws IOException
Get the internet address of the currently-active NN. This should rarely be used, since callers of this method who connect directly to the NN using the resulting InetSocketAddress will not be able to connect to the active NN if a failover were to occur after this method has been called.

Parameters:
fs - the file system to get the active address of.
Returns:
the internet address of the currently-active NN.
Throws:
IOException - if an error occurs while resolving the active NN.


Copyright © 2013 Apache Software Foundation. All Rights Reserved.