Skip to content

Commit

Permalink
[JENKINS-63971] prepare for casc support of node monitors (#189)
Browse files Browse the repository at this point in the history
* [JENKINS-63971] prepare for casc support for node monitors

to support node monitors in casc, is is essential that they have
DataBoundConstructors defined and a proper symbol is used.

* apply formatting

* remove newInstance from descriptor

* Remove unused imports

---------

Co-authored-by: Mark Waite <[email protected]>
  • Loading branch information
mawinter69 and MarkEWaite authored Dec 1, 2023
1 parent bdb52e3 commit db638ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.security.MasterToSlaveCallable;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class JVMVersionMonitor extends NodeMonitor {
Expand Down Expand Up @@ -110,6 +111,7 @@ public JVMVersionComparator.ComparisonMode getComparisonMode() {
}

@Extension
@Symbol("jvmVersion")
public static class JvmVersionDescriptor extends AbstractAsyncNodeMonitorDescriptor<String> {

@Override
Expand Down
28 changes: 19 additions & 9 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 @@ -34,13 +35,16 @@
import java.io.IOException;
import java.util.logging.Logger;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class VersionMonitor extends NodeMonitor {

private static final String masterVersion = Launcher.VERSION;

@DataBoundConstructor
public VersionMonitor() {}

@SuppressWarnings("unused") // jelly
public String toHtml(String version) {
if (version == null) {
Expand All @@ -52,8 +56,19 @@ public String toHtml(String version) {
return version;
}

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

@Extension
public static final AbstractNodeMonitorDescriptor<String> DESCRIPTOR = new AbstractNodeMonitorDescriptor<>() {
@Symbol("remotingVersion")
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 {
String version = c.getChannel().call(new SlaveVersion());
Expand All @@ -70,12 +85,7 @@ protected String monitor(Computer c) throws IOException, InterruptedException {
public String getDisplayName() {
return Messages.VersionMonitor_DisplayName();
}

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

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

Expand Down

0 comments on commit db638ec

Please sign in to comment.