Class RegistryAdminService

java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.service.CompositeService
All Implemented Interfaces:
Closeable, AutoCloseable, RegistryConstants, RegistryOperations, RegistryBindingSource, org.apache.hadoop.service.Service

public class RegistryAdminService extends RegistryOperationsService
Administrator service for the registry. This is the one with permissions to create the base directories and those for users. It also includes support for asynchronous operations, so that zookeeper connectivity problems do not hold up the server code performing the actions. Any action queued via submit(Callable) will be run asynchronously. The createDirAsync(String, List, boolean) is an example of such an an action A key async action is the depth-first tree purge, which supports pluggable policies for deleting entries. The method purge(String, NodeSelector, PurgePolicy, BackgroundCallback) implements the recursive purge operation —the class {{AsyncPurge}} provides the asynchronous scheduling of this.
  • Field Details

    • USER_HOMEDIR_ACL_PERMISSIONS

      public static final int USER_HOMEDIR_ACL_PERMISSIONS
      The ACL permissions for the user's homedir ACL.
      See Also:
    • executor

      protected final ExecutorService executor
      Executor for async operations
  • Constructor Details

    • RegistryAdminService

      public RegistryAdminService(String name)
      Construct an instance of the service
      Parameters:
      name - service name
    • RegistryAdminService

      public RegistryAdminService(String name, RegistryBindingSource bindingSource)
      construct an instance of the service, using the specified binding source to bond to ZK
      Parameters:
      name - service name
      bindingSource - provider of ZK binding information
  • Method Details

    • serviceStop

      protected void serviceStop() throws Exception
      Stop the service: halt the executor.
      Overrides:
      serviceStop in class CuratorService
      Throws:
      Exception - exception.
    • stopExecutor

      protected void stopExecutor()
      Stop the executor if it is not null. This uses ExecutorService.shutdownNow() and so does not block until they have completed.
    • getExecutor

      protected ExecutorService getExecutor()
      Get the executor
      Returns:
      the executor
    • submit

      public <V> Future<V> submit(Callable<V> callable)
      Submit a callable
      Type Parameters:
      V - type of the final get
      Parameters:
      callable - callable
      Returns:
      a future to wait on
    • createDirAsync

      public Future<Boolean> createDirAsync(String path, List<org.apache.zookeeper.data.ACL> acls, boolean createParents) throws IOException
      Asynchronous operation to create a directory
      Parameters:
      path - path
      acls - ACL list
      createParents - flag to indicate parent dirs should be created as needed
      Returns:
      the future which will indicate whether or not the operation succeeded —and propagate any exceptions
      Throws:
      IOException
    • serviceInit

      protected void serviceInit(org.apache.hadoop.conf.Configuration conf) throws Exception
      Init operation sets up the system ACLs.
      Overrides:
      serviceInit in class CuratorService
      Parameters:
      conf - configuration of the service
      Throws:
      Exception
    • serviceStart

      protected void serviceStart() throws Exception
      Start the service, including creating base directories with permissions
      Overrides:
      serviceStart in class CuratorService
      Throws:
      Exception
    • createRootRegistryPaths

      @VisibleForTesting public void createRootRegistryPaths() throws IOException
      Create the initial registry paths
      Throws:
      IOException - any failure
    • homeDir

      protected String homeDir(String username)
      Get the path to a user's home dir
      Parameters:
      username - username
      Returns:
      a path for services underneath
    • aclsForUser

      public List<org.apache.zookeeper.data.ACL> aclsForUser(String username, int perms) throws IOException
      Set up the ACL for the user. Important: this must run client-side as it needs to know the id:pass tuple for a user
      Parameters:
      username - user name
      perms - permissions
      Returns:
      an ACL list
      Throws:
      IOException - ACL creation/parsing problems
    • initUserRegistryAsync

      public Future<Boolean> initUserRegistryAsync(String shortname) throws IOException
      Start an async operation to create the home path for a user if it does not exist
      Parameters:
      shortname - username, without any @REALM in kerberos
      Returns:
      the path created
      Throws:
      IOException - any failure while setting up the operation
    • initUserRegistry

      public String initUserRegistry(String username) throws IOException
      Create the home path for a user if it does not exist. This uses initUserRegistryAsync(String) and then waits for the result ... the code path is the same as the async operation; this just picks up and relays/converts exceptions
      Parameters:
      username - username
      Returns:
      the path created
      Throws:
      IOException - any failure
    • verifyRealmValidity

      protected void verifyRealmValidity() throws org.apache.hadoop.service.ServiceStateException
      Method to validate the validity of the kerberos realm.
      • Insecure: not needed.
      • Secure: must have been determined.
      Throws:
      org.apache.hadoop.service.ServiceStateException
    • purge

      @VisibleForTesting public int purge(String path, RegistryAdminService.NodeSelector selector, RegistryAdminService.PurgePolicy purgePolicy, org.apache.curator.framework.api.BackgroundCallback callback) throws IOException
      Recursive operation to purge all matching records under a base path.
      1. Uses a depth first search
      2. A match is on ID and persistence policy, or, if policy==-1, any match
      3. If a record matches then it is deleted without any child searches
      4. Deletions will be asynchronous if a callback is provided
      The code is designed to be robust against parallel deletions taking place; in such a case it will stop attempting that part of the tree. This avoid the situation of more than 1 purge happening in parallel and one of the purge operations deleteing the node tree above the other.
      Parameters:
      path - base path
      selector - selector for the purge policy
      purgePolicy - what to do if there is a matching record with children
      callback - optional curator callback
      Returns:
      the number of delete operations perfomed. As deletes may be for everything under a path, this may be less than the number of records actually deleted
      Throws:
      IOException - problems
      org.apache.hadoop.fs.PathIsNotEmptyDirectoryException - if an entry cannot be deleted as it has children and the purge policy is FailOnChildren