RegistryUtils (Apache Hadoop Main 3.5.0 API)
Description: declaration: package: org.apache.hadoop.registry.client.binding, class: RegistryUtils

Package org.apache.hadoop.registry.client.binding

# Class RegistryUtils

java.lang.Object
org.apache.hadoop.registry.client.binding.RegistryUtils

@Public @Evolving public class RegistryUtils extends Object
Utility methods for working with a registry.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `org.apache.hadoop.registry.client.binding.RegistryUtils.ServiceRecordMarshal`
  Static instance of service record marshalling

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RegistryUtils()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `componentListPath(String user, String serviceClass, String serviceName)`
  Create a path for listing components under a service
  `static String`
  `componentPath(String user, String serviceClass, String serviceName, String componentName)`
  Create the path to a service record for a component
  `static String`
  `convertUsername(String username)`
  Convert the username to that which can be used for registry entries.
  `static String`
  `currentUser()`
  Get the current user path formatted for the registry
  `static 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 matching
  `static 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 String`
  `getCurrentUsernameUnencoded(String env_hadoop_username)`
  Get the current username, using the value of the parameter `env_hadoop_username` if it is set on an insecure cluster.
  `static String`
  `homePathForCurrentUser()`
  Get the home path of the current user.
  `static String`
  `homePathForUser(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 path
  `static String`
  `registryUser(String shortUserName)`
  Convert the given user name formatted for the registry.
  `static String`
  `serviceclassPath(String user, String serviceClass)`
  Create a service classpath
  `static String`
  `servicePath(String user, String serviceClass, String serviceName)`
  Create a path to a service under a user and service class
  `static Map<String,RegistryPathStatus>`
  `statChildren(RegistryOperations registryOperations, String path)`
  List children of a directory and retrieve their `RegistryPathStatus` values.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### RegistryUtils

    public RegistryUtils()

- ## Method Details

  - ### homePathForUser

    public static String homePathForUser(String username)
    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

    public static String convertUsername(String username)
    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

    public static String serviceclassPath(String user, String serviceClass)
    Create a service classpath
    Parameters:
      `user` - username or ""
      `serviceClass` - service name
    Returns:
      a full path

  - ### servicePath

    public static String servicePath(String user, String serviceClass, String serviceName)
    Create a path to a service under a user and service class
    Parameters:
      `user` - username or ""
      `serviceClass` - service name
      `serviceName` - service name unique for that user and service class
    Returns:
      a full path

  - ### componentListPath

    public static String componentListPath(String user, String serviceClass, String serviceName)
    Create a path for listing components under a service
    Parameters:
      `user` - username or ""
      `serviceClass` - service name
      `serviceName` - 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 name
      `serviceName` - service name unique for that user and service class
      `componentName` - 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 instance
      `path` - 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 their `RegistryPathStatus` values.

    This is not an atomic operation; A child may be deleted during the iteration through the child entries. If this happens, the `PathNotFoundException` is 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

    public static String homePathForCurrentUser()
    Get the home path of the current user.

    In an insecure cluster, the environment variable `HADOOP_USER_NAME` is 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

    @VisibleForTesting public static String getCurrentUsernameUnencoded(String env_hadoop_username)
    Get the current username, using the value of the parameter `env_hadoop_username` if 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

    public static String currentUser()
    Get the current user path formatted for the registry

    In an insecure cluster, the environment variable `HADOOP_USER_NAME` is 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

    public static String registryUser(String shortUserName)
    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 fetches
      `parentpath` - path of the parent of all the entries
      `stats` - 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 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 fetches
      `parentpath` - 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 fetches
      `parentpath` - 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.