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

Simplified NodeContributor.record on updated #158

Merged
merged 1 commit into from
Mar 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import java.util.stream.Collectors;
import jenkins.model.Jenkins;
import jenkins.model.NodeListener;
import jenkins.model.Nodes;
import jenkins.util.SystemProperties;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -152,6 +151,11 @@ protected void onCreated(@NonNull Node node) {
record(node);
}

@Override
protected void onUpdated(Node oldOne, Node newOne) {
record(newOne);
}

@Override
protected void onDeleted(@NonNull Node node) {
if (!DISABLE) {
Expand Down Expand Up @@ -238,29 +242,13 @@ public static boolean hasAmbiguousEntries(final AuthorizationContainer container
}

@Extension
public static class NodeAndJobSaveableListenerImpl extends SaveableListener {
public static class JobSaveableListenerImpl extends SaveableListener {
@Override
public void onChange(final Saveable o, final XmlFile file) {
if (!AmbiguityMonitor.isGatheringData()) {
return; // The below is a bit much when we're not doing anything in the end, so get out early
}
try {
if (o instanceof Nodes) {
LOGGER.log(Level.FINEST, () -> "Recording update to Saveable " + o + " stored in " + file);

// Cf. Nodes#persistNode, hacky but probably the best we can do
final String nodeName = file.getFile().getParentFile().getName();
// Nodes is @Restricted but the Saveable we inform listeners about, so go through Jenkins#getNode
// instead
final Node node = Jenkins.get().getNode(nodeName);
LOGGER.log(
Level.FINER,
() -> "Determined node name " + nodeName + " from file " + file + " and found node "
+ node);
if (node != null) {
NodeContributor.record(node);
}
}
if (o instanceof Job) {
LOGGER.log(Level.FINEST, () -> "Recording update to Saveable " + o + " stored in " + file);

Expand Down