Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-33917] fix hostname can't be null for certain edgecases #738

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
Expand Down Expand Up @@ -234,23 +235,29 @@ public JobID submitJobToSessionCluster(

@Override
public boolean isJobManagerPortReady(Configuration config) {
final URI uri;
SocketAddress socketAddress;
try (var clusterClient = getClusterClient(config)) {
uri = URI.create(clusterClient.getWebInterfaceURL());
socketAddress = getSocketAddress(clusterClient);

} catch (Exception ex) {
throw new FlinkRuntimeException(ex);
}
SocketAddress socketAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
Socket socket = new Socket();
try {

try (Socket socket = new Socket()) {
socket.connect(socketAddress, 1000);
socket.close();
return true;
} catch (IOException e) {
return false;
}
}

protected SocketAddress getSocketAddress(RestClusterClient<String> clusterClient)
throws MalformedURLException {
final URL url = new URL(clusterClient.getWebInterfaceURL());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flink uses URL to create this String. Hence using URL to extract the hostname makes sense. URI fails to interpret the host name correctly in certain URLs like http://test.01-bla:8081 and treats it as a different part of an URI.

LOG.debug("JobManager webinterface url {}", clusterClient.getWebInterfaceURL());
return new InetSocketAddress(url.getHost(), url.getPort());
}

@Override
public Collection<JobStatusMessage> listJobs(Configuration conf) throws Exception {
try (var clusterClient = getClusterClient(conf)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import static org.apache.flink.kubernetes.operator.api.status.SavepointFormatType.NATIVE;
import static org.apache.flink.kubernetes.operator.config.FlinkConfigBuilder.FLINK_VERSION;
import static org.apache.flink.kubernetes.operator.config.KubernetesOperatorConfigOptions.OPERATOR_SAVEPOINT_FORMAT_TYPE;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -1024,6 +1025,26 @@ public String getWebInterfaceURL() {
}
}

@ParameterizedTest
@ValueSource(
strings = {"http://127.0.0.1:8081", "http://dev-test:8081", "http://dev-test.01:8081"})
void testValidSocketAddresses(String inputAddress) throws Exception {

var clusterClient =
new TestingClusterClient<String>(configuration) {
@Override
public String getWebInterfaceURL() {
return inputAddress;
}
};
var flinkService = new TestingService(clusterClient);

assertDoesNotThrow(
() -> {
flinkService.getSocketAddress(clusterClient);
});
}

class TestingService extends AbstractFlinkService {

RestClusterClient<String> clusterClient;
Expand Down