-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Simplifying JNLPLauncher
#8762
Simplifying JNLPLauncher
#8762
Changes from 4 commits
0d101a6
3be5ae0
601722a
457557d
44ebca2
ed5818a
8f57907
c6d02b4
d24f3fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,19 +34,16 @@ | |
import hudson.model.Computer; | ||
import hudson.model.Descriptor; | ||
import hudson.model.TaskListener; | ||
import hudson.util.FormValidation; | ||
import jenkins.model.Jenkins; | ||
import jenkins.model.identity.InstanceIdentityProvider; | ||
import jenkins.slaves.RemotingWorkDirSettings; | ||
import jenkins.util.SystemProperties; | ||
import jenkins.websocket.WebSockets; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.jenkinsci.Symbol; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.DoNotUse; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import org.kohsuke.stapler.QueryParameter; | ||
|
||
/** | ||
* {@link ComputerLauncher} via inbound connections. | ||
|
@@ -56,28 +53,23 @@ | |
*/ | ||
public class JNLPLauncher extends ComputerLauncher { | ||
/** | ||
* If the agent needs to tunnel the connection to the controller, | ||
* specify the "host:port" here. This can include the special | ||
* syntax "host:" and ":port" to indicate the default host/port | ||
* shall be used. | ||
* | ||
* <p> | ||
* Null if no tunneling is necessary. | ||
* | ||
* @since 1.250 | ||
* Deprecated (only used with deprecated {@code -jnlpUrl} mode), but cannot mark it as such without breaking CasC. | ||
*/ | ||
@DataBoundSetter | ||
@CheckForNull | ||
public final String tunnel; | ||
public String tunnel; | ||
|
||
/** | ||
* @deprecated No longer used. | ||
*/ | ||
@Deprecated | ||
public final transient String vmargs = null; | ||
|
||
@Deprecated | ||
@NonNull | ||
private RemotingWorkDirSettings workDirSettings = RemotingWorkDirSettings.getEnabledDefaults(); | ||
|
||
@Deprecated | ||
private boolean webSocket; | ||
|
||
/** | ||
|
@@ -88,14 +80,7 @@ | |
public static final String CUSTOM_INBOUND_URL_PROPERTY = "jenkins.agent.inboundUrl"; | ||
|
||
/** | ||
* Constructor. | ||
* @param tunnel Tunnel settings | ||
* @param vmargs JVM arguments | ||
* @param workDirSettings Settings for Work Directory management in Remoting. | ||
* If {@code null}, {@link RemotingWorkDirSettings#getEnabledDefaults()} | ||
* will be used to enable work directories by default in new agents. | ||
* @since 2.68 | ||
* @deprecated use {@link #JNLPLauncher(String, String)} and {@link #setWorkDirSettings(RemotingWorkDirSettings)} | ||
* @deprecated no useful properties, use {@link #JNLPLauncher()} | ||
*/ | ||
@Deprecated | ||
public JNLPLauncher(@CheckForNull String tunnel, @CheckForNull String vmargs, @CheckForNull RemotingWorkDirSettings workDirSettings) { | ||
|
@@ -105,36 +90,30 @@ | |
} | ||
} | ||
|
||
// TODO cannot easily make tunnel into a @DataBoundSetter because then the @DataBoundConstructor would be on a no-arg constructor | ||
// which is already defined and deprecated. Could retroactively let no-arg constructor use default for workDirSettings, | ||
// which would be a behavioral change only for callers of the Java constructor (unlikely). | ||
@DataBoundConstructor | ||
/** | ||
* @deprecated no useful properties, use {@link #JNLPLauncher()} | ||
*/ | ||
@Deprecated | ||
public JNLPLauncher(@CheckForNull String tunnel) { | ||
this.tunnel = Util.fixEmptyAndTrim(tunnel); | ||
} | ||
|
||
/** | ||
* @deprecated use {@link JNLPLauncher#JNLPLauncher(String)} | ||
* @deprecated no useful properties, use {@link #JNLPLauncher()} | ||
*/ | ||
@Deprecated | ||
public JNLPLauncher(@CheckForNull String tunnel, @CheckForNull String vmargs) { | ||
this.tunnel = Util.fixEmptyAndTrim(tunnel); | ||
} | ||
|
||
/** | ||
* @deprecated This Launcher does not enable the work directory. | ||
* It is recommended to use {@link #JNLPLauncher(boolean)} | ||
*/ | ||
@Deprecated | ||
@DataBoundConstructor | ||
public JNLPLauncher() { | ||
this(false); | ||
} | ||
|
||
/** | ||
* Constructor with default options. | ||
* | ||
* @param enableWorkDir If {@code true}, the work directory will be enabled with default settings. | ||
* @deprecated no useful properties, use {@link #JNLPLauncher()} | ||
*/ | ||
@Deprecated | ||
jglick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public JNLPLauncher(boolean enableWorkDir) { | ||
this(null, null, enableWorkDir | ||
? RemotingWorkDirSettings.getEnabledDefaults() | ||
|
@@ -150,16 +129,14 @@ | |
return this; | ||
} | ||
|
||
/** | ||
* Returns work directory settings. | ||
* | ||
* @since 2.72 | ||
*/ | ||
@NonNull | ||
@Deprecated | ||
public RemotingWorkDirSettings getWorkDirSettings() { | ||
return workDirSettings; | ||
} | ||
|
||
/** | ||
* Deprecated (only used with deprecated {@code -jnlpUrl} mode), but cannot mark it as such without breaking CasC. | ||
*/ | ||
@DataBoundSetter | ||
public final void setWorkDirSettings(@NonNull RemotingWorkDirSettings workDirSettings) { | ||
this.workDirSettings = workDirSettings; | ||
|
@@ -170,15 +147,13 @@ | |
return false; | ||
} | ||
|
||
/** | ||
* @since 2.216 | ||
*/ | ||
@Deprecated | ||
public boolean isWebSocket() { | ||
return webSocket; | ||
} | ||
|
||
/** | ||
* @since 2.216 | ||
* Deprecated (only used with deprecated {@code -jnlpUrl} mode), but cannot mark it as such without breaking CasC. | ||
*/ | ||
@DataBoundSetter | ||
public void setWebSocket(boolean webSocket) { | ||
|
@@ -210,6 +185,11 @@ | |
return getRemotingOptions(escapeWindows(computer.getName())); | ||
} | ||
|
||
@Restricted(DoNotUse.class) | ||
public boolean isConfigured() { | ||
return webSocket || tunnel != null || workDirSettings.isConfigured(); | ||
} | ||
|
||
private String getRemotingOptions(String computerName) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("-name "); | ||
|
@@ -296,25 +276,6 @@ | |
return DescriptorImpl.class.equals(getClass()); | ||
} | ||
|
||
public FormValidation doCheckWebSocket(@QueryParameter boolean webSocket, @QueryParameter String tunnel) { | ||
jglick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (webSocket) { | ||
if (!WebSockets.isSupported()) { | ||
return FormValidation.error(Messages.JNLPLauncher_WebsocketNotEnabled()); | ||
} | ||
if (Util.fixEmptyAndTrim(tunnel) != null) { | ||
return FormValidation.error(Messages.JNLPLauncher_TunnelingNotSupported()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and other improper combinations now handled by args4j in the launcher itself. |
||
} | ||
} else { | ||
if (Jenkins.get().getTcpSlaveAgentListener() == null) { | ||
return FormValidation.error(Messages.JNLPLauncher_TCPPortDisabled()); | ||
} | ||
if (InstanceIdentityProvider.RSA.getCertificate() == null || InstanceIdentityProvider.RSA.getPrivateKey() == null) { | ||
return FormValidation.error(Messages.JNLPLauncher_InstanceIdentityRequired()); | ||
} | ||
} | ||
return FormValidation.ok(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
configured=\ | ||
Configuring any properties on the inbound agent launcher is deprecated \ | ||
as it would only have an effect in deprecated <code>-jnlpUrl</code> mode. \ | ||
Instead pass any desired options to the agent yourself. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,28 +38,6 @@ THE SOFTWARE. | |
<j:set var="copy_java_cmd_unix" value="java -jar agent.jar -url ${jenkinsURL} ${it.launcher.getRemotingOptionsUnix(it)}${it.launcher.getWorkDirOptions(it)}" /> | ||
<j:set var="copy_java_cmd_windows" value="java -jar agent.jar -url ${jenkinsURL} ${it.launcher.getRemotingOptionsWindows(it)}${it.launcher.getWorkDirOptions(it)}" /> | ||
<j:if test="${h.hasPermission(it, it.CONNECT)}"> | ||
<j:choose> | ||
<j:when test="${it.ACL.hasPermission(app.ANONYMOUS, it.CONNECT)}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This clause tried to omit the |
||
<h3> | ||
${%slaveAgent.cli.run} (Unix) | ||
<l:copyButton text="${copy_agent_jar_unix};${copy_java_cmd_unix}"/> | ||
</h3> | ||
<pre> | ||
${copy_agent_jar_unix} | ||
${copy_java_cmd_unix} | ||
</pre> | ||
|
||
<h3> | ||
${%slaveAgent.cli.run} (Windows) | ||
<l:copyButton text="${copy_agent_jar_windows} & ${copy_java_cmd_windows}"/> | ||
</h3> | ||
<pre> | ||
${copy_agent_jar_windows} | ||
${copy_java_cmd_windows} | ||
</pre> | ||
|
||
</j:when> | ||
<j:otherwise> | ||
<j:set var="copy_java_cmd_secret_unix" value="java -jar agent.jar -url ${jenkinsURL} -secret ${it.jnlpMac} ${it.launcher.getRemotingOptionsUnix(it)}${it.launcher.getWorkDirOptions(it)}" /> | ||
<j:set var="copy_java_cmd_secret_windows" value="java -jar agent.jar -url ${jenkinsURL} -secret ${it.jnlpMac} ${it.launcher.getRemotingOptionsWindows(it)}${it.launcher.getWorkDirOptions(it)}" /> | ||
<h3> | ||
|
@@ -104,8 +82,11 @@ ${copy_secret_to_file} | |
${copy_agent_jar_windows} | ||
${copy_java_cmd_secret2_windows} | ||
</pre> | ||
</j:otherwise> | ||
</j:choose> | ||
<j:if test="${!it.configured}"> | ||
jglick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<p> | ||
${%commonOptions} | ||
</p> | ||
</j:if> | ||
<p> | ||
${%powerShell.cli.curl} | ||
</p> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,7 @@ slaveAgentPort.disabled=JNLP agent port is disabled and agents cannot connect th | |
slaveAgent.connected=Agent is connected. | ||
slaveAgent.cli.run=Run from agent command line: | ||
slaveAgent.cli.run.secret=Or run from agent command line, with the secret stored in a file: | ||
powerShell.cli.curl=Note: PowerShell users must use curl.exe instead of curl because curl is a default PowerShell cmdlet alias for Invoke-WebRequest. | ||
powerShell.cli.curl=Note: PowerShell users must use curl.exe instead of curl because curl is a default PowerShell cmdlet alias for Invoke-WebRequest. | ||
commonOptions=\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt |
||
The most commonly used option is <code>-webSocket</code>. \ | ||
Run <code>java -jar agent.jar -help</code> for more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would only affect
-jnlpUrl
mode