public static void validatePorts(Port plainTextPort, Port sslPort, Port http2Port, boolean sslRequired) {
    if (sslRequired && sslPort == null && http2Port == null) {
      throw new IllegalArgumentException("No SSL port to a data node to which SSL is enabled.");
    }

    if (plainTextPort.getPort() < MIN_PORT || plainTextPort.getPort() > MAX_PORT) {
      throw new IllegalArgumentException(
          "PlainText Port " + plainTextPort.getPort() + " not in valid range [" + MIN_PORT + " - " + MAX_PORT + "]");
    }
    if (!sslRequired) {
      return;
    }
    // check ports duplication
    Set<Integer> ports = new HashSet<Integer>();
    ports.add(plainTextPort.getPort());

    if (sslPort != null) {
      if (sslPort.getPort() < MIN_PORT || sslPort.getPort() > MAX_PORT) {
        throw new IllegalArgumentException(
            "SSL Port " + sslPort.getPort() + " not in valid range [" + MIN_PORT + " - " + MAX_PORT + "]");
      }
      if (!ports.add(sslPort.getPort())) {
        throw new IllegalArgumentException("Port number duplication found. " + ports);
      }
    }

    if (http2Port != null) {
      if (http2Port.getPort() < MIN_PORT || http2Port.getPort() > MAX_PORT) {
        throw new IllegalArgumentException(
            "HTTP2 Port " + http2Port.getPort() + " not in valid range [" + MIN_PORT + " - " + MAX_PORT + "]");
      }
      if (!ports.add(http2Port.getPort())) {
        throw new IllegalArgumentException("Port number duplication found. " + ports);
      }
    }
  }
Validate plainTextPort, sslPort and http2Port.
@param plainTextPort PlainText {@link Port}.
@param sslPort SSL {@link Port}.
@param http2Port HTTP2 SSL {@link Port}.
@param sslRequired if ssl encrypted port needed.
@throws IllegalArgumentException if ports are not valid.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/ClusterMapUtils.java