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-64816] prepare for support of node monitors by JCasC #8629

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
Expand All @@ -40,6 +41,11 @@
* @author Kohsuke Kawaguchi
*/
public class ArchitectureMonitor extends NodeMonitor {

@DataBoundConstructor
public ArchitectureMonitor() {
}

@Extension @Symbol("architecture")
public static final class DescriptorImpl extends AbstractAsyncNodeMonitorDescriptor<String> {
@Override
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/node_monitors/ClockMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
Expand All @@ -46,6 +47,11 @@
* @since 1.123
*/
public class ClockMonitor extends NodeMonitor {

@DataBoundConstructor
public ClockMonitor() {
}

public ClockDifference getDifferenceFor(Computer c) {
return DESCRIPTOR.get(c);
}
Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package hudson.node_monitors;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.FilePath;
import hudson.model.Computer;
Expand All @@ -34,6 +35,7 @@
import java.io.IOException;
import java.text.ParseException;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand Down Expand Up @@ -61,7 +63,17 @@ public String getColumnCaption() {
return Jenkins.get().hasPermission(Jenkins.ADMINISTER) ? super.getColumnCaption() : null;
}

public static final DiskSpaceMonitorDescriptor DESCRIPTOR = new DiskSpaceMonitorDescriptor() {
@SuppressFBWarnings(value = "MS_PKGPROTECT", justification = "for backward compatibility")
public static /*almost final*/ DiskSpaceMonitorDescriptor DESCRIPTOR;

@Extension @Symbol("diskSpace")
public static class DescriptorImpl extends DiskSpaceMonitorDescriptor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure whether we want @since for this. Technically, yes?

Copy link
Contributor Author

@mawinter69 mawinter69 Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see the need for this here.


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

@NonNull
@Override
public String getDisplayName() {
Expand All @@ -78,7 +90,7 @@ protected Callable<DiskSpace, IOException> createCallable(Computer c) {

return p.asCallableWith(new GetUsableSpace());
}
};
}

@Extension
public static DiskSpaceMonitorDescriptor install() {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/hudson/node_monitors/NodeMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
* <p>
* {@link NodeMonitor}s are persisted via XStream.
*
* <h2>CasC</h2>
* To be able to configure {@link NodeMonitor}s via JCasC, they should have a {@link org.kohsuke.stapler.DataBoundConstructor}
*
* @author Kohsuke Kawaguchi
* @since 1.123
*/
Expand Down
21 changes: 19 additions & 2 deletions core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package hudson.node_monitors;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.Computer;
import hudson.remoting.Callable;
Expand All @@ -34,6 +35,8 @@
import java.util.logging.Logger;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
Expand All @@ -44,8 +47,22 @@
* @author Kohsuke Kawaguchi
*/
public class ResponseTimeMonitor extends NodeMonitor {

@DataBoundConstructor
public ResponseTimeMonitor() {
}

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

@Extension
public static final AbstractNodeMonitorDescriptor<Data> DESCRIPTOR = new AbstractAsyncNodeMonitorDescriptor<>() {
@Symbol("responseTime")
public static class DescriptorImpl extends AbstractAsyncNodeMonitorDescriptor<Data> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure whether we want @since for this. Technically, yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito


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

@Override
protected Callable<Data, IOException> createCallable(Computer c) {
Expand Down Expand Up @@ -91,7 +108,7 @@ public String getDisplayName() {
public NodeMonitor newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new ResponseTimeMonitor();
}
};
}

private static final class Step1 extends MasterToSlaveCallable<Data, IOException> {
private Data cur;
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.jenkinsci.Symbol;
import org.jvnet.hudson.MemoryMonitor;
import org.jvnet.hudson.MemoryUsage;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
Expand All @@ -48,6 +49,11 @@
* @since 1.233
*/
public class SwapSpaceMonitor extends NodeMonitor {

@DataBoundConstructor
public SwapSpaceMonitor() {
}

/**
* Returns the HTML representation of the space.
*/
Expand Down