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

fix(sdk): fixed fqdn name query on ECS instances #245

Open
wants to merge 2 commits into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.consoleconnect.kraken.operator.core.toolkit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -53,9 +56,17 @@ public static String getHostAddress() {

public static String getFQDN() {
try {
InetAddress address = InetAddress.getLocalHost();
return address.getCanonicalHostName();
} catch (UnknownHostException e) {
ProcessBuilder builder = new ProcessBuilder();
builder.command("bash", "-c", "hostname -f");
Process process = builder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
StringBuilder result = new StringBuilder();
while ((line = reader.readLine()) != null) {
result.append(line);
}
return result.toString();
} catch (IOException e) {
return IP_UNKNOWN;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ void givenRequest_whenGetIpAddress_thenReturnIpAddress() {
String ip = IpUtils.getIP(request);
Assertions.assertNotNull(ip);
}

@Test
void givenECS_whenQueryFQDN_thenReturnSuccess() {
String result = IpUtils.getFQDN();
Assertions.assertNotEquals("unknown", result);
}
}