提交 694764e6 编写于 作者: A Alexander Link 提交者: Oleg Nenashev

Introduce new hudson.TcpSlaveAgentListener.getAdvertisedHost() method (#4227)

* Introduced hudson.TcpSlaveAgentListener.getAdvertisedHost()

* review feedback

* better error message
上级 f5385ea3
...@@ -43,6 +43,7 @@ import java.io.DataOutputStream; ...@@ -43,6 +43,7 @@ import java.io.DataOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import jenkins.AgentProtocol; import jenkins.AgentProtocol;
...@@ -55,6 +56,7 @@ import java.io.OutputStreamWriter; ...@@ -55,6 +56,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.BindException; import java.net.BindException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Socket; import java.net.Socket;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -131,6 +133,21 @@ public final class TcpSlaveAgentListener extends Thread { ...@@ -131,6 +133,21 @@ public final class TcpSlaveAgentListener extends Thread {
return CLI_PORT != null ? CLI_PORT : getPort(); return CLI_PORT != null ? CLI_PORT : getPort();
} }
/**
* Gets the host name that we advertise protocol clients to connect to.
* @since TODO
*/
public String getAdvertisedHost() {
if (CLI_HOST_NAME != null) {
return CLI_HOST_NAME;
}
try {
return new URL(Jenkins.get().getRootUrl()).getHost();
} catch (MalformedURLException | NullPointerException e) {
throw new IllegalStateException("Could not get TcpSlaveAgentListener host name", e);
}
}
/** /**
* Gets the Base64 encoded public key that forms part of this instance's identity keypair. * Gets the Base64 encoded public key that forms part of this instance's identity keypair.
* @return the Base64 encoded public key * @return the Base64 encoded public key
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册