Class CuratorHelper


  • public class CuratorHelper
    extends java.lang.Object
    Class for obtaining an initialized CuratorFramework instance. This class takes care of looking up in the classpath the appropriate builder for setting up Curator. This allows us to override API implementations with mocks in the test environment.

    Properties

    Properties will be pulled from the first default properties file on the classpath unless a system property override is used. The AIE_SERVICES_PROPFILE system property may be used to override the location of this file.

    Property Description
    curator.framework.builder The classname for the desired CuratorFrameworkBuilder
    curator.default.session.timeout Session timeout for connections to ZooKeeper. Default is 1 minute, specified in milliseconds. Note that the ZooKeeper server may cap the maximum timeout. The default maximum timeout for ZK is 40 seconds.
    curator.default.connection.timeout Connection timeout for establishing new connections to ZooKeeper. Default is 20 seconds, specified in milliseconds.
    • Field Detail

      • ROOT

        public static final java.lang.String ROOT
        Root node for all Attivio ZooKeeper paths
        See Also:
        Constant Field Values
      • AIE_SERVICES_PROPFILE

        public static final java.lang.String AIE_SERVICES_PROPFILE
        If defined, this file will be used to load the aie.services definitions. Otherwise DEFAULT_AIE_SERVICES_PROPERTIES will be loaded from the classpath.
        See Also:
        Constant Field Values
      • DEFAULT_AIE_SERVICES_PROPERTIES

        public static final java.lang.String DEFAULT_AIE_SERVICES_PROPERTIES
        See Also:
        Constant Field Values
      • CURATOR_DEFAULT_SESSION_TIMEOUT_PROP

        public static final java.lang.String CURATOR_DEFAULT_SESSION_TIMEOUT_PROP
        Property name for the session timeout
        See Also:
        Constant Field Values
      • CURATOR_DEFAULT_CONNECTION_TIMEOUT_PROP

        public static final java.lang.String CURATOR_DEFAULT_CONNECTION_TIMEOUT_PROP
        See Also:
        Constant Field Values
      • ZOO_URI_SCHEME

        public static final java.lang.String ZOO_URI_SCHEME
        zoo URI scheme name
        See Also:
        Constant Field Values
      • DEFAULT_SESSION_TIMEOUT

        public static final java.lang.String DEFAULT_SESSION_TIMEOUT
        See Also:
        Constant Field Values
      • DEFAULT_CONNECTION_TIMEOUT

        public static final java.lang.String DEFAULT_CONNECTION_TIMEOUT
        See Also:
        Constant Field Values
    • Constructor Detail

      • CuratorHelper

        public CuratorHelper()
    • Method Detail

      • loadProperties

        public static java.util.Properties loadProperties()
        Loads and returns properties associated with Attivio services. By default, these properties will be obtained by looking up DEFAULT_AIE_SERVICES_PROPERTIES on the classpath. The system property AIE_SERVICES_PROPFILE may be used to override this behavior and specify the source file for properties.
        Returns:
        the properties file for customization of Attivio services implementations.
      • getConnectionInfo

        public static java.lang.String getConnectionInfo()
        Retrieves the configured connection information, first from the CuratorFrameworkBuilder.AIE_ZOOKEEPER system property, falling back to the environment variable CuratorFrameworkBuilder.AIE_ZOOKEEPER. The connection information and its source are logged and the DEBUG level. If no connection information is found an error is logged.
        Returns:
        the ZooKeeper connection information to use for Curator
      • getConnectionInfo

        public static java.lang.String getConnectionInfo​(boolean logError)
        Retrieves the configured connection information, first from the CuratorFrameworkBuilder.AIE_ZOOKEEPER system property, falling back to the environment variable CuratorFrameworkBuilder.AIE_ZOOKEEPER. The connection information and its source are logged at the DEBUG level.
        Parameters:
        logError - if true logs an error if no connection information is found.
        Returns:
        the ZooKeeper connection information to use for Curator
      • setConnectionInfo

        public static void setConnectionInfo​(java.lang.String zkConnectionInfo)
        Sets the connection string that will be used by Curator for contacting ZooKeeper. Note, the presence of this connection information is what triggers Platform.baseport() to contact ZooKeeper to get the baseport. In a testing situation where the TestingConfigServer has not been activated, this will cause long delays before timeouts kick in. If zkConnectionInfo is the same as a previous call, this method is a no-op. If the connection information is different all ZooKeeper related services are reset and the new connection is made.
        Parameters:
        zkConnectionInfo -
      • instance

        public static org.apache.curator.framework.CuratorFramework instance()
      • shutdown

        public static void shutdown()
      • getLastResetDate

        public static java.util.Date getLastResetDate()
        Will block until any executing reset has completed.
        Returns:
        The Date of the last call to #reset().
      • reset

        public static void reset​(boolean clearServices,
                                 java.lang.String host,
                                 java.lang.String nodeName,
                                 java.lang.String projectName,
                                 java.lang.String envName)
      • serviceInstanceBuilder

        public static org.apache.curator.x.discovery.ServiceInstanceBuilder<AieServiceInfo> serviceInstanceBuilder()
                                                                                                            throws AttivioException
        The Curator service discovery framework will initialize the address for a service to the IP address of the first NIC found on the host. Sometimes this may not be an externally accessible IP address. The Attivio project contains the configured host name or IP address of the project for this node, so it should be used if available. It is not supported to get an instance of the ServiceInstanceBuilder from any other source than this method.
        Returns:
        a ServiceInstance builder with the host address properly set.
        Throws:
        AttivioException - if the builder cannot be created (likely a zk connection issue)