Skip to content

Commit

Permalink
[JENKINS-13619] - Added configuration options for Matrix project's th…
Browse files Browse the repository at this point in the history
…rottling

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed Mar 8, 2014
1 parent c453516 commit c8280ad
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 4 deletions.
Expand Up @@ -12,6 +12,7 @@
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.Util;
import hudson.matrix.MatrixProject;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -37,6 +38,7 @@ public class ThrottleJobProperty extends JobProperty<AbstractProject<?,?>> {
private List<String> categories;
private boolean throttleEnabled;
private String throttleOption;
private final ThrottleMatrixProjectOptions matrixOptions;

/**
* Store a config version so we're able to migrate config on various
Expand All @@ -49,12 +51,15 @@ public ThrottleJobProperty(Integer maxConcurrentPerNode,
Integer maxConcurrentTotal,
List<String> categories,
boolean throttleEnabled,
String throttleOption) {
String throttleOption,
ThrottleMatrixProjectOptions matrixOptions
) {
this.maxConcurrentPerNode = maxConcurrentPerNode == null ? 0 : maxConcurrentPerNode;
this.maxConcurrentTotal = maxConcurrentTotal == null ? 0 : maxConcurrentTotal;
this.categories = categories;
this.throttleEnabled = throttleEnabled;
this.throttleOption = throttleOption;
this.matrixOptions = matrixOptions;
}


Expand Down Expand Up @@ -131,6 +136,10 @@ public Integer getMaxConcurrentTotal() {
return maxConcurrentTotal;
}

public ThrottleMatrixProjectOptions getMatrixOptions() {
return matrixOptions;
}

static List<AbstractProject<?,?>> getCategoryProjects(String category) {
assert category != null && !category.equals("");
List<AbstractProject<?,?>> categoryProjects = new ArrayList<AbstractProject<?, ?>>();
Expand Down Expand Up @@ -169,7 +178,7 @@ public static final class DescriptorImpl extends JobPropertyDescriptor {
= new HashMap<String,Map<ThrottleJobProperty,Void>>();
/** A sync object for {@link #propertiesByCategory} */
private final transient Object propertiesByCategoryLock = new Object();

public DescriptorImpl() {
super(ThrottleJobProperty.class);
synchronized(propertiesByCategoryLock) {
Expand All @@ -195,6 +204,10 @@ public String getDisplayName() {
public boolean isApplicable(Class<? extends Job> jobType) {
return AbstractProject.class.isAssignableFrom(jobType);
}

public boolean isMatrixProject(Job job) {
return job instanceof MatrixProject;
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
Expand Down Expand Up @@ -310,7 +323,7 @@ public List<NodeLabeledPair> getNodeLabeledPairs() {

return nodeLabeledPairs;
}

@Extension
public static class DescriptorImpl extends Descriptor<ThrottleCategory> {
@Override
Expand Down
@@ -0,0 +1,82 @@
/*
* The MIT License
*
* Copyright 2014 Oleg Nenashev, Synopsys 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 hudson.plugins.throttleconcurrents;

import hudson.Extension;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixConfiguration;
import hudson.model.Describable;
import hudson.model.Descriptor;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Defines additional options for throttling of {@link MatrixBuild}s and
* @{@link MatrixConfiguration}s.
* This class is intended to be used inside {@link ThrottleJobProperty}.
* @author Oleg Nenashev <o.v.nenashev@gmail.com>
* @since TODO: 1.9.0?
*/
public class ThrottleMatrixProjectOptions implements Describable<ThrottleMatrixProjectOptions> {

private final boolean throttleMatrixBuilds;
private final boolean throttleMatrixConfigurations;

/**
* A default configuration, which retains the behavior from
* version 1.8.
*/
public static final ThrottleMatrixProjectOptions DEFAULT =
new ThrottleMatrixProjectOptions(true, false);

@DataBoundConstructor
public ThrottleMatrixProjectOptions(boolean throttleMatrixBuilds, boolean throttleMatrixConfigurations) {
this.throttleMatrixBuilds = throttleMatrixBuilds;
this.throttleMatrixConfigurations = throttleMatrixConfigurations;
}

public boolean isThrottleMatrixBuilds() {
return throttleMatrixBuilds;
}

public boolean isThrottleMatrixConfigurations() {
return throttleMatrixConfigurations;
}

@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

@Override
public Descriptor<ThrottleMatrixProjectOptions> getDescriptor() {
return DESCRIPTOR;
}

public static class DescriptorImpl extends Descriptor<ThrottleMatrixProjectOptions> {

@Override
public String getDisplayName() {
return Messages.ThrottleMatrixProjectOptions_DisplayName();
}
}
}
@@ -1,3 +1,5 @@
ThrottleQueueTaskDispatcher.MaxCapacityOnNode=Already running {0} builds on node
ThrottleQueueTaskDispatcher.MaxCapacityTotal=Already running {0} builds across all nodes
ThrottleQueueTaskDispatcher.BuildPending=A build is pending launch
ThrottleQueueTaskDispatcher.BuildPending=A build is pending launch

ThrottleMatrixProjectOptions.DisplayName=Additional options for Matrix projects
Expand Up @@ -29,6 +29,12 @@
</j:forEach>
</f:entry>
</j:if>
<!--Specific options for Matrix projects-->
<j:if test="${descriptor.isMatrixProject(it)}">
<f:entry>
<f:property field="matrixOptions"/>
</f:entry>
</j:if>
</f:optionalBlock>
</j:jelly>

Expand Down
@@ -0,0 +1,8 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:p="/lib/hudson/project">
<f:entry field="throttleMatrixBuilds" title="${%throttleMatrixBuilds.title}">
<f:checkbox/>
</f:entry>
<f:entry field="throttleMatrixConfigurations" title="${%throttleMatrixConfigurations.title}">
<f:checkbox/>
</f:entry>
</j:jelly>
@@ -0,0 +1,2 @@
throttleMatrixBuilds.title= Throttle Matrix master builds
throttleMatrixConfigurations.title= Throttle Matrix configuration builds

1 comment on commit c8280ad

@oleg-nenashev
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologizes...
I've synchronized changes to the improper repo...

Please sign in to comment.