Skip to content

Commit d200a57

Browse files
committed
Implement (most) review requests in
jenkinsci#9
1 parent ecd0165 commit d200a57

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

src/main/java/hudson/plugins/throttleconcurrents/ThrottleJobProperty.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class ThrottleJobProperty extends JobProperty<AbstractProject<?,?>> {
3232
// Moving category to categories, to support, well, multiple categories per job.
3333
@Deprecated transient String category;
34-
34+
3535
private Integer maxConcurrentPerNode;
3636
private Integer maxConcurrentTotal;
3737
private List<String> categories;
@@ -47,7 +47,7 @@ public class ThrottleJobProperty extends JobProperty<AbstractProject<?,?>> {
4747
* functionality upgrades.
4848
*/
4949
private Long configVersion;
50-
50+
5151
@DataBoundConstructor
5252
public ThrottleJobProperty(Integer maxConcurrentPerNode,
5353
Integer maxConcurrentTotal,
@@ -96,7 +96,7 @@ public Object readResolve() {
9696
}
9797

9898
configVersion = 1L;
99-
99+
100100
return this;
101101
}
102102

@@ -121,33 +121,34 @@ public boolean getThrottleEnabled() {
121121
return throttleEnabled;
122122
}
123123

124-
public boolean getlimitOneJobWithMatchingParams() {
124+
public boolean isLimitOneJobWithMatchingParams() {
125125
return limitOneJobWithMatchingParams;
126126
}
127127

128+
128129
public String getLimitOneJobByParams() {
129130
return limitOneJobByParams;
130131
}
131132

132133
public String getThrottleOption() {
133134
return throttleOption;
134135
}
135-
136+
136137
public List<String> getCategories() {
137138
return categories;
138139
}
139-
140+
140141
public Integer getMaxConcurrentPerNode() {
141142
if (maxConcurrentPerNode == null)
142143
maxConcurrentPerNode = 0;
143-
144+
144145
return maxConcurrentPerNode;
145146
}
146147

147148
public Integer getMaxConcurrentTotal() {
148149
if (maxConcurrentTotal == null)
149150
maxConcurrentTotal = 0;
150-
151+
151152
return maxConcurrentTotal;
152153
}
153154

@@ -179,24 +180,24 @@ private static Item getItem(ItemGroup group, String name) {
179180
return group.getItem(name);
180181
}
181182
}
182-
183+
183184
@Extension
184185
public static final class DescriptorImpl extends JobPropertyDescriptor {
185186
private List<ThrottleCategory> categories;
186-
187+
187188
/** Map from category names, to properties including that category. */
188189
private Map<String,Map<ThrottleJobProperty,Void>> propertiesByCategory = new HashMap<String,Map<ThrottleJobProperty,Void>>();
189-
190+
190191
public DescriptorImpl() {
191192
super(ThrottleJobProperty.class);
192193
load();
193194
}
194-
195+
195196
@Override
196197
public String getDisplayName() {
197198
return "Throttle Concurrent Builds";
198199
}
199-
200+
200201
@Override
201202
@SuppressWarnings("rawtypes")
202203
public boolean isApplicable(Class<? extends Job> jobType) {
@@ -236,10 +237,10 @@ public FormValidation doCheckMaxConcurrentTotal(@QueryParameter String value) {
236237
return checkNullOrInt(value);
237238
}
238239

239-
240+
240241
public ThrottleCategory getCategoryByName(String categoryName) {
241242
ThrottleCategory category = null;
242-
243+
243244
for (ThrottleCategory tc : categories) {
244245
if (tc.getCategoryName().equals(categoryName)) {
245246
category = tc;
@@ -252,7 +253,7 @@ public ThrottleCategory getCategoryByName(String categoryName) {
252253
public void setCategories(List<ThrottleCategory> categories) {
253254
this.categories = categories;
254255
}
255-
256+
256257
public List<ThrottleCategory> getCategories() {
257258
if (categories == null) {
258259
categories = new ArrayList<ThrottleCategory>();
@@ -265,14 +266,14 @@ public ListBoxModel doFillCategoryItems() {
265266
ListBoxModel m = new ListBoxModel();
266267

267268
m.add("(none)", "");
268-
269+
269270
for (ThrottleCategory tc : getCategories()) {
270271
m.add(tc.getCategoryName());
271272
}
272273

273274
return m;
274275
}
275-
276+
276277
}
277278

278279
public static final class ThrottleCategory extends AbstractDescribableImpl<ThrottleCategory> {
@@ -292,18 +293,18 @@ public ThrottleCategory(String categoryName,
292293
this.nodeLabeledPairs =
293294
nodeLabeledPairs == null ? new ArrayList<NodeLabeledPair>() : nodeLabeledPairs;
294295
}
295-
296+
296297
public Integer getMaxConcurrentPerNode() {
297298
if (maxConcurrentPerNode == null)
298299
maxConcurrentPerNode = 0;
299-
300+
300301
return maxConcurrentPerNode;
301302
}
302-
303+
303304
public Integer getMaxConcurrentTotal() {
304305
if (maxConcurrentTotal == null)
305306
maxConcurrentTotal = 0;
306-
307+
307308
return maxConcurrentTotal;
308309
}
309310

src/main/java/hudson/plugins/throttleconcurrents/ThrottleQueueTaskDispatcher.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ else if (tjp.getThrottleOption().equals("category")) {
9494
public CauseOfBlockage canRun(Queue.Item item) {
9595
ThrottleJobProperty tjp = getThrottleJobProperty(item.task);
9696
if (tjp!=null && tjp.getThrottleEnabled()) {
97-
if (tjp.getlimitOneJobWithMatchingParams() && isAnotherBuildWithSameParametersRunningOnAnyNode(item)) {
97+
if (tjp.isLimitOneJobWithMatchingParams() && isAnotherBuildWithSameParametersRunningOnAnyNode(item)) {
9898
LOGGER.info("A build with matching parameters is already running.");
9999
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_OnlyOneWithMatchingParameters());
100100
}
@@ -189,13 +189,13 @@ private boolean isAnotherBuildWithSameParametersRunningOnNode(Node node, Queue.I
189189
if (exec.getCurrentExecutable() != null &&
190190
exec.getCurrentExecutable().getParent() != null &&
191191
exec.getCurrentExecutable().getParent().getOwnerTask() != null &&
192-
exec.getCurrentExecutable().getParent().getOwnerTask().getName().equals(item.task.getName())) {
192+
exec.getCurrentExecutable().getParent().getOwnerTask().getName().equals(item.task.getDisplayName())) {
193193
List<ParameterValue> executingUnitParams = getParametersFromWorkUnit(exec.getCurrentWorkUnit());
194194
executingUnitParams = doFilterParams(paramsToCompare, executingUnitParams);
195195

196196
if (executingUnitParams.containsAll(itemParams)) {
197-
LOGGER.info("build (" + exec.getCurrentWorkUnit() + ") with identical parameters (" +
198-
executingUnitParams + ") is already running.");
197+
LOGGER.debug("build (" + exec.getCurrentWorkUnit() + ") with identical parameters (" +
198+
executingUnitParams + ") is already running.");
199199
return true;
200200
}
201201
}
@@ -240,12 +240,16 @@ public List<ParameterValue> getParametersFromWorkUnit(WorkUnit unit) {
240240
}
241241

242242
public List<ParameterValue> getParametersFromQueueItem(Queue.Item item) {
243-
List<ParameterValue> paramsList = new ArrayList<ParameterValue>();
243+
List<ParameterValue> paramsList;
244244

245245
ParametersAction params = item.getAction(ParametersAction.class);
246246
if (params != null) {
247247
paramsList = params.getParameters();
248248
}
249+
else
250+
{
251+
paramsList = new ArrayList<ParameterValue>();
252+
}
249253
return paramsList;
250254
}
251255

0 commit comments

Comments
 (0)