Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #35 from adamrofer/JENKINS-15970
Fix for JENKINS-15970: Add forcible synchronized serial delay option
  • Loading branch information
abayer committed Dec 6, 2012
2 parents 67af6ab + e7eb5a3 commit 42167b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Expand Up @@ -71,6 +71,8 @@ public class JCloudsSlaveTemplate implements Describable<JCloudsSlaveTemplate>,
private final String fsRoot;
public final boolean allowSudo;
public final int overrideRetentionTime;
public final int spoolDelayMs;
private final Object delayLockObject = new Object();

private transient Set<LabelAtom> labelSet;

Expand All @@ -97,7 +99,9 @@ public JCloudsSlaveTemplate(final String name,
final boolean preExistingJenkinsUser,
final String fsRoot,
final boolean allowSudo,
final int overrideRetentionTime) {
final int overrideRetentionTime,
final int spoolDelayMs
) {

this.name = Util.fixEmptyAndTrim(name);
this.imageId = Util.fixEmptyAndTrim(imageId);
Expand All @@ -119,6 +123,7 @@ public JCloudsSlaveTemplate(final String name,
this.fsRoot = Util.fixEmptyAndTrim(fsRoot);
this.allowSudo = allowSudo;
this.overrideRetentionTime = overrideRetentionTime;
this.spoolDelayMs = spoolDelayMs;
readResolve();
}

Expand Down Expand Up @@ -200,6 +205,21 @@ public NodeMetadata get() {
template.getOptions().overrideLoginCredentials(lc);
}

if (spoolDelayMs > 0)
{
// (JENKINS-15970) Add optional delay before spooling. Author: Adam Rofer
synchronized(delayLockObject)
{
LOGGER.info("Delaying " + spoolDelayMs + " milliseconds. Current ms -> " + System.currentTimeMillis());
try
{
Thread.sleep(spoolDelayMs);
}
catch (InterruptedException e)
{
}
}
}

Statement initStatement = null;
Statement bootstrap = null;
Expand Down
Expand Up @@ -65,6 +65,11 @@
<f:entry title="Override Retention Time" field="overrideRetentionTime">
<f:textbox />
</f:entry>

<f:entry title="Delay before spooling up (ms)" field="spoolDelayMs">
<f:textbox />
</f:entry>

<f:entry title="Init Script" field="initScript">
<f:textarea />
</f:entry>
Expand Down
@@ -0,0 +1,3 @@
<div>
Optional delay before spooling up a VM instance (in milliseconds).
</div>
Expand Up @@ -14,7 +14,7 @@ public void testConfigRoundtrip() throws Exception {
String name = "testSlave";
JCloudsSlaveTemplate originalTemplate = new JCloudsSlaveTemplate(name, "imageId", "hardwareId", 1, 512, "osFamily",
"osVersion", "jclouds-slave-type1 jclouds-type2", "Description",
"initScript", "1", false, null, null, true, "jenkins", false, null, false, 5);
"initScript", "1", false, null, null, true, "jenkins", false, null, false, 5, 0);

List<JCloudsSlaveTemplate> templates = new ArrayList<JCloudsSlaveTemplate>();
templates.add(originalTemplate);
Expand Down

0 comments on commit 42167b2

Please sign in to comment.