diff --git a/flink-clients/src/main/java/org/apache/flink/client/ClientUtils.java b/flink-clients/src/main/java/org/apache/flink/client/ClientUtils.java deleted file mode 100644 index 03f2f8e791ca47..00000000000000 --- a/flink-clients/src/main/java/org/apache/flink/client/ClientUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.client; - -import java.net.InetSocketAddress; -import java.net.URI; -import java.net.URISyntaxException; - -/** - * A class that provides some utility methods. - */ -public class ClientUtils { - /** - * Utility method that converts a string of the form "host:port" into an {@link InetSocketAddress}. - * The returned InetSocketAddress may be unresolved! - * - * @param hostport The "host:port" string. - * @return The converted InetSocketAddress. - */ - public static InetSocketAddress parseHostPortAddress(String hostport) { - // from http://stackoverflow.com/questions/2345063/java-common-way-to-validate-and-convert-hostport-to-inetsocketaddress - URI uri; - try { - uri = new URI("my://" + hostport); - } catch (URISyntaxException e) { - throw new RuntimeException("Could not identify hostname and port in '" + hostport + "'.", e); - } - String host = uri.getHost(); - int port = uri.getPort(); - if (host == null || port == -1) { - throw new RuntimeException("Could not identify hostname and port in '" + hostport + "'."); - } - return new InetSocketAddress(host, port); - } -} diff --git a/flink-clients/src/main/java/org/apache/flink/client/RemoteExecutor.java b/flink-clients/src/main/java/org/apache/flink/client/RemoteExecutor.java index 51506fae3a8fa1..183077649bfb6e 100644 --- a/flink-clients/src/main/java/org/apache/flink/client/RemoteExecutor.java +++ b/flink-clients/src/main/java/org/apache/flink/client/RemoteExecutor.java @@ -32,6 +32,7 @@ import org.apache.flink.optimizer.costs.DefaultCostEstimator; import org.apache.flink.optimizer.plan.OptimizedPlan; import org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator; +import org.apache.flink.util.NetUtils; import java.net.InetSocketAddress; import java.net.URL; @@ -73,7 +74,7 @@ public RemoteExecutor(String hostname, int port, URL jarFile) { } public RemoteExecutor(String hostport, URL jarFile) { - this(ClientUtils.parseHostPortAddress(hostport), new Configuration(), Collections.singletonList(jarFile), + this(NetUtils.parseHostPortAddress(hostport), new Configuration(), Collections.singletonList(jarFile), Collections.emptyList()); } @@ -93,7 +94,7 @@ public RemoteExecutor(String hostname, int port, Configuration clientConfigurati } public RemoteExecutor(String hostport, Configuration clientConfiguration, URL jarFile) { - this(ClientUtils.parseHostPortAddress(hostport), clientConfiguration, + this(NetUtils.parseHostPortAddress(hostport), clientConfiguration, Collections.singletonList(jarFile), Collections.emptyList()); } diff --git a/flink-clients/src/main/java/org/apache/flink/client/cli/AbstractCustomCommandLine.java b/flink-clients/src/main/java/org/apache/flink/client/cli/AbstractCustomCommandLine.java index 484c391f0d932c..0cae6e72e6f97b 100644 --- a/flink-clients/src/main/java/org/apache/flink/client/cli/AbstractCustomCommandLine.java +++ b/flink-clients/src/main/java/org/apache/flink/client/cli/AbstractCustomCommandLine.java @@ -18,11 +18,11 @@ package org.apache.flink.client.cli; -import org.apache.flink.client.ClientUtils; import org.apache.flink.configuration.Configuration; import org.apache.flink.configuration.HighAvailabilityOptions; import org.apache.flink.configuration.UnmodifiableConfiguration; import org.apache.flink.util.FlinkException; +import org.apache.flink.util.NetUtils; import org.apache.flink.util.Preconditions; import org.apache.commons.cli.CommandLine; @@ -80,7 +80,7 @@ protected Configuration applyCommandLineOptionsToConfiguration(CommandLine comma if (commandLine.hasOption(addressOption.getOpt())) { String addressWithPort = commandLine.getOptionValue(addressOption.getOpt()); - InetSocketAddress jobManagerAddress = ClientUtils.parseHostPortAddress(addressWithPort); + InetSocketAddress jobManagerAddress = NetUtils.parseHostPortAddress(addressWithPort); setJobManagerAddressInConfig(resultingConfiguration, jobManagerAddress); } diff --git a/flink-core/src/main/java/org/apache/flink/util/NetUtils.java b/flink-core/src/main/java/org/apache/flink/util/NetUtils.java index 1a4bb7a829f12b..11dad734304f9b 100644 --- a/flink-core/src/main/java/org/apache/flink/util/NetUtils.java +++ b/flink-core/src/main/java/org/apache/flink/util/NetUtils.java @@ -77,7 +77,7 @@ public static String getHostnameFromFQDN(String fqdn) { * * @return URL object for accessing host and Port */ - public static URL getCorrectHostnamePort(String hostPort) { + private static URL validateHostPort(String hostPort) { try { URL u = new URL("http://" + hostPort); if (u.getHost() == null) { @@ -92,6 +92,25 @@ public static URL getCorrectHostnamePort(String hostPort) { } } + /** + * Validates the "host:port" string and returns a url. + * + * @return URL object for accessing host and Port + */ + public static URL getCorrectHostnamePort(String hostPort) { + return validateHostPort(hostPort); + } + + /** + * Validates the "hostname:port" string and returns a socket address. + * + * @return InetSocketAddress object for accessing host and Port + */ + public static InetSocketAddress parseHostPortAddress(String hostPort) { + URL url = validateHostPort(hostPort); + return new InetSocketAddress(url.getHost(), url.getPort()); + } + // ------------------------------------------------------------------------ // Lookup of to free ports // ------------------------------------------------------------------------