Skip to content

Commit fe65200

Browse files
authored
Merge branch 'master' into feature/JENKINS-75675
2 parents 344fffd + 7738998 commit fe65200

23 files changed

+189
-291
lines changed

core/src/main/java/hudson/diagnosis/ReverseProxySetupMonitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public boolean isActivated() {
6666
return true;
6767
}
6868

69+
@Override
70+
public boolean isActivationFake() {
71+
return true;
72+
}
73+
6974
@Restricted(DoNotUse.class) // WebOnly
7075
@RestrictedSince("2.235")
7176
public HttpResponse doTest(StaplerRequest2 request, @QueryParameter boolean testWithContext) {

core/src/main/java/hudson/model/AdministrativeMonitor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public boolean isEnabled() {
160160
*/
161161
public abstract boolean isActivated();
162162

163+
@Restricted(NoExternalUse.class)
164+
public boolean isActivationFake() {
165+
return false;
166+
}
167+
163168
/**
164169
* Returns true if this monitor is security related.
165170
*
@@ -186,8 +191,7 @@ public void doDisable(StaplerRequest2 req, StaplerResponse2 rsp) throws IOExcept
186191
* By default {@link Jenkins#ADMINISTER}, but {@link Jenkins#SYSTEM_READ} or {@link Jenkins#MANAGE} are also supported.
187192
* <p>
188193
* Changing this permission check to return {@link Jenkins#SYSTEM_READ} will make the active
189-
* administrative monitor appear on {@code manage.jelly} and on the globally visible
190-
* {@link jenkins.management.AdministrativeMonitorsDecorator} to users without Administer permission.
194+
* administrative monitor appear on {@link ManageJenkinsAction} to users without Administer permission.
191195
* {@link #doDisable(StaplerRequest2, StaplerResponse2)} will still always require Administer permission.
192196
* </p>
193197
* <p>

core/src/main/java/hudson/model/Computer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,19 @@ public final boolean isOnline() {
625625
return !isOffline();
626626
}
627627

628+
/**
629+
* {@inheritDoc}
630+
* <p>
631+
* Uses {@link #getChannel()} to check the connection.
632+
* A connected agent may still be offline for scheduling if marked temporarily offline.
633+
* @return {@code true} if the agent is connected, {@code false} otherwise.
634+
* @see #isOffline()
635+
*/
636+
@Override
637+
public boolean isConnected() {
638+
return getChannel() != null;
639+
}
640+
628641
/**
629642
* This method is called to determine whether manual launching of the agent is allowed at this point in time.
630643
* @return {@code true} if manual launching of the agent is allowed at this point in time.

core/src/main/java/hudson/model/ManageJenkinsAction.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
import hudson.Extension;
2828
import hudson.Util;
29+
import hudson.util.HudsonIsLoading;
30+
import hudson.util.HudsonIsRestarting;
2931
import java.io.IOException;
30-
import java.util.Collection;
31-
import java.util.Collections;
32-
import java.util.Optional;
33-
import jenkins.management.AdministrativeMonitorsDecorator;
32+
import java.util.logging.Level;
33+
import java.util.logging.Logger;
3434
import jenkins.management.Badge;
3535
import jenkins.model.Jenkins;
3636
import jenkins.model.ModelObjectWithContextMenu;
@@ -50,6 +50,9 @@
5050
*/
5151
@Extension(ordinal = 998) @Symbol("manageJenkins")
5252
public class ManageJenkinsAction implements RootAction, StaplerFallback, ModelObjectWithContextMenu {
53+
54+
private static final Logger LOGGER = Logger.getLogger(ManageJenkinsAction.class.getName());
55+
5356
@Override
5457
public String getIconFileName() {
5558
if (Jenkins.get().hasAnyPermission(Jenkins.MANAGE, Jenkins.SYSTEM_READ))
@@ -98,28 +101,36 @@ public void addContextMenuItem(ContextMenu menu, String url, String icon, String
98101
menu.add("manage/" + url, icon, iconXml, text, post, requiresConfirmation, badge, message);
99102
}
100103

104+
/** Unlike {@link Jenkins#getActiveAdministrativeMonitors} this checks for activation lazily. */
101105
@Override
102106
public Badge getBadge() {
103-
Jenkins jenkins = Jenkins.get();
104-
AdministrativeMonitorsDecorator decorator = jenkins.getExtensionList(PageDecorator.class)
105-
.get(AdministrativeMonitorsDecorator.class);
106-
107-
if (decorator == null) {
107+
if (!(AdministrativeMonitor.hasPermissionToDisplay())) {
108108
return null;
109109
}
110110

111-
Collection<AdministrativeMonitor> activeAdministrativeMonitors = Optional.ofNullable(decorator.getMonitorsToDisplay()).orElse(Collections.emptyList());
112-
boolean anySecurity = activeAdministrativeMonitors.stream().anyMatch(AdministrativeMonitor::isSecurity);
113-
114-
if (activeAdministrativeMonitors.isEmpty()) {
111+
var app = Jenkins.get().getServletContext().getAttribute("app");
112+
if (app instanceof HudsonIsLoading || app instanceof HudsonIsRestarting) {
115113
return null;
116114
}
117115

118-
int size = activeAdministrativeMonitors.size();
119-
String tooltip = size > 1 ? Messages.ManageJenkinsAction_notifications(size) : Messages.ManageJenkinsAction_notification(size);
116+
if (Jenkins.get().administrativeMonitors.stream().anyMatch(m -> m.isSecurity() && isActive(m))) {
117+
return new Badge("1+", Messages.ManageJenkinsAction_notifications(),
118+
Badge.Severity.DANGER);
119+
} else if (Jenkins.get().administrativeMonitors.stream().anyMatch(m -> !m.isSecurity() && isActive(m))) {
120+
return new Badge("1+", Messages.ManageJenkinsAction_notifications(),
121+
Badge.Severity.WARNING);
122+
} else {
123+
return null;
124+
}
125+
}
120126

121-
return new Badge(String.valueOf(size),
122-
tooltip,
123-
anySecurity ? Badge.Severity.DANGER : Badge.Severity.WARNING);
127+
private static boolean isActive(AdministrativeMonitor m) {
128+
try {
129+
return !m.isActivationFake() && m.hasRequiredPermission() && m.isEnabled() && m.isActivated();
130+
} catch (Throwable x) {
131+
LOGGER.log(Level.WARNING, null, x);
132+
return false;
133+
}
124134
}
135+
125136
}

core/src/main/java/jenkins/diagnostics/URICheckEncodingMonitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public boolean isActivated() {
3131
return true;
3232
}
3333

34+
@Override
35+
public boolean isActivationFake() {
36+
return true;
37+
}
38+
3439
@Override
3540
public String getDisplayName() {
3641
return Messages.URICheckEncodingMonitor_DisplayName();

core/src/main/java/jenkins/management/AdministrativeMonitorsApi.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

core/src/main/java/jenkins/management/AdministrativeMonitorsApiData.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

core/src/main/java/jenkins/management/AdministrativeMonitorsDecorator.java

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)