Package com.attivio.service
Class CuratorHelper
- java.lang.Object
-
- com.attivio.service.CuratorHelper
-
public class CuratorHelper extends java.lang.Object
Class for obtaining an initializedCuratorFramework
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 Summary
Fields Modifier and Type Field Description static java.lang.String
AIE_SERVICES_PROPFILE
If defined, this file will be used to load the aie.services definitions.static java.lang.String
CURATOR_DEFAULT_CONNECTION_TIMEOUT_PROP
static java.lang.String
CURATOR_DEFAULT_SESSION_TIMEOUT_PROP
Property name for the session timeoutstatic java.lang.String
DEFAULT_AIE_SERVICES_PROPERTIES
static java.lang.String
DEFAULT_CONNECTION_TIMEOUT
static java.lang.String
DEFAULT_SESSION_TIMEOUT
static java.lang.String
ROOT
Root node for all Attivio ZooKeeper pathsstatic java.lang.String
ZOO_URI_SCHEME
zoo 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.String
getConnectionInfo()
Retrieves the configured connection information, first from theCuratorFrameworkBuilder.AIE_ZOOKEEPER
system property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER
.static java.lang.String
getConnectionInfo(boolean logError)
Retrieves the configured connection information, first from theCuratorFrameworkBuilder.AIE_ZOOKEEPER
system property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER
.static java.util.Date
getLastResetDate()
Will block until any executing reset has completed.static org.apache.curator.framework.CuratorFramework
instance()
static java.util.Properties
loadProperties()
Loads and returns properties associated with Attivio services.static void
reset(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 void
setConnectionInfo(java.lang.String zkConnectionInfo)
Sets the connection string that will be used by Curator for contacting ZooKeeper.static void
shutdown()
-
-
-
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_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
-
-
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_PROPERTIES
on the classpath. The system propertyAIE_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 theCuratorFrameworkBuilder.AIE_ZOOKEEPER
system property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER
. The connection information and its source are logged and theDEBUG
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 theCuratorFrameworkBuilder.AIE_ZOOKEEPER
system property, falling back to the environment variableCuratorFrameworkBuilder.AIE_ZOOKEEPER
. The connection information and its source are logged at theDEBUG
level.- Parameters:
logError
- iftrue
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 triggersPlatform.baseport()
to contact ZooKeeper to get the baseport. In a testing situation where theTestingConfigServer
has not been activated, this will cause long delays before timeouts kick in. IfzkConnectionInfo
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)
-
-