Class ClusterMapUtils


  • public class ClusterMapUtils
    extends java.lang.Object
    A class with clustermap related utility methods for use by other classes.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ClusterMapUtils.DcZkInfo
      Stores all zk related info for a DC.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClusterMapUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getDcName​(org.apache.helix.model.InstanceConfig instanceConfig)
      Get the datacenter name associated with the given instance.
      static java.lang.String getDcName​(org.apache.helix.zookeeper.datamodel.ZNRecord znRecord)
      Get the datacenter name associated with the given instance.
      static java.util.List<java.lang.String> getDisabledReplicas​(org.apache.helix.model.InstanceConfig instanceConfig)
      Get the list of disabled replicas on a given instance.
      static java.util.List<java.lang.String> getDisabledReplicas​(org.apache.helix.zookeeper.datamodel.ZNRecord znRecord)
      Get the list of disabled replicas on a given instance.
      static java.lang.String getFullyQualifiedDomainName​(java.lang.String unqualifiedHostname)
      Converts a hostname into a canonical hostname.
      static java.lang.Integer getHttp2PortStr​(org.apache.helix.model.InstanceConfig instanceConfig)
      Get the http2 port associated with the given instance (if any).
      static java.lang.String getInstanceName​(java.lang.String host, java.lang.Integer port)
      Construct and return the instance name given the host and port.
      static java.lang.Integer getSslPortStr​(org.apache.helix.model.InstanceConfig instanceConfig)
      Get the ssl port associated with the given instance (if any).
      static java.util.Map<java.lang.String,​ClusterMapUtils.DcZkInfo> parseDcJsonAndPopulateDcInfo​(java.lang.String dcInfoJsonString)
      Parses DC information JSON string and returns a map of datacenter name to ClusterMapUtils.DcZkInfo.
      static void validateHostName​(java.lang.Boolean clusterMapResolveHostnames, java.lang.String hostName)
      Validate hostName.
      static void validatePorts​(com.github.ambry.network.Port plainTextPort, com.github.ambry.network.Port sslPort, com.github.ambry.network.Port http2Port, boolean sslRequired)
      Validate plainTextPort, sslPort and http2Port.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PARTITION_OVERRIDE_STR

        public static final java.lang.String PARTITION_OVERRIDE_STR
        See Also:
        Constant Field Values
      • REPLICA_ADDITION_STR

        public static final java.lang.String REPLICA_ADDITION_STR
        See Also:
        Constant Field Values
      • PARTITION_DISABLED_STR

        public static final java.lang.String PARTITION_DISABLED_STR
        See Also:
        Constant Field Values
      • PROPERTYSTORE_STR

        public static final java.lang.String PROPERTYSTORE_STR
        See Also:
        Constant Field Values
      • ADMIN_CONFIG_ZNODE_PATH

        public static final java.lang.String ADMIN_CONFIG_ZNODE_PATH
        See Also:
        Constant Field Values
      • PARTITION_OVERRIDE_ZNODE_PATH

        public static final java.lang.String PARTITION_OVERRIDE_ZNODE_PATH
        See Also:
        Constant Field Values
      • REPLICA_ADDITION_ZNODE_PATH

        public static final java.lang.String REPLICA_ADDITION_ZNODE_PATH
        See Also:
        Constant Field Values
      • PARTITION_DISABLED_ZNODE_PATH

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

      • ClusterMapUtils

        public ClusterMapUtils()
    • Method Detail

      • getInstanceName

        public static java.lang.String getInstanceName​(java.lang.String host,
                                                       java.lang.Integer port)
        Construct and return the instance name given the host and port.
        Parameters:
        host - the hostname of the instance.
        port - the port of the instance. Can be null.
        Returns:
        the constructed instance name.
      • parseDcJsonAndPopulateDcInfo

        public static java.util.Map<java.lang.String,​ClusterMapUtils.DcZkInfo> parseDcJsonAndPopulateDcInfo​(java.lang.String dcInfoJsonString)
                                                                                                           throws org.json.JSONException
        Parses DC information JSON string and returns a map of datacenter name to ClusterMapUtils.DcZkInfo.
        Parameters:
        dcInfoJsonString - the string containing the DC info.
        Returns:
        a map of dcName -> DcInfo.
        Throws:
        org.json.JSONException - if there is an error parsing the JSON.
      • getDisabledReplicas

        public static java.util.List<java.lang.String> getDisabledReplicas​(org.apache.helix.model.InstanceConfig instanceConfig)
        Get the list of disabled replicas on a given instance. This is guaranteed to return a non-null list. It would return an empty list if there are no disabled replicas or if the field itself is absent for this instance.
        Parameters:
        instanceConfig - the InstanceConfig associated with the interested instance.
        Returns:
        the list of disabled replicas.
      • getDisabledReplicas

        public static java.util.List<java.lang.String> getDisabledReplicas​(org.apache.helix.zookeeper.datamodel.ZNRecord znRecord)
        Get the list of disabled replicas on a given instance. This is guaranteed to return a non-null list. It would return an empty list if there are no disabled replicas or if the field itself is absent for this instance.
        Parameters:
        znRecord - the ZNRecord associated with the interested instance.
        Returns:
        the list of disabled replicas.
      • getDcName

        public static java.lang.String getDcName​(org.apache.helix.model.InstanceConfig instanceConfig)
        Get the datacenter name associated with the given instance.
        Parameters:
        instanceConfig - the InstanceConfig associated with the interested instance.
        Returns:
        the datacenter name associated with the given instance.
      • getDcName

        public static java.lang.String getDcName​(org.apache.helix.zookeeper.datamodel.ZNRecord znRecord)
        Get the datacenter name associated with the given instance.
        Parameters:
        znRecord - the ZNRecord associated with the interested instance.
        Returns:
        the datacenter name associated with the given instance.
      • getSslPortStr

        public static java.lang.Integer getSslPortStr​(org.apache.helix.model.InstanceConfig instanceConfig)
        Get the ssl port associated with the given instance (if any).
        Parameters:
        instanceConfig - the InstanceConfig associated with the interested instance.
        Returns:
        the ssl port associated with the given instance.
      • getHttp2PortStr

        public static java.lang.Integer getHttp2PortStr​(org.apache.helix.model.InstanceConfig instanceConfig)
        Get the http2 port associated with the given instance (if any).
        Parameters:
        instanceConfig - the InstanceConfig associated with the interested instance.
        Returns:
        the http2 port associated with the given instance.
      • getFullyQualifiedDomainName

        public static java.lang.String getFullyQualifiedDomainName​(java.lang.String unqualifiedHostname)
        Converts a hostname into a canonical hostname.
        Parameters:
        unqualifiedHostname - hostname to be fully qualified
        Returns:
        canonical hostname that can be compared with DataNode.getHostname()
      • validateHostName

        public static void validateHostName​(java.lang.Boolean clusterMapResolveHostnames,
                                            java.lang.String hostName)
        Validate hostName.
        Parameters:
        clusterMapResolveHostnames - indicates if a reverse DNS lookup is enabled or not.
        hostName - hostname to be validated.
        Throws:
        java.lang.IllegalArgumentException - if hostname is not valid.
      • validatePorts

        public static void validatePorts​(com.github.ambry.network.Port plainTextPort,
                                         com.github.ambry.network.Port sslPort,
                                         com.github.ambry.network.Port http2Port,
                                         boolean sslRequired)
        Validate plainTextPort, sslPort and http2Port.
        Parameters:
        plainTextPort - PlainText Port.
        sslPort - SSL Port.
        http2Port - HTTP2 SSL Port.
        sslRequired - if ssl encrypted port needed.
        Throws:
        java.lang.IllegalArgumentException - if ports are not valid.