Skip to content

Commit

Permalink
Changed to use WorkspaceList.allocate instead of acquire.
Browse files Browse the repository at this point in the history
Acquiring a quick lock causes parallelised builds to back up waiting for
the workspace to become available.  This is because WorkspaceList.allocate
will give executing jobs the first workspace as the given lock is a quick
lock.  Then builds will wait in WorkspaceList.acquire all trying to get
the same workspace.
  • Loading branch information
mellowplace committed May 12, 2016
1 parent 3342b0c commit 36bc08a
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/main/java/hudson/plugins/promoted_builds/Promotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public EnvVars getEnvironment(TaskListener listener) throws IOException, Interru

return e;
}


/**
* Get a user name of the person, who triggered the promotion.
* The method tries various sources like {@link UserIdCause} or {@link ManualCondition.Badge}.
Expand All @@ -180,7 +180,7 @@ public String getUserName() {
return nameFromUserIdCause;
}

//fallback to badge lookup for compatibility
//fallback to badge lookup for compatibility
for (PromotionBadge badget : getStatus().getBadges()) {
if (badget instanceof ManualCondition.Badge) {
final String nameFromBadge = ((ManualCondition.Badge) badget).getUserName();
Expand All @@ -191,14 +191,14 @@ public String getUserName() {
}
return Jenkins.ANONYMOUS.getName();
}


/**
* Gets ID of the {@link User}, who triggered the promotion.
* The method tries various sources like {@link UserIdCause} or {@link ManualCondition.Badge}.
* @return ID of the user who triggered the promotion.
* If the search fails, returns ID of {@link User#getUnknown()}.
* @since 2.22
* @since 2.22
*/
@Nonnull
public String getUserId() {
Expand All @@ -218,7 +218,7 @@ public String getUserId() {
return idFromUserIdCause;
}

//fallback to badge lookup for compatibility
//fallback to badge lookup for compatibility
for (PromotionBadge badget : getStatus().getBadges()) {
if (badget instanceof ManualCondition.Badge) {
final String idFromBadge = ((ManualCondition.Badge) badget).getUserId();
Expand All @@ -231,7 +231,7 @@ public String getUserId() {
}

public List<ParameterValue> getParameterValues(){
List<ParameterValue> values=new ArrayList<ParameterValue>();
List<ParameterValue> values=new ArrayList<ParameterValue>();
ParametersAction parametersAction=getParametersActions(this);
if (parametersAction!=null){
ManualCondition manualCondition=(ManualCondition) getProject().getPromotionCondition(ManualCondition.class.getName());
Expand All @@ -244,16 +244,16 @@ public List<ParameterValue> getParameterValues(){
}
return values;
}
//fallback to badge lookup for compatibility

//fallback to badge lookup for compatibility
for (PromotionBadge badget:getStatus().getBadges()){
if (badget instanceof ManualCondition.Badge){
return ((ManualCondition.Badge) badget).getParameterValues();
}
}
return Collections.emptyList();
}

/**
* Gets parameter definitions from the {@link ManualCondition}.
* @return List of parameter definitions to be presented.
Expand All @@ -266,7 +266,7 @@ public List<ParameterDefinition> getParameterDefinitionsWithValue(){
if (manualCondition == null) {
return definitions;
}

for (ParameterValue pvalue:getParameterValues()){
ParameterDefinition pdef=manualCondition.getParameterDefinition(pvalue.getName());
if (pdef == null) {
Expand All @@ -286,11 +286,11 @@ public void run() {

protected class RunnerImpl extends AbstractRunner {
final Promotion promotionRun;

RunnerImpl(final Promotion promotionRun) {
this.promotionRun = promotionRun;
}

@Override
protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
String customWorkspace = Promotion.this.getProject().getCustomWorkspace();
Expand All @@ -303,13 +303,13 @@ protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedExc
return Lease.createDummyLease(
rootPath.child(getEnvironment(listener).expand(customWorkspace)));
}

TopLevelItem item = (TopLevelItem)getTarget().getProject();
FilePath workspace = n.getWorkspaceFor(item);
if (workspace == null) {
throw new IOException("Cannot retrieve workspace for " + item + " on the node " + n);
}
return wsl.acquire(workspace, true);
return wsl.allocate(workspace, promotionRun);
}

protected Result doRun(BuildListener listener) throws Exception {
Expand All @@ -326,10 +326,10 @@ protected Result doRun(BuildListener listener) throws Exception {

if(!preBuild(listener,project.getBuildSteps()))
return Result.FAILURE;

try {
List<ParameterValue> params=getParameterValues();

if (params!=null){
for(ParameterValue value : params) {
BuildWrapper wrapper=value.createBuildWrapper(Promotion.this);
Expand All @@ -341,20 +341,20 @@ protected Result doRun(BuildListener listener) throws Exception {
}
}
}

if(!build(listener,project.getBuildSteps(),target))
return Result.FAILURE;

return null;
} finally {
boolean failed = false;

for(int i = buildEnvironments.size()-1; i >= 0; i--) {
if (!buildEnvironments.get(i).tearDown(Promotion.this,listener)) {
failed=true;
}
}

if(failed)
return Result.FAILURE;
}
Expand Down Expand Up @@ -419,7 +419,7 @@ private boolean preBuild(BuildListener listener, List<BuildStep> steps) {
}
return true;
}

}

public static final PermissionGroup PERMISSIONS = new PermissionGroup(Promotion.class, Messages._Promotion_Permissions_Title());
Expand All @@ -441,9 +441,9 @@ public boolean equals(Object obj) {
final Promotion other = (Promotion) obj;
return this.getId().equals(other.getId());
}



/**
* Factory method for creating {@link ParametersAction}
* @param parameters
Expand All @@ -462,15 +462,15 @@ public static ParametersAction getParametersActions(Promotion build){
* @param build
* @param promotionParams
*/
public static void buildParametersAction(@Nonnull List<Action> actions,
public static void buildParametersAction(@Nonnull List<Action> actions,
@Nonnull AbstractBuild<?, ?> build,
@CheckForNull List<ParameterValue> promotionParams) {
if (promotionParams == null) {
promotionParams = new ArrayList<ParameterValue>();
}

List<ParameterValue> params=new ArrayList<ParameterValue>();

//Add the target build parameters first, if the same parameter is not being provided bu the promotion build
List<ParametersAction> parameters = build.getActions(ParametersAction.class);
for(ParametersAction paramAction:parameters){
Expand All @@ -480,10 +480,10 @@ public static void buildParametersAction(@Nonnull List<Action> actions,
}
}
}

//Add all the promotion build parameters
params.addAll(promotionParams);

// Create list of actions to pass to scheduled build
actions.add(new ParametersAction(params));
}
Expand Down

0 comments on commit 36bc08a

Please sign in to comment.