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-31801] Add Pipeline throttle(category) step #46
Changes from 1 commit
af877cd
c000c30
91cdb4b
d011b40
666ff55
42f4da1
8378722
492c500
89f7bce
33b8e0f
f09aea8
aca9d87
bb0fb3e
13cafdf
fdd9102
4ec2057
968d77c
0b222d3
7d83b60
ee1e959
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import hudson.model.TaskListener; | ||
import hudson.plugins.throttleconcurrents.ThrottleJobProperty; | ||
import hudson.util.FormValidation; | ||
import org.apache.commons.lang.StringUtils; | ||
import hudson.util.ListBoxModel; | ||
import org.jenkinsci.plugins.workflow.steps.Step; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor; | ||
|
@@ -14,40 +14,23 @@ | |
|
||
import javax.annotation.Nonnull; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.StringTokenizer; | ||
|
||
public class ThrottleStep extends Step implements Serializable { | ||
private String categories; | ||
private List<String> categories; | ||
|
||
@DataBoundConstructor | ||
public ThrottleStep(@Nonnull String categories) { | ||
public ThrottleStep(@Nonnull List<String> categories) { | ||
this.categories = categories; | ||
} | ||
|
||
@Nonnull | ||
public String getCategories() { | ||
public List<String> getCategories() { | ||
return categories; | ||
} | ||
|
||
@Nonnull | ||
public List<String> getCategoriesList() { | ||
List<String> catList = new ArrayList<>(); | ||
|
||
StringTokenizer tokenizer = new StringTokenizer(categories, ","); | ||
while (tokenizer.hasMoreTokens()) { | ||
String nextToken = tokenizer.nextToken().trim(); | ||
if (StringUtils.isNotEmpty(nextToken)) { | ||
catList.add(nextToken); | ||
} | ||
} | ||
|
||
return catList; | ||
} | ||
|
||
@Override | ||
public StepExecution start(StepContext context) throws Exception { | ||
return new ThrottleStepExecution(this, context); | ||
|
@@ -80,6 +63,14 @@ public Set<? extends Class<?>> getRequiredContext() { | |
public FormValidation doCheckCategoryName(@QueryParameter String value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restricted ? not sure if RequirePost is mandatory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. This doesn't actually expose any meaningful information - all you can do is tell whether there's a category with a given name, not anything about the category, etc. I think it's harmless, but defer to others. |
||
return ThrottleJobProperty.fetchDescriptor().doCheckCategoryName(value); | ||
} | ||
|
||
public List<ThrottleJobProperty.ThrottleCategory> getCategories() { | ||
return ThrottleJobProperty.fetchDescriptor().getCategories(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap to the unmodifyableList? |
||
} | ||
|
||
public ListBoxModel doFillCategoryItems() { | ||
return ThrottleJobProperty.fetchDescriptor().doFillCategoryItems(); | ||
} | ||
} | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No descriptor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoops. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
<?jelly escape-by-default='true'?> | ||
<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"> | ||
<f:entry title="${%Categories}" field="categories"> | ||
<f:textbox/> | ||
</f:entry> | ||
<j:choose> | ||
<j:when test="${!empty(descriptor.categories)}"> | ||
<f:entry title="${%Categories}"> | ||
<j:forEach var="cat" items="${descriptor.categories}"> | ||
<f:checkbox name="categories" json="${cat.categoryName}" checked="${instance.categories.contains(cat.categoryName)}" /> | ||
<label class="attach-previous">${cat.categoryName}</label> | ||
<st:nbsp/> | ||
</j:forEach> | ||
</f:entry> | ||
</j:when> | ||
<j:otherwise> | ||
No categories configured | ||
</j:otherwise> | ||
</j:choose> | ||
</j:jelly> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<p>One or more throttle categories in a list.</p> | ||
</div> |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you just have the one field, probably better to inline that into the execution state.