diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index fe69bac0af93..507752378996 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -196,7 +196,7 @@ protected Slave(@NonNull String name, String nodeDescription, String remoteFS, i this.numExecutors = numExecutors; this.mode = mode; this.remoteFS = Util.fixNull(remoteFS).trim(); - this.labelAtomSet = Collections.unmodifiableSet(Label.parse(labelString)); + _setLabelString(labelString); this.launcher = launcher; this.retentionStrategy = retentionStrategy; getAssignedLabels(); // compute labels now diff --git a/core/src/main/java/jenkins/agents/CloudSet.java b/core/src/main/java/jenkins/agents/CloudSet.java index 5229dd06f18b..00a27b04693d 100644 --- a/core/src/main/java/jenkins/agents/CloudSet.java +++ b/core/src/main/java/jenkins/agents/CloudSet.java @@ -39,6 +39,11 @@ import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletException; @@ -248,6 +253,25 @@ public synchronized void doDoCreate(StaplerRequest req, StaplerResponse rsp, rsp.sendRedirect2("."); } + @POST + public void doReorder(StaplerRequest req, StaplerResponse rsp) throws IOException { + Jenkins.get().checkPermission(Jenkins.ADMINISTER); + var names = req.getParameterValues("name"); + if (names == null) { + throw new Failure("No cloud names given"); + } + var namesList = Arrays.asList(names); + var clouds = new ArrayList<>(Jenkins.get().clouds); + Collections.sort(clouds, Comparator.comparingInt(c -> getIndexOf(namesList, c))); + Jenkins.get().clouds.replaceBy(clouds); + rsp.sendRedirect2("."); + } + + private static int getIndexOf(List namesList, Cloud cloud) { + var i = namesList.indexOf(cloud.name); + return i == -1 ? Integer.MAX_VALUE : i; + } + @Extension public static class DescriptorImpl extends Descriptor implements StaplerProxy { diff --git a/core/src/main/java/jenkins/telemetry/impl/Uptime.java b/core/src/main/java/jenkins/telemetry/impl/Uptime.java new file mode 100644 index 000000000000..f5ddfc294ec0 --- /dev/null +++ b/core/src/main/java/jenkins/telemetry/impl/Uptime.java @@ -0,0 +1,65 @@ +/* + * The MIT License + * + * Copyright (c) 2023, CloudBees, Inc. + * + * 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. + */ + +package jenkins.telemetry.impl; + +import edu.umd.cs.findbugs.annotations.NonNull; +import hudson.Extension; +import java.time.LocalDate; +import jenkins.telemetry.Telemetry; +import net.sf.json.JSONObject; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; + +/** + * Records approximations of when Jenkins was started and the current time, to allow for computation of uptime. + */ +@Extension +@Restricted(NoExternalUse.class) +public class Uptime extends Telemetry { + private static final long START = System.nanoTime(); + + @NonNull + @Override + public String getDisplayName() { + return "Uptime"; + } + + @NonNull + @Override + public LocalDate getStart() { + return LocalDate.of(2023, 10, 20); + } + + @NonNull + @Override + public LocalDate getEnd() { + return LocalDate.of(2024, 1, 20); + } + + @Override + public JSONObject createContent() { + return new JSONObject().element("start", START).element("now", System.nanoTime()).element("components", buildComponentInformation()); + } +} diff --git a/core/src/main/resources/hudson/model/BooleanParameterValue/value.jelly b/core/src/main/resources/hudson/model/BooleanParameterValue/value.jelly index 29d5a71ed3c6..ba45b2262ce7 100644 --- a/core/src/main/resources/hudson/model/BooleanParameterValue/value.jelly +++ b/core/src/main/resources/hudson/model/BooleanParameterValue/value.jelly @@ -27,7 +27,7 @@ THE SOFTWARE. xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project"> - - + + diff --git a/core/src/main/resources/jenkins/agents/CloudSet/index.jelly b/core/src/main/resources/jenkins/agents/CloudSet/index.jelly index 3062c25ad01d..4c14e73c21f6 100644 --- a/core/src/main/resources/jenkins/agents/CloudSet/index.jelly +++ b/core/src/main/resources/jenkins/agents/CloudSet/index.jelly @@ -26,8 +26,14 @@ THE SOFTWARE. Entrance to the configuration page --> - + + + +