Skip to content

Commit

Permalink
Migrate to new Remoting calling conventions (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Oct 24, 2023
1 parent 1a9cbe3 commit 85c612a
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions client/src/main/java/hudson/plugins/swarm/SwarmClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.sun.net.httpserver.HttpServer;
import hudson.remoting.Launcher;
import hudson.remoting.jnlp.Main;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmHeapPressureMetrics;
Expand Down Expand Up @@ -38,7 +37,6 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
Expand Down Expand Up @@ -142,17 +140,10 @@ List<String> getJnlpArgs(URL url) throws IOException, RetryException {
launcher.agentJnlpURL = new URL(url + "computer/" + name + "/slave-agent.jnlp");

if (options.username != null && options.password != null) {
launcher.auth = options.username + ":" + options.password;
launcher.agentJnlpCredentials = options.username + ":" + options.password;
}

if (options.disableSslVerification) {
try {
launcher.setNoCertificateCheck(true);
} catch (KeyManagementException | NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
launcher.noCertificateCheck = options.disableSslVerification;

try {
return launcher.parseJnlpArguments();
Expand All @@ -168,14 +159,18 @@ List<String> getJnlpArgs(URL url) throws IOException, RetryException {
*/
void connect(List<String> jnlpArgs, URL url) throws IOException, RetryException {
List<String> args = new ArrayList<>();
args.add(jnlpArgs.get(0));
args.add(jnlpArgs.get(1));

args.add("-url");
args.add(url.toString());

args.add("-secret");
args.add(jnlpArgs.get(0));

args.add("-name");
args.add(name);

if (options.disableSslVerification) {
args.add("-disableHttpsCertValidation");
args.add("-noCertificateCheck");
}

// if the tunnel option is set in the command line, use it
Expand Down Expand Up @@ -214,9 +209,9 @@ void connect(List<String> jnlpArgs, URL url) throws IOException, RetryException

/*
* Swarm does its own retrying internally, so disable the retrying functionality in
* hudson.remoting.Engine.
* Remoting.
*/
args.add("-noreconnect");
args.add("-noReconnect");

if (options.webSocket) {
args.add("-webSocket");
Expand All @@ -230,9 +225,9 @@ void connect(List<String> jnlpArgs, URL url) throws IOException, RetryException
}

try {
Main.main(args.toArray(new String[0]));
Launcher.main(args.toArray(new String[0]));
} catch (InterruptedException | RuntimeException e) {
throw new RetryException("Failed to establish JNLP connection to " + url, e);
throw new RetryException("Failed to establish connection to " + url, e);
}
}

Expand Down

0 comments on commit 85c612a

Please sign in to comment.