Skip to content
Permalink
Browse files

Merge pull request #131 from oleg-nenashev/bug/JENKINS-39596

[JENKINS-39596,JENKINS-39617] - hudsonUrl in Remoting Engine was always null since 3.0
  • Loading branch information
oleg-nenashev committed Nov 9, 2016
2 parents fa398e1 + 837bfeb commit e0cfb18cc844d6f027df64f76c9b3fc0aa4ec2bb
@@ -128,6 +128,7 @@ public void run() {
* This value is determined from {@link #candidateUrls} after a successful connection.
* Note that this URL <b>DOES NOT</b> have "tcpSlaveAgentListener" in it.
*/
@CheckForNull
private URL hudsonUrl;

private final String secretKey;
@@ -171,6 +172,12 @@ public void setJarCache(JarCache jarCache) {
this.jarCache = jarCache;
}

/**
* Provides Jenkins URL if available.
* @return Jenkins URL. May return {@code null} if the connection is not established or if the URL cannot be determined
* in the {@link JnlpAgentEndpointResolver}.
*/
@CheckForNull
public URL getHudsonUrl() {
return hudsonUrl;
}
@@ -334,6 +341,7 @@ private void innerRun(IOHub hub, SSLContext context, ExecutorService service) {
events.status("Could not resolve server among " + candidateUrls);
return;
}
hudsonUrl = endpoint.getServiceUrl();

events.status(String.format("Agent discovery successful%n"
+ " Agent address: %s%n"
@@ -29,6 +29,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URL;
import java.nio.channels.SocketChannel;
import java.security.interfaces.RSAPublicKey;
import java.util.Collections;
@@ -65,24 +66,44 @@
*/
@CheckForNull
private final Set<String> protocols;

/**
* Jenkins URL for the discovered endpoint.
* @since TODO
*/
@CheckForNull
private final URL serviceUrl;

/**
* @deprecated Use {@link #JnlpAgentEndpoint(java.lang.String, int, java.security.interfaces.RSAPublicKey, java.util.Set, java.lang.String)}
*/
@Deprecated
public JnlpAgentEndpoint(@Nonnull String host, int port, @CheckForNull RSAPublicKey publicKey,
@CheckForNull Set<String> protocols) {
this(host, port, publicKey, protocols, null);
}

/**
* Constructor for a remote {@code Jenkins} instance.
*
* @param host the hostname.
* @param port the port.
* @param publicKey the {@code InstanceIdentity.getPublic()} of the remote instance (if known).
* @param protocols The supported protocols.
* @param serviceURL URL of the service hosting the remoting endpoint.
* Use {@code null} if it is not a web service or if the URL cannot be determined
* @since TODO
*/
public JnlpAgentEndpoint(@Nonnull String host, int port, @CheckForNull RSAPublicKey publicKey,
@CheckForNull Set<String> protocols) {
@CheckForNull Set<String> protocols, @CheckForNull URL serviceURL) {
if (port <= 0 || 65536 <= port) {
throw new IllegalArgumentException("Port " + port + " is not in the range 1-65535");
}
this.host = host;
this.port = port;
this.publicKey = publicKey;
this.protocols = protocols == null ? null : Collections.unmodifiableSet(new LinkedHashSet<String>(protocols));
this.serviceUrl = serviceURL;
}

/**
@@ -95,6 +116,15 @@ public InetSocketAddress getAddress() {
return new InetSocketAddress(host, port);
}

/**
* Retrieves URL of the web service providing the remoting endpoint.
* @return Service URL if available. {@code null} otherwise.
*/
@CheckForNull
public URL getServiceUrl() {
return serviceUrl;
}

/**
* Gets the hostname.
*
@@ -127,7 +127,16 @@ public void setTunnel(String tunnel) {
public JnlpAgentEndpoint resolve() throws IOException {
IOException firstError = null;
for (String jenkinsUrl : jenkinsUrls) {
URL salURL = toAgentListenerURL(jenkinsUrl);

final URL selectedJenkinsURL;
final URL salURL;
try {
selectedJenkinsURL = new URL(jenkinsUrl);
salURL = toAgentListenerURL(jenkinsUrl);
} catch (MalformedURLException ex) {
LOGGER.log(Level.WARNING, String.format("Cannot parse agent endpoint URL %s. Skipping it", jenkinsUrl), ex);
continue;
}

// find out the TCP port
HttpURLConnection con =
@@ -223,7 +232,8 @@ public int compare(String o1, String o2) {
if (tokens[0].length() > 0) host = tokens[0];
if (tokens[1].length() > 0) port = Integer.parseInt(tokens[1]);
}
return new JnlpAgentEndpoint(host, port, identity, agentProtocolNames);

return new JnlpAgentEndpoint(host, port, identity, agentProtocolNames, selectedJenkinsURL);
} finally {
con.disconnect();
}

0 comments on commit e0cfb18

Please sign in to comment.
You can’t perform that action at this time.