Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
766475a
basic support for limiting concurrent job runs by parameters
joemiller Feb 25, 2013
931f183
Merge pull request #1 from pantheon-systems/limit_concurrency_by_job_…
joemiller Feb 25, 2013
75a1598
allow limiting job concurrency against a list of parameters
joemiller Feb 26, 2013
07d2291
added some quick commands to help other devs work on the plugin
joemiller Feb 26, 2013
65bc248
Merge pull request #2 from pantheon-systems/selectable_parameters
joemiller Feb 26, 2013
05b8ed7
fix bug with jenkins >1.510 causing stackoverflow. bump version
joemiller Jun 19, 2013
0be7eff
fix bug where parameter-based job concurrency stops working after jen…
joemiller Aug 20, 2013
d8d2017
Successful build against 1.509.4
Hornswoggles Feb 20, 2014
8319b20
merging in 1.8.1 upstream changes
Hornswoggles Feb 20, 2014
f4c0ce2
Fixing NPE
Hornswoggles Feb 20, 2014
ed78fdb
Merge pull request #3 from pantheon-systems/upstream
Hornswoggles Feb 21, 2014
805556e
updating tests so they pass
Hornswoggles Feb 21, 2014
a01b866
Merge branch 'upstream'
Hornswoggles Feb 21, 2014
801200e
fix npes
Feb 24, 2014
77ad29d
helper function
Feb 24, 2014
3421a91
Merge pull request #4 from pantheon-systems/fix_npe_again
kibra Feb 24, 2014
7520a2c
replace deprecated method
Mar 19, 2014
12b7aac
fix test by changing select options to upper case
Mar 19, 2014
1a32b7d
add .idea directory to .gitignore
Mar 19, 2014
cc0da5a
fix comment typo
zihaoyu Mar 20, 2014
5284d6d
Merge pull request #5 from zihaoyu/develop
Hornswoggles Mar 20, 2014
ecd0165
Merge remote-tracking branch 'upupstream/master'
jmozmoz Oct 24, 2015
d200a57
Implement (most) review requests in
jmozmoz Oct 24, 2015
599453b
Store parameters to compare in a transient list build on save/load
jmozmoz Jan 8, 2016
e96ca2b
Changes requested by reviewer:
jmozmoz Jan 10, 2016
f8869a8
Merge remote-tracking branch 'upupstream/master'
jmozmoz Jan 10, 2016
5d71753
Removed obsolet logging.
jmozmoz Jan 10, 2016
c5b5090
Remove compilation error. FIXME: paramsToUseForLimit not loaded into
jmozmoz Jan 10, 2016
af34349
Remove obsolete code. Add getter for paramsToUseForLimit
jmozmoz Jan 10, 2016
0e6c0f1
Remove obsolete debugging output.
jmozmoz Jan 10, 2016
857f6de
Manual merge with upstream master
jmozmoz Jan 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Work in progress on a plugin to dynamically allocate labels in order
to allow for throttling the number of concurrent builds of a project
allowed to run on a given node at one time.

Contributing
------------

### Run / Debug cycle:

Execute `mvn hpi:run`. This will compile the plugin and launch a Jenkins instance on http://localhost:8080

### Create Package (.hpi):

Execute `mvn hpi:hpi`. This will create `throttle-concurrent.hpi` in the `target/` directory

For other mvn targets, see: https://jenkins-ci.org/maven-hpi-plugin/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.424</version>
<version>1.509.4</version>
</parent>

<artifactId>throttle-concurrents</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -36,27 +37,33 @@
public class ThrottleJobProperty extends JobProperty<Job<?,?>> {
// Moving category to categories, to support, well, multiple categories per job.
@Deprecated transient String category;

private Integer maxConcurrentPerNode;
private Integer maxConcurrentTotal;
private List<String> categories;
private boolean throttleEnabled;
private String throttleOption;
private boolean limitOneJobWithMatchingParams;
private transient boolean throttleConfiguration;
private @CheckForNull ThrottleMatrixProjectOptions matrixOptions;

private String paramsToUseForLimit;
private transient List<String> paramsToCompare;

/**
* Store a config version so we're able to migrate config on various
* functionality upgrades.
*/
private Long configVersion;

@DataBoundConstructor
public ThrottleJobProperty(Integer maxConcurrentPerNode,
Integer maxConcurrentTotal,
List<String> categories,
boolean throttleEnabled,
String throttleOption,
boolean limitOneJobWithMatchingParams,
String paramsToUseForLimit,
@CheckForNull ThrottleMatrixProjectOptions matrixOptions
) {
this.maxConcurrentPerNode = maxConcurrentPerNode == null ? 0 : maxConcurrentPerNode;
Expand All @@ -66,9 +73,22 @@ public ThrottleJobProperty(Integer maxConcurrentPerNode,
new CopyOnWriteArrayList<String>(categories);
this.throttleEnabled = throttleEnabled;
this.throttleOption = throttleOption;
this.limitOneJobWithMatchingParams = limitOneJobWithMatchingParams;
this.matrixOptions = matrixOptions;
}
this.paramsToUseForLimit = paramsToUseForLimit;
if ((this.paramsToUseForLimit != null)) {
if ((this.paramsToUseForLimit.length() > 0)) {
this.paramsToCompare = Arrays.asList(this.paramsToUseForLimit.split(","));
}
else {
this.paramsToCompare = new ArrayList<String>();
}
}
else {
this.paramsToCompare = new ArrayList<String>();
}

}

/**
* Migrates deprecated/obsolete data
Expand All @@ -95,6 +115,7 @@ public Object readResolve() {
maxConcurrentTotal = 0;
}
}

configVersion = 1L;

// Handle the throttleConfiguration in custom builds (not released)
Expand Down Expand Up @@ -126,28 +147,36 @@ public boolean getThrottleEnabled() {
return throttleEnabled;
}

public boolean isLimitOneJobWithMatchingParams() {
return limitOneJobWithMatchingParams;
}

public String getThrottleOption() {
return throttleOption;
}

public List<String> getCategories() {
return categories;
}

public Integer getMaxConcurrentPerNode() {
if (maxConcurrentPerNode == null)
maxConcurrentPerNode = 0;

return maxConcurrentPerNode;
}

public Integer getMaxConcurrentTotal() {
if (maxConcurrentTotal == null)
maxConcurrentTotal = 0;

return maxConcurrentTotal;
}

public String getParamsToUseForLimit() {
return paramsToUseForLimit;
}

@CheckForNull
public ThrottleMatrixProjectOptions getMatrixOptions() {
return matrixOptions;
Expand All @@ -171,6 +200,23 @@ public boolean isThrottleMatrixConfigurations() {
: ThrottleMatrixProjectOptions.DEFAULT.isThrottleMatrixConfigurations();
}

public List<String> getParamsToCompare() {
if (paramsToCompare == null) {
if ((paramsToUseForLimit != null)) {
if ((paramsToUseForLimit.length() > 0)) {
paramsToCompare = Arrays.asList(paramsToUseForLimit.split(","));
}
else {
paramsToCompare = new ArrayList<String>();
}
}
else {
paramsToCompare = new ArrayList<String>();
}
}
return paramsToCompare;
}

static List<Queue.Task> getCategoryTasks(String category) {
assert category != null && !category.equals("");
List<Queue.Task> categoryTasks = new ArrayList<Queue.Task>();
Expand Down Expand Up @@ -198,18 +244,19 @@ static List<Queue.Task> getCategoryTasks(String category) {
}
return categoryTasks;
}

private static Item getItem(ItemGroup group, String name) {
if (group instanceof Jenkins) {
return ((Jenkins) group).getItemMap().get(name);
} else {
return group.getItem(name);
}
}

@Extension
public static final class DescriptorImpl extends JobPropertyDescriptor {
private List<ThrottleCategory> categories;

/** Map from category names, to properties including that category. */
private transient Map<String,Map<ThrottleJobProperty,Void>> propertiesByCategory
= new HashMap<String,Map<ThrottleJobProperty,Void>>();
Expand All @@ -235,7 +282,7 @@ public DescriptorImpl() {
public String getDisplayName() {
return "Throttle Concurrent Builds";
}

@Override
@SuppressWarnings("rawtypes")
public boolean isApplicable(Class<? extends Job> jobType) {
Expand Down Expand Up @@ -279,10 +326,9 @@ public FormValidation doCheckMaxConcurrentTotal(@QueryParameter String value) {
return checkNullOrInt(value);
}


public ThrottleCategory getCategoryByName(String categoryName) {
ThrottleCategory category = null;

for (ThrottleCategory tc : categories) {
if (tc.getCategoryName().equals(categoryName)) {
category = tc;
Expand All @@ -295,7 +341,7 @@ public ThrottleCategory getCategoryByName(String categoryName) {
public void setCategories(List<ThrottleCategory> categories) {
this.categories = new CopyOnWriteArrayList<ThrottleCategory>(categories);
}

public List<ThrottleCategory> getCategories() {
if (categories == null) {
categories = new CopyOnWriteArrayList<ThrottleCategory>();
Expand All @@ -308,14 +354,14 @@ public ListBoxModel doFillCategoryItems() {
ListBoxModel m = new ListBoxModel();

m.add("(none)", "");

for (ThrottleCategory tc : getCategories()) {
m.add(tc.getCategoryName());
}

return m;
}

}

public static final class ThrottleCategory extends AbstractDescribableImpl<ThrottleCategory> {
Expand All @@ -335,18 +381,18 @@ public ThrottleCategory(String categoryName,
this.nodeLabeledPairs =
nodeLabeledPairs == null ? new ArrayList<NodeLabeledPair>() : nodeLabeledPairs;
}

public Integer getMaxConcurrentPerNode() {
if (maxConcurrentPerNode == null)
maxConcurrentPerNode = 0;

return maxConcurrentPerNode;
}

public Integer getMaxConcurrentTotal() {
if (maxConcurrentTotal == null)
maxConcurrentTotal = 0;

return maxConcurrentTotal;
}

Expand All @@ -360,7 +406,7 @@ public List<NodeLabeledPair> getNodeLabeledPairs() {

return nodeLabeledPairs;
}

@Extension
public static class DescriptorImpl extends Descriptor<ThrottleCategory> {
@Override
Expand Down
Loading