Skip to content
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

JENKINS-63607 Do not disconnect agent when remoting doesn't match #192

Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ target
.classpath
.settings
.project
.vscode
*.iml
*.ipr
*.iws
Expand Down
70 changes: 60 additions & 10 deletions src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package hudson.plugin.versioncolumn;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.Util;
import hudson.model.Computer;
Expand All @@ -41,41 +42,90 @@

private static final String masterVersion = Launcher.VERSION;

private Boolean disconnect = true;

public VersionMonitor() {}

public VersionMonitor(Boolean disconnect) {
this.disconnect = disconnect;
}

protected Object readResolve() {

// Ensure backward compatibility which disconnect the agent by default
if (disconnect == null) {
disconnect = true;
}
return this;
}

@SuppressWarnings("unused") // jelly
public String toHtml(String version) {
if (version == null) {
return "N/A";
}
if (!version.equals(masterVersion)) {
return Util.wrapToErrorSpan(version);
}
return version;
}

@Extension
public static final AbstractNodeMonitorDescriptor<String> DESCRIPTOR = new AbstractNodeMonitorDescriptor<>() {
@SuppressWarnings("unused") // jelly
public boolean isDisconnect() {
return disconnect;

Check warning on line 75 in src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 49-75 are not covered by tests
}

protected String monitor(Computer c) throws IOException, InterruptedException {
String version = c.getChannel().call(new SlaveVersion());
if (version == null || !version.equals(masterVersion)) {
if (!isIgnored()) {
markOffline(c, OfflineCause.create(Messages._VersionMonitor_OfflineCause()));
@Override
public Object data(Computer c) {
String remotingVersion = (String) super.data(c);
if (remotingVersion != null && remotingVersion != "N/A" && !remotingVersion.equals(masterVersion)) {

Check warning on line 81 in src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 81 is only partially covered, 5 branches are missing
if (!isIgnored()) {
if (disconnect) {
((DescriptorImpl) getDescriptor())
.markOffline(c, OfflineCause.create(Messages._VersionMonitor_OfflineCause()));
LOGGER.warning(Messages.VersionMonitor_MarkedOffline(c.getName()));
} else {
LOGGER.finer("Remoting incompatibility detected, but keeping the agent '"
+ c.getName()

Check warning on line 89 in src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 82-89 are not covered by tests
+ "' online per the node monitor configuration");
}
}
return version;
}
return remotingVersion;
}

@SuppressFBWarnings(value = "MS_PKGPROTECT", justification = "for backward compatibility")
public static /*almost final*/ AbstractNodeMonitorDescriptor<String> DESCRIPTOR;

@Extension
public static class DescriptorImpl extends AbstractNodeMonitorDescriptor<String> {

@SuppressFBWarnings(
value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
justification = "for backward compatibility")
public DescriptorImpl() {
DESCRIPTOR = this;
}

protected String monitor(Computer c) throws IOException, InterruptedException {
return c.getChannel().call(new SlaveVersion());
}

@Override // Just augmenting visibility
public boolean markOffline(Computer c, OfflineCause oc) {
return super.markOffline(c, oc);
}

@NonNull
public String getDisplayName() {
return Messages.VersionMonitor_DisplayName();
}

@Override
public NodeMonitor newInstance(StaplerRequest req, @NonNull JSONObject formData) throws FormException {
return new VersionMonitor();
return new VersionMonitor(formData.getBoolean("disconnect"));

Check warning on line 126 in src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 116-126 are not covered by tests
}
};
}

private static final class SlaveVersion extends MasterToSlaveCallable<String, IOException> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry title="${%DisconnectAgent}" field="disconnect">
<f:checkbox />
</f:entry>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisconnectAgent=Disconnect agent when remoting mismatch is found
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<p>Check this checkbox if you want to disconnect agents if they have a mismatch remoting version.

<p>The default behaviour is to disconnect such agents.</p>

</div>