Class ConsulUtils


  • public class ConsulUtils
    extends Object
    • Constructor Detail

      • ConsulUtils

        public ConsulUtils()
    • Method Detail

      • isSame

        public static boolean isSame​(List<URL> urls1,
                                     List<URL> urls2)
        Check if two lists have the same urls.
        Parameters:
        urls1 - first url list
        urls2 - second url list
        Returns:
        boolean true when they are the same
      • buildService

        public static ConsulService buildService​(URL url)
        build consul service from url
        Parameters:
        url - a URL object
        Returns:
        ConsulService consul service
      • buildUrl

        public static URL buildUrl​(String protocol,
                                   ConsulService service)
        build url from service
        Parameters:
        protocol - the protocol of the service
        service - consul service
        Returns:
        URL object
      • getUrlClusterInfo

        public static String getUrlClusterInfo​(URL url)
        get cluster info from url, cluster info (protocol, path)
        Parameters:
        url - a URL object
        Returns:
        String url cluster info
      • convertGroupToServiceName

        public static String convertGroupToServiceName​(String group)
        convert group to service name
        Parameters:
        group - group
        Returns:
        String service name
      • getGroupFromServiceName

        public static String getGroupFromServiceName​(String group)
        get group from consul service
        Parameters:
        group - group
        Returns:
        group
      • convertConsulSerivceId

        public static String convertConsulSerivceId​(URL url)
        convert url to consul service id. serviceid includes ip+port+service
        Parameters:
        url - a URL object
        Returns:
        service id
      • getPathFromServiceId

        public static String getPathFromServiceId​(String serviceId)
        get path of url from service id in consul
        Parameters:
        serviceId - service id
        Returns:
        path
      • getProtocolFromTag

        public static String getProtocolFromTag​(String tag)
        get protocol from consul tag
        Parameters:
        tag - tag
        Returns:
        protocol
      • convertServiceId

        public static String convertServiceId​(String host,
                                              int port,
                                              String path)
      • getWaitInSecond

        public static int getWaitInSecond​(String wait)
        convert the string wait to integer seconds from the config file. The possible format might be 600s or 10m etc. And the result will be 600 after the conversion.
        Parameters:
        wait - String format of wait from the config
        Returns:
        int of the wait seconds
      • getTimeoutBufferInSecond

        public static int getTimeoutBufferInSecond​(String timeoutBuffer)
        convert the string timeoutBuffer to integer seconds from the config file. The possible format might be 600s or 10m etc. And the result will be 600 after the conversion. Default timeoutBuffer value is 5s
        Parameters:
        timeoutBuffer - String format of timeoutBuffer from the config
        Returns:
        int of the timeoutBuffer in seconds