Navigation Menu

Skip to content

Commit

Permalink
JENKINS-26848 Does not actually randomize DISPLAY
Browse files Browse the repository at this point in the history
Implement new feature for parallel builds, display names take
100*computer index offset if used.
  • Loading branch information
Zoran Regvart committed Feb 8, 2015
1 parent 0aa3519 commit 259e422
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/main/java/org/jenkinsci/plugins/xvfb/XvfbBuildWrapper.java
Expand Up @@ -63,6 +63,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -258,6 +260,16 @@ public void preOnline(final Computer c, final Channel channel, final FilePath ro

};

private static final class ComputerNameComparator implements Comparator<Computer> {

private static final ComputerNameComparator INSTANCE = new ComputerNameComparator();

public int compare(Computer left, Computer right) {
return left.getName().compareTo(right.getName());
}

}

private static final int MILLIS_IN_SECOND = 1000;

/** default screen configuration for Xvfb, used by default, and if user left screen configuration blank */
Expand Down Expand Up @@ -363,12 +375,15 @@ public Void call() throws InterruptedException {
/** Let Xvfb pick display number */
private boolean autoDisplayName = false;

/** Run only on ondes labeled */
/** Run only on nodes labeled */
private final String assignedLabels;

/** Run on same node in parallel */
private boolean parallelBuild = false;

@DataBoundConstructor
public XvfbBuildWrapper(final String installationName, final Integer displayName, final String screen, final Boolean debug, final int timeout, final int displayNameOffset,
final String additionalOptions, final Boolean shutdownWithBuild, final Boolean autoDisplayName, String assignedLabels) {
final String additionalOptions, final Boolean shutdownWithBuild, final Boolean autoDisplayName, String assignedLabels, final Boolean parallelBuild) {
this.installationName = installationName;
this.displayName = displayName;

Expand Down Expand Up @@ -398,6 +413,8 @@ public XvfbBuildWrapper(final String installationName, final Integer displayName
}

this.assignedLabels = Util.fixEmptyAndTrim(assignedLabels);

this.parallelBuild = parallelBuild;
}

public String getAdditionalOptions() {
Expand Down Expand Up @@ -457,27 +474,38 @@ public boolean isDebug() {
return debug;
}

public boolean isParallelBuild(){
return parallelBuild;
}

public boolean isShutdownWithBuild() {
return shutdownWithBuild;
}

private XvfbEnvironment launchXvfb(@SuppressWarnings("rawtypes") final AbstractBuild build, final Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {
int displayNameUsed;
final Computer currentComputer = Computer.currentComputer();

int displayNameUsed;

if (displayName == null) {
if (!autoDisplayName) {
final Executor executor = build.getExecutor();
displayNameUsed = executor.getNumber() + displayNameOffset;
}
else {
displayNameUsed = -1;
if (parallelBuild) {
final Computer[] computers = Jenkins.getInstance().getComputers();
final int nodeIndex = Arrays.binarySearch(computers, currentComputer, ComputerNameComparator.INSTANCE);

displayNameUsed = nodeIndex * 100 + executor.getNumber() + displayNameOffset;
} else {
displayNameUsed = executor.getNumber() + displayNameOffset;
}
} else {
displayNameUsed = -1;
}
}
else {
displayNameUsed = displayName;
}

final Computer currentComputer = Computer.currentComputer();
final Node currentNode = currentComputer.getNode();
final FilePath rootPath = currentNode.getRootPath();

Expand Down
Expand Up @@ -49,6 +49,10 @@ SUCH DAMAGE.
<f:textbox autoCompleteDelimChar=" " value="${instance.assignedLabels}" />
</f:entry>

<f:entry title="${%I’m running this job in parallel on same node}" field="parallelBuild">
<f:checkbox value="${instance.parallelBuild}" />
</f:entry>

<f:entry title="${%Timeout in seconds}" field="timeout">
<f:textbox value="${instance.timeout}" />
</f:entry>
Expand Down
@@ -0,0 +1,31 @@
<!--
Copyright (c) 2012 Zoran Regvart All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
-->
<div>When running multiple Jenkins nodes on the same machine this
setting influences the display number generation. The display number
will be based upon node position in the list of nodes multiplied by 100
to which current executor number and any given offset will be added.
Using this with offset set to 0 there is a limit of 595 nodes and 35
executors on a node, having more nodes or executors is not compatible
with this option.</div>

0 comments on commit 259e422

Please sign in to comment.