Skip to content

Commit

Permalink
FLINK-13317 Merge NetUtils and ClientUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
xuchao0903 committed Jul 19, 2019
1 parent 2975f3e commit 5e56dc9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 56 deletions.

This file was deleted.

Expand Up @@ -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;
Expand Down Expand Up @@ -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.<URL>emptyList());
}

Expand All @@ -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.<URL>emptyList());
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
21 changes: 20 additions & 1 deletion flink-core/src/main/java/org/apache/flink/util/NetUtils.java
Expand Up @@ -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) {
Expand All @@ -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
// ------------------------------------------------------------------------
Expand Down

0 comments on commit 5e56dc9

Please sign in to comment.