Search in sources :

Example 21 with KsqlServerException

use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.

the class KsqlRestConfig method sanitizeInterNodeListener.

/**
 * Used to sanitize the first `listener` config.
 *
 * <p>It will:
 * <ul>
 *    <li>resolve any auto-port assignment to the actual port the server is listening on</li>
 *    <li>potentially, replace the host with localhost. This can be useful where the first
 *    listener is a wildcard address, e.g. {@code 0.0.0.0}/li>
 * </ul>
 *
 * @param listener the URL to sanitize
 * @param portResolver the function to call to resolve the port.
 * @param replaceHost flag indicating if the host in the URL should be replaced with localhost.
 * @return the sanitized URL.
 */
private static URL sanitizeInterNodeListener(final URL listener, final Function<URL, Integer> portResolver, final boolean replaceHost) {
    final String host = replaceHost ? getLocalHostName() : listener.getHost();
    final int port = listener.getPort() == 0 ? portResolver.apply(listener) : listener.getPort();
    try {
        return new URL(listener.getProtocol(), host, port, "");
    } catch (final MalformedURLException e) {
        throw new KsqlServerException("Resolved first listener to malformed URL", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ValidString(org.apache.kafka.common.config.ConfigDef.ValidString) URL(java.net.URL) KsqlServerException(io.confluent.ksql.util.KsqlServerException)

Aggregations

KsqlServerException (io.confluent.ksql.util.KsqlServerException)21 KsqlException (io.confluent.ksql.util.KsqlException)13 ExecutionException (java.util.concurrent.ExecutionException)10 RetryException (com.github.rholder.retry.RetryException)8 URISyntaxException (java.net.URISyntaxException)8 List (java.util.List)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 MetaStore (io.confluent.ksql.metastore.MetaStore)3 Statement (io.confluent.ksql.parser.tree.Statement)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Builder (com.google.common.collect.ImmutableList.Builder)2 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)2 ServiceInfo (io.confluent.ksql.ServiceInfo)2 Analysis (io.confluent.ksql.analyzer.Analysis)2 ImmutableAnalysis (io.confluent.ksql.analyzer.ImmutableAnalysis)2 QueryAnalyzer (io.confluent.ksql.analyzer.QueryAnalyzer)2 RewrittenAnalysis (io.confluent.ksql.analyzer.RewrittenAnalysis)2