Package com.attivio.service
Class CuratorHelper
- java.lang.Object
-
- com.attivio.service.CuratorHelper
-
public class CuratorHelper extends java.lang.ObjectClass for obtaining an initializedCuratorFrameworkinstance. 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_PROPFILEsystem property may be used to override the location of this file.Property Description curator.framework.builder The classname for the desired CuratorFrameworkBuildercurator.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 Summary
Fields Modifier and Type Field Description static java.lang.StringAIE_SERVICES_PROPFILEIf defined, this file will be used to load the aie.services definitions.static java.lang.StringCURATOR_DEFAULT_CONNECTION_TIMEOUT_PROPstatic java.lang.StringCURATOR_DEFAULT_SESSION_TIMEOUT_PROPProperty name for the session timeoutstatic java.lang.StringDEFAULT_AIE_SERVICES_PROPERTIESstatic java.lang.StringDEFAULT_CONNECTION_TIMEOUTstatic java.lang.StringDEFAULT_SESSION_TIMEOUTstatic java.lang.StringROOTRoot node for all Attivio ZooKeeper pathsstatic java.lang.StringZOO_URI_SCHEMEzoo URI scheme name
-
Constructor Summary
Constructors Constructor Description CuratorHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetConnectionInfo()Retrieves the configured connection information, first from theCuratorFrameworkBuilder.AIE_ZOOKEEPERsystem property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER.static java.lang.StringgetConnectionInfo(boolean logError)Retrieves the configured connection information, first from theCuratorFrameworkBuilder.AIE_ZOOKEEPERsystem property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER.static java.util.DategetLastResetDate()Will block until any executing reset has completed.static org.apache.curator.framework.CuratorFrameworkinstance()static java.util.PropertiesloadProperties()Loads and returns properties associated with Attivio services.static voidreset(boolean clearServices, java.lang.String host, java.lang.String nodeName, java.lang.String projectName, java.lang.String envName)static org.apache.curator.x.discovery.ServiceInstanceBuilder<AieServiceInfo>serviceInstanceBuilder()The Curator service discovery framework will initialize the address for a service to the IP address of the first NIC found on the host.static voidsetConnectionInfo(java.lang.String zkConnectionInfo)Sets the connection string that will be used by Curator for contacting ZooKeeper.static voidshutdown()
-
-
-
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. OtherwiseDEFAULT_AIE_SERVICES_PROPERTIESwill 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
-
-
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 upDEFAULT_AIE_SERVICES_PROPERTIESon the classpath. The system propertyAIE_SERVICES_PROPFILEmay 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 theCuratorFrameworkBuilder.AIE_ZOOKEEPERsystem property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER. The connection information and its source are logged and theDEBUGlevel. 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 theCuratorFrameworkBuilder.AIE_ZOOKEEPERsystem property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER. The connection information and its source are logged at theDEBUGlevel.- Parameters:
logError- iftruelogs 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 triggersPlatform.baseport()to contact ZooKeeper to get the baseport. In a testing situation where theTestingConfigServerhas not been activated, this will cause long delays before timeouts kick in. IfzkConnectionInfois 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
Dateof 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
ServiceInstancebuilder with the host address properly set. - Throws:
AttivioException- if the builder cannot be created (likely a zk connection issue)
-
-