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-72159] deactivate MarkedOffline monitor when agents are online #8618

Merged
merged 2 commits into from Nov 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions core/src/main/java/hudson/node_monitors/NodeMonitorUpdater.java
@@ -1,6 +1,7 @@
package hudson.node_monitors;

import hudson.Extension;
import hudson.model.AdministrativeMonitor;
import hudson.model.Computer;
import hudson.model.ComputerSet;
import hudson.model.TaskListener;
Expand All @@ -9,6 +10,7 @@
import java.io.IOException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jenkins.model.Jenkins;
import jenkins.util.Timer;

/**
Expand All @@ -28,6 +30,23 @@ public void run() {
}
};

private static final Runnable MARKEDOFFLINE_UPDATER = new Runnable() {
@Override
public void run() {
MonitorMarkedNodeOffline no = AdministrativeMonitor.all().get(MonitorMarkedNodeOffline.class);
if (no != null) {
boolean markedOffline = false;
for (Computer c : Jenkins.get().getComputers()) {
if (c.getChannel() != null && c.getOfflineCause() instanceof MonitorOfflineCause) {
markedOffline = true;
break;
}
}
no.active = markedOffline;
}
}
};

private Future<?> future = Futures.precomputed(null);

/**
Expand All @@ -41,4 +60,12 @@ public void onOnline(Computer c, TaskListener listener) throws IOException, Inte
future = Timer.get().schedule(MONITOR_UPDATER, 5, TimeUnit.SECONDS);
}
}

@Override
public void onTemporarilyOnline(Computer c) {
synchronized (this) {
future.cancel(false);
future = Timer.get().schedule(MARKEDOFFLINE_UPDATER, 5, TimeUnit.SECONDS);
}
}
}