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-72978] Remove executors widget from Dashboard and nodes page #9126

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
4 changes: 4 additions & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -5777,6 +5777,10 @@ public boolean shouldShowStackTrace() {
public static final Permission[] MANAGE_AND_SYSTEM_READ =
new Permission[] { MANAGE, SYSTEM_READ };

@Restricted(NoExternalUse.class) // called by jelly
public static final Permission[] ADMINISTER_MANAGE_SYSTEM_READ =
new Permission[] { ADMINISTER, MANAGE, SYSTEM_READ };

public static final Permission READ = new Permission(PERMISSIONS, "Read", Messages._Hudson_ReadPermission_Description(), Permission.READ, PermissionScope.JENKINS);
/** @deprecated in Jenkins 2.222 use {@link Jenkins#ADMINISTER} instead */
@Deprecated
Expand Down
39 changes: 0 additions & 39 deletions core/src/main/java/jenkins/widgets/ExecutorsWidget.java
Expand Up @@ -3,8 +3,6 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Computer;
import hudson.model.ComputerSet;
import hudson.model.View;
import hudson.widgets.Widget;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -39,24 +37,6 @@ public List<Computer> getComputers() {
return Collections.unmodifiableList(computers);
}

@Extension(ordinal = 100) @Symbol("executors") // historically this was above normal widgets and below BuildQueueWidget
public static final class ViewFactoryImpl extends WidgetFactory<View, ExecutorsWidget> {
@Override
public Class<View> type() {
return View.class;
}

@Override
public Class<ExecutorsWidget> widgetType() {
return ExecutorsWidget.class;
}

@NonNull
@Override
public Collection<ExecutorsWidget> createFor(@NonNull View target) {
return List.of(new ExecutorsWidget(target.getUrl(), target.getComputers()));
}
}

@Extension(ordinal = 100) @Symbol("executorsComputer") // historically this was above normal widgets and below BuildQueueWidget
public static final class ComputerFactoryImpl extends WidgetFactory<Computer, ExecutorsWidget> {
Expand All @@ -76,23 +56,4 @@ public Collection<ExecutorsWidget> createFor(@NonNull Computer target) {
return List.of(new ExecutorsWidget(target.getUrl(), List.of(target)));
}
}

@Extension(ordinal = 100) @Symbol("executorsComputerSet") // historically this was above normal widgets and below BuildQueueWidget
public static final class ComputerSetFactoryImpl extends WidgetFactory<ComputerSet, ExecutorsWidget> {
@Override
public Class<ComputerSet> type() {
return ComputerSet.class;
}

@Override
public Class<ExecutorsWidget> widgetType() {
return ExecutorsWidget.class;
}

@NonNull
@Override
public Collection<ExecutorsWidget> createFor(@NonNull ComputerSet target) {
return List.of(new ExecutorsWidget("computer/", List.of(target.get_all())));
}
}
}
4 changes: 4 additions & 0 deletions core/src/main/resources/hudson/model/ComputerSet/index.jelly
Expand Up @@ -45,6 +45,10 @@ THE SOFTWARE.
${%Configure Monitors}
</a>
</j:if>
<a class="jenkins-button" href="status" tooltip="${%Status}">
<l:icon src="symbol-computer" />
${%Status}
</a>
<l:hasAdministerOrManage>
<form method="post" action="updateNow" class="jenkins-!-display-contents">
<button tooltip="${%Refresh status}" class="jenkins-button">
Expand Down
44 changes: 44 additions & 0 deletions core/src/main/resources/hudson/model/ComputerSet/status.jelly
@@ -0,0 +1,44 @@
<!--
The MIT License

Copyright (c) 2024, Jenkins project contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<!--
Manage monitoring
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:st="jelly:stapler"
>
<l:layout title="${%Status}" type="one-column">
<j:set var="readOnlyMode" value="${!app.hasPermission(app.MANAGE)}"/>
<l:breadcrumb title="${%Status}"/>
<l:main-panel>
<l:app-bar title="${%Status}"/>
<div id="side-panel">
<t:executors ajax="false"/>
<div class="widget-refresh-reference" data-id="executors" data-url="${rootURL}/manage/computer/statusAjax"/>
<st:adjunct includes="lib.hudson.widget-refresh"/>
</div>
</l:main-panel>
</l:layout>
</j:jelly>
33 changes: 33 additions & 0 deletions core/src/main/resources/hudson/model/ComputerSet/statusAjax.jelly
@@ -0,0 +1,33 @@
<!--
The MIT License

Copyright (c) 2024, Jenkins project contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<!--
Used to asynchronously update executor queue
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:t="/lib/hudson">
<l:ajax>
<t:executors ajax="false"/>
</l:ajax>
</j:jelly>
5 changes: 5 additions & 0 deletions core/src/main/resources/hudson/model/View/sidepanel.jelly
Expand Up @@ -56,6 +56,11 @@ THE SOFTWARE.
<l:task href="${rootURL}/fingerprintCheck" icon="icon-fingerprint icon-md" title="${%Check File Fingerprint}"/>
</j:if>

<!-- These users will access from Manage Jenkins -->
<j:if test="${!h.hasAnyPermission(it, app.ADMINISTER_MANAGE_SYSTEM_READ)}">
<l:task href="${rootURL}/computer" icon="symbol-computer" title="${%Nodes}" permission="${it.READ}"/>
timja marked this conversation as resolved.
Show resolved Hide resolved
</j:if>

<!-- subtypes can put more stuff here -->
<st:include page="sidepanel2.jelly" optional="true"/>

Expand Down
24 changes: 0 additions & 24 deletions test/src/test/java/hudson/model/ComputerSetTest.java
Expand Up @@ -38,8 +38,6 @@
import hudson.slaves.OfflineCause;
import java.net.HttpURLConnection;
import jenkins.model.Jenkins;
import jenkins.widgets.ExecutorsWidget;
import jenkins.widgets.HasWidgetHelper;
import org.htmlunit.Page;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlPage;
Expand Down Expand Up @@ -159,26 +157,4 @@ public void testTerminatedNodeStatusPageDoesNotShowTrace() throws Exception {

j.assertBuildStatus(Result.FAILURE, j.waitForCompletion(b));
}

@Test
@Issue("SECURITY-2120")
public void testTerminatedNodeAjaxExecutorsDoesNotShowTrace() throws Exception {
DumbSlave agent = j.createOnlineSlave();
FreeStyleProject p = j.createFreeStyleProject();
p.setAssignedNode(agent);

FreeStyleBuild b = ExecutorTest.startBlockingBuild(p);

String message = "It went away";
b.getBuiltOn().toComputer().disconnect(
new OfflineCause.ChannelTermination(new RuntimeException(message))
);

WebClient wc = j.createWebClient();
Page page = wc.getPage(wc.createCrumbedUrl(HasWidgetHelper.getWidget(j.jenkins.getComputer(), ExecutorsWidget.class).orElseThrow().getUrl() + "ajax"));
String content = page.getWebResponse().getContentAsString();
assertThat(content, not(containsString(message)));

j.assertBuildStatus(Result.FAILURE, j.waitForCompletion(b));
}
}
4 changes: 2 additions & 2 deletions test/src/test/java/jenkins/security/Security2278Test.java
Expand Up @@ -65,7 +65,7 @@ public static void setUp() throws Exception {
@Test
public void testUi() throws Exception {
final JenkinsRule.WebClient webClient = j.createWebClient();
final HtmlPage topPage = webClient.goTo("");
final HtmlPage topPage = webClient.goTo("computer/status");
final String contentAsString = topPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString("Build Executor Status"));
assertThat(contentAsString, containsString("Unknown Task"));
Expand All @@ -76,7 +76,7 @@ public void testUi() throws Exception {
@Test
public void testUiWithPermission() throws Exception {
final JenkinsRule.WebClient webClient = j.createWebClient().login("alice");
final HtmlPage topPage = webClient.goTo("");
final HtmlPage topPage = webClient.goTo("computer/status");
final String contentAsString = topPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString("Build Executor Status"));
assertThat(contentAsString, not(containsString("Unknown Task")));
Expand Down
14 changes: 6 additions & 8 deletions test/src/test/java/lib/layout/AjaxTest.java
Expand Up @@ -24,8 +24,7 @@

package lib.layout;

import jenkins.widgets.ExecutorsWidget;
import jenkins.widgets.HasWidgetHelper;
import hudson.model.FreeStyleProject;
import org.htmlunit.html.DomElement;
import org.htmlunit.html.HtmlLink;
import org.htmlunit.html.HtmlPage;
Expand Down Expand Up @@ -61,8 +60,10 @@ public class AjaxTest {
@Test
@Issue("JENKINS-65288")
public void ajaxPageRenderingPossibleWithoutJellyTrace() throws Exception {
FreeStyleProject p = r.createProject(FreeStyleProject.class, "foo");

JenkinsRule.WebClient wc = r.createWebClient();
HtmlPage htmlPage = wc.goTo(getExecutorsWidgetAjaxViewUrl());
HtmlPage htmlPage = wc.goTo(p.getUrl() + "buildHistory/ajax");
r.assertGoodStatus(htmlPage);
}

Expand All @@ -72,19 +73,16 @@ public void ajaxPageRenderingPossibleWithoutJellyTrace() throws Exception {
@Test
@Issue("JENKINS-65288")
public void ajaxPageRenderingPossibleWithJellyTrace() throws Exception {
FreeStyleProject p = r.createProject(FreeStyleProject.class, "foo");
boolean currentValue = JellyFacet.TRACE;
try {
JellyFacet.TRACE = true;

JenkinsRule.WebClient wc = r.createWebClient();
HtmlPage htmlPage = wc.goTo(getExecutorsWidgetAjaxViewUrl());
HtmlPage htmlPage = wc.goTo(p.getUrl() + "buildHistory/ajax");
r.assertGoodStatus(htmlPage);
} finally {
JellyFacet.TRACE = currentValue;
}
}

private String getExecutorsWidgetAjaxViewUrl() {
return HasWidgetHelper.getWidget(r.jenkins.getPrimaryView(), ExecutorsWidget.class).orElseThrow().getUrl() + "ajax";
}
}