Class Curator

java.lang.Object
com.yahoo.component.AbstractComponent
com.yahoo.vespa.curator.Curator
All Implemented Interfaces:
com.yahoo.component.Component, com.yahoo.component.Deconstructable, AutoCloseable, Comparable<com.yahoo.component.Component>
Direct Known Subclasses:
MockCurator

public class Curator extends com.yahoo.component.AbstractComponent implements AutoCloseable
Curator interface for Vespa. This contains method for constructing common recipes and utilities as well as a small wrapper API for common operations which uses typed paths and avoids throwing checked exceptions.

There is a mock implementation in MockCurator.

Author:
vegardh, bratseth
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Interface for waiting for completion of an operation
    static interface 
    A listenable cache of all the immediate children of a curator path.
    static interface 
    A listenable cache of the content of a single curator path.
  • Field Summary

    Fields inherited from class com.yahoo.component.AbstractComponent

    isDeconstructable
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Curator(com.yahoo.cloud.config.CuratorConfig curatorConfig, com.yahoo.vespa.zookeeper.VespaZooKeeperServer server)
     
    protected
    Curator(String connectionSpec, String zooKeeperEnsembleConnectionSpec, Function<org.apache.curator.RetryPolicy,org.apache.curator.framework.CuratorFramework> curatorFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    boolean
    create(com.yahoo.path.Path path)
     
    boolean
    create(com.yahoo.path.Path path, Duration ttl)
    Creates an empty node at a path, creating any parents as necessary.
    static Curator
    create(String connectionSpec)
    Creates a curator instance from a comma-separated string of ZooKeeper host:port strings
    static Curator
    create(String connectionSpec, Optional<File> clientConfigFile)
     
    void
    createAtomically(com.yahoo.path.Path... paths)
    Creates all the given paths in a single transaction.
    org.apache.curator.framework.recipes.atomic.DistributedAtomicLong
    For internal use; prefer creating a CuratorCounter
    createCompletionWaiter(com.yahoo.path.Path parentPath, String waiterNode, String id, Duration waitForAll)
     
    createDirectoryCache(String path, boolean cacheData, boolean dataIsCompressed, ExecutorService executorService)
    Creates a listenable cache which keeps in sync with changes to all the immediate children of a path
    createFileCache(String path, boolean dataIsCompressed)
    Creates a listenable cache which keeps in sync with changes to a given node
    org.apache.curator.framework.recipes.locks.InterProcessLock
    createMutex(String lockPath)
    For internal use; prefer creating a Lock
    void
     
    void
    delete(com.yahoo.path.Path path)
    Deletes the path and any children it may have.
    void
    delete(com.yahoo.path.Path path, boolean recursive)
    Deletes the path and any children it may have.
    void
    delete(com.yahoo.path.Path path, int expectedVersion, boolean recursive)
     
    boolean
    exists(com.yahoo.path.Path path)
    A convenience method which returns whether the given path exists
    org.apache.curator.framework.CuratorFramework
    Returns the curator framework API
    getChildren(com.yahoo.path.Path path)
    Returns the names of the children at the given path.
    getCompletionWaiter(com.yahoo.path.Path waiterPath, String id, Duration waitForAll)
     
    Optional<byte[]>
    getData(com.yahoo.path.Path path)
    Returns the data at the given path, which may be a zero-length buffer if the node exists but have no data.
    Optional<byte[]>
    getData(com.yahoo.path.Path path, org.apache.zookeeper.data.Stat stat)
     
    Optional<org.apache.zookeeper.data.Stat>
    getStat(com.yahoo.path.Path path)
    Returns the stat data at the given path.
    lock(com.yahoo.path.Path path, Duration timeout)
    Create and acquire a re-entrant lock in given path
    lock(com.yahoo.path.Path path, Duration timeout, Duration ttl)
    Create and acquire a re-entrant lock in given path with a TTL
     
    org.apache.zookeeper.data.Stat
    set(com.yahoo.path.Path path, byte[] data)
    A convenience method which sets some content at a path.
    org.apache.zookeeper.data.Stat
    set(com.yahoo.path.Path path, byte[] data, int expectedVersion)
     
     
    int
    Returns the number of zooKeeper servers in this ensemble.

    Methods inherited from class com.yahoo.component.AbstractComponent

    clone, compareTo, getClassName, getId, getIdString, hasInitializedId, initId, isDeconstructable, setIsDeconstructable, toString

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Curator

      @Inject public Curator(com.yahoo.cloud.config.CuratorConfig curatorConfig, com.yahoo.vespa.zookeeper.VespaZooKeeperServer server)
    • Curator

      protected Curator(String connectionSpec, String zooKeeperEnsembleConnectionSpec, Function<org.apache.curator.RetryPolicy,org.apache.curator.framework.CuratorFramework> curatorFactory)
  • Method Details

    • create

      public static Curator create(String connectionSpec)
      Creates a curator instance from a comma-separated string of ZooKeeper host:port strings
    • create

      public static Curator create(String connectionSpec, Optional<File> clientConfigFile)
    • sessionTimeout

      public Duration sessionTimeout()
    • createAtomicCounter

      public org.apache.curator.framework.recipes.atomic.DistributedAtomicLong createAtomicCounter(String path)
      For internal use; prefer creating a CuratorCounter
    • createMutex

      public org.apache.curator.framework.recipes.locks.InterProcessLock createMutex(String lockPath)
      For internal use; prefer creating a Lock
    • getCompletionWaiter

      public Curator.CompletionWaiter getCompletionWaiter(com.yahoo.path.Path waiterPath, String id, Duration waitForAll)
    • createCompletionWaiter

      public Curator.CompletionWaiter createCompletionWaiter(com.yahoo.path.Path parentPath, String waiterNode, String id, Duration waitForAll)
    • createDirectoryCache

      public Curator.DirectoryCache createDirectoryCache(String path, boolean cacheData, boolean dataIsCompressed, ExecutorService executorService)
      Creates a listenable cache which keeps in sync with changes to all the immediate children of a path
    • createFileCache

      public Curator.FileCache createFileCache(String path, boolean dataIsCompressed)
      Creates a listenable cache which keeps in sync with changes to a given node
    • exists

      public boolean exists(com.yahoo.path.Path path)
      A convenience method which returns whether the given path exists
    • set

      public org.apache.zookeeper.data.Stat set(com.yahoo.path.Path path, byte[] data)
      A convenience method which sets some content at a path. If the path and any of its parents does not exists they are created.
    • set

      public org.apache.zookeeper.data.Stat set(com.yahoo.path.Path path, byte[] data, int expectedVersion)
    • create

      public boolean create(com.yahoo.path.Path path)
      See Also:
    • create

      public boolean create(com.yahoo.path.Path path, Duration ttl)
      Creates an empty node at a path, creating any parents as necessary. If the node already exists nothing is done. Returns whether a change was attempted.
    • createAtomically

      public void createAtomically(com.yahoo.path.Path... paths)
      Creates all the given paths in a single transaction. Any paths which already exists are ignored.
    • delete

      public void delete(com.yahoo.path.Path path)
      Deletes the path and any children it may have. If the path does not exist, nothing is done.
    • delete

      public void delete(com.yahoo.path.Path path, boolean recursive)
      Deletes the path and any children it may have. If the path does not exist, nothing is done.
    • delete

      public void delete(com.yahoo.path.Path path, int expectedVersion, boolean recursive)
    • getChildren

      public List<String> getChildren(com.yahoo.path.Path path)
      Returns the names of the children at the given path. If the path does not exist or have no children an empty list (never null) is returned.
    • getData

      public Optional<byte[]> getData(com.yahoo.path.Path path)
      Returns the data at the given path, which may be a zero-length buffer if the node exists but have no data. Empty is returned if the path does not exist.
    • getData

      public Optional<byte[]> getData(com.yahoo.path.Path path, org.apache.zookeeper.data.Stat stat)
    • getStat

      public Optional<org.apache.zookeeper.data.Stat> getStat(com.yahoo.path.Path path)
      Returns the stat data at the given path. Empty is returned if the path does not exist.
    • lock

      public Lock lock(com.yahoo.path.Path path, Duration timeout, Duration ttl)
      Create and acquire a re-entrant lock in given path with a TTL
    • lock

      public Lock lock(com.yahoo.path.Path path, Duration timeout)
      Create and acquire a re-entrant lock in given path
    • framework

      public org.apache.curator.framework.CuratorFramework framework()
      Returns the curator framework API
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • deconstruct

      public void deconstruct()
      Specified by:
      deconstruct in interface com.yahoo.component.Deconstructable
      Overrides:
      deconstruct in class com.yahoo.component.AbstractComponent
    • zooKeeperEnsembleConnectionSpec

      public String zooKeeperEnsembleConnectionSpec()
      Returns:
      The non-null connect string containing all ZooKeeper servers in the ensemble. WARNING: This may be different from the servers this Curator may connect to. TODO: Move method out of this class.
    • zooKeeperEnsembleCount

      public int zooKeeperEnsembleCount()
      Returns the number of zooKeeper servers in this ensemble. WARNING: This may be different from the number of servers this Curator may connect to. TODO: Move method out of this class.