Class RegistryUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.registry.client.binding.RegistryUtils.ServiceRecordMarshalStatic instance of service record marshalling -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcomponentListPath(String user, String serviceClass, String serviceName) Create a path for listing components under a servicestatic StringcomponentPath(String user, String serviceClass, String serviceName, String componentName) Create the path to a service record for a componentstatic StringconvertUsername(String username) Convert the username to that which can be used for registry entries.static StringGet the current user path formatted for the registrystatic Map<String,ServiceRecord> extractServiceRecords(RegistryOperations operations, String parentpath) Extract all service records under a list of stat operations...this non-atomic action skips entries that are too short or simply not matching.static Map<String,ServiceRecord> extractServiceRecords(RegistryOperations operations, String parentpath, Collection<RegistryPathStatus> stats) Extract all service records under a list of stat operations...this skips entries that are too short or simply not matchingstatic Map<String,ServiceRecord> extractServiceRecords(RegistryOperations operations, String parentpath, Map<String, RegistryPathStatus> stats) Extract all service records under a list of stat operations...this non-atomic action skips entries that are too short or simply not matching.static StringgetCurrentUsernameUnencoded(String env_hadoop_username) Get the current username, using the value of the parameterenv_hadoop_usernameif it is set on an insecure cluster.static StringGet the home path of the current user.static StringhomePathForUser(String username) Buld the user path -switches to the system path if the user is "".static Map<String,ServiceRecord> listServiceRecords(RegistryOperations registryOperations, String path) List service records directly under a pathstatic StringregistryUser(String shortUserName) Convert the given user name formatted for the registry.static StringserviceclassPath(String user, String serviceClass) Create a service classpathstatic StringservicePath(String user, String serviceClass, String serviceName) Create a path to a service under a user and service classstatic Map<String,RegistryPathStatus> statChildren(RegistryOperations registryOperations, String path) List children of a directory and retrieve theirRegistryPathStatusvalues.
-
Constructor Details
-
RegistryUtils
public RegistryUtils()
-
-
Method Details
-
homePathForUser
Buld the user path -switches to the system path if the user is "". It also cross-converts the username to ascii via punycode- Parameters:
username- username or ""- Returns:
- the path to the user
-
convertUsername
Convert the username to that which can be used for registry entries. Lower cases it, Strip the kerberos realm off a username if needed, and any "/" hostname entries- Parameters:
username- user- Returns:
- the converted username
-
serviceclassPath
Create a service classpath- Parameters:
user- username or ""serviceClass- service name- Returns:
- a full path
-
servicePath
Create a path to a service under a user and service class- Parameters:
user- username or ""serviceClass- service nameserviceName- service name unique for that user and service class- Returns:
- a full path
-
componentListPath
Create a path for listing components under a service- Parameters:
user- username or ""serviceClass- service nameserviceName- service name unique for that user and service class- Returns:
- a full path
-
componentPath
public static String componentPath(String user, String serviceClass, String serviceName, String componentName) Create the path to a service record for a component- Parameters:
user- username or ""serviceClass- service nameserviceName- service name unique for that user and service classcomponentName- unique name/ID of the component- Returns:
- a full path
-
listServiceRecords
public static Map<String,ServiceRecord> listServiceRecords(RegistryOperations registryOperations, String path) throws IOException List service records directly under a path- Parameters:
registryOperations- registry operations instancepath- path to list- Returns:
- a mapping of the service records that were resolved, indexed by their full path
- Throws:
IOException
-
statChildren
public static Map<String,RegistryPathStatus> statChildren(RegistryOperations registryOperations, String path) throws org.apache.hadoop.fs.PathNotFoundException, InvalidPathnameException, IOException List children of a directory and retrieve theirRegistryPathStatusvalues.This is not an atomic operation; A child may be deleted during the iteration through the child entries. If this happens, the
PathNotFoundExceptionis caught and that child entry ommitted.- Parameters:
path- path- Returns:
- a possibly empty map of child entries listed by their short name.
- Throws:
org.apache.hadoop.fs.PathNotFoundException- path is not in the registry.InvalidPathnameException- the path is invalid.IOException- Any other IO Exception
-
homePathForCurrentUser
Get the home path of the current user.In an insecure cluster, the environment variable
HADOOP_USER_NAMEis queried first.This means that in a YARN container where the creator set this environment variable to propagate their identity, the defined user name is used in preference to the actual user.
In a secure cluster, the kerberos identity of the current user is used.
- Returns:
- a path for the current user's home dir.
- Throws:
RuntimeException- if the current user identity cannot be determined from the OS/kerberos.
-
getCurrentUsernameUnencoded
Get the current username, using the value of the parameterenv_hadoop_usernameif it is set on an insecure cluster. This ensures that the username propagates correctly across processes started by YARN.This method is primarly made visible for testing.
- Parameters:
env_hadoop_username- the environment variable- Returns:
- the selected username
- Throws:
RuntimeException- if there is a problem getting the short user name of the current user.
-
currentUser
Get the current user path formatted for the registryIn an insecure cluster, the environment variable
HADOOP_USER_NAMEis queried first.This means that in a YARN container where the creator set this environment variable to propagate their identity, the defined user name is used in preference to the actual user.
In a secure cluster, the kerberos identity of the current user is used.
- Returns:
- the encoded shortname of the current user
- Throws:
RuntimeException- if the current user identity cannot be determined from the OS/kerberos.
-
registryUser
Convert the given user name formatted for the registry.- Parameters:
shortUserName-- Returns:
- converted user name
-
extractServiceRecords
public static Map<String,ServiceRecord> extractServiceRecords(RegistryOperations operations, String parentpath, Collection<RegistryPathStatus> stats) throws IOException Extract all service records under a list of stat operations...this skips entries that are too short or simply not matching- Parameters:
operations- operation support for fetchesparentpath- path of the parent of all the entriesstats- Collection of stat results- Returns:
- a possibly empty map of fullpath:record.
- Throws:
IOException- for any IO Operation that wasn't ignored.
-
extractServiceRecords
public static Map<String,ServiceRecord> extractServiceRecords(RegistryOperations operations, String parentpath, Map<String, RegistryPathStatus> stats) throws IOExceptionExtract all service records under a list of stat operations...this non-atomic action skips entries that are too short or simply not matching.- Parameters:
operations- operation support for fetchesparentpath- path of the parent of all the entries- Returns:
- a possibly empty map of fullpath:record.
- Throws:
IOException- for any IO Operation that wasn't ignored.
-
extractServiceRecords
public static Map<String,ServiceRecord> extractServiceRecords(RegistryOperations operations, String parentpath) throws IOException Extract all service records under a list of stat operations...this non-atomic action skips entries that are too short or simply not matching.- Parameters:
operations- operation support for fetchesparentpath- path of the parent of all the entries- Returns:
- a possibly empty map of fullpath:record.
- Throws:
IOException- for any IO Operation that wasn't ignored.
-