public static @Nullable URI getServerUri(@Nullable String host, @Nullable String portString) throws
          URISyntaxException {
    if (host == null) {
      host = System.getenv(ENV_SERVER);
    }
    if (host == null) {
      host = System.getProperty(PROP_HOST);
    }
    if (host == null) {
      host = DEFAULT_HOST;
    }
    host = host.trim();

    if ((portString == null || portString.isEmpty() || portString.equals("0")) &&
            !host.contains(":")) {
      portString = System.getenv(ENV_PORT);
      if (portString == null) {
        portString = System.getProperty(PROP_PORT);
      }
    }
    Integer port = Constants.HMS_DEFAULT_PORT;
    if (portString != null) {
      port = Integer.parseInt(portString);
    }

    HostAndPort hp = HostAndPort.fromString(host)
            .withDefaultPort(port);

    LOG.info("Connecting to {}:{}", hp.getHost(), hp.getPort());

    return new URI(THRIFT_SCHEMA, null, hp.getHost(), hp.getPort(),
            null, null, null);
  }
Get server URI.<p>
HMS host is obtained from
<ol>
<li>Argument</li>
<li>HMS_HOST environment parameter</li>
<li>hms.host Java property</li>
<li>use 'localhost' if above fails</li>
</ol>
HMS Port is obtained from
<ol>
<li>Argument</li>
<li>host:port string</li>
<li>HMS_PORT environment variable</li>
<li>hms.port Java property</li>
<li>default port value</li>
</ol>

@param host       HMS host string.
@param portString HMS port
@return HMS URI
@throws URISyntaxException if URI is is invalid
standalone-metastore/metastore-tools/tools-common/src/main/java/org/apache/hadoop/hive/metastore/tools/Util.java