Skip to content
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.
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
Expand Up @@ -63,6 +63,20 @@ public class Conductor implements AutoCloseable {

private static final Logger logger = LoggerFactory.getLogger(Conductor.class);

private static final String hostname = resolveHostname();

private static String resolveHostname() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
return fallbackHostname(System.getenv("HOSTNAME"));
}
}

static String fallbackHostname(String envHostname) {
return envHostname != null ? envHostname : "<unknown>";
}

private final String url;
private final SystemDatabase systemDatabase;
private final DBOSExecutor dbosExecutor;
Expand Down Expand Up @@ -741,7 +755,6 @@ static CompletableFuture<BaseResponse> handleExecutorInfo(
return CompletableFuture.supplyAsync(
() -> {
try {
String hostname = InetAddress.getLocalHost().getHostName();
return new ExecutorInfoResponse(
message,
conductor.dbosExecutor.executorId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.java_websocket.handshake.ClientHandshake;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.RetryingTest;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand Down Expand Up @@ -526,6 +527,16 @@ public void canExecutorInfo() throws Exception {
}
}

@Test
public void fallbackHostnameUsesEnvWhenSet() {
assertEquals("env-host", Conductor.fallbackHostname("env-host"));
}

@Test
public void fallbackHostnameUsesUnknownWhenNull() {
assertEquals("<unknown>", Conductor.fallbackHostname(null));
}

@RetryingTest(3)
public void canExecutorInfoWithMetadata() throws Exception {
MessageListener listener = new MessageListener();
Expand Down