Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-25865] Add ability to configure node usage mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmoore3 committed Mar 20, 2015
1 parent 20c6ca8 commit d2d8494
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
Expand Up @@ -41,6 +41,7 @@ public class JCloudsSlave extends AbstractCloudSlave {
private final boolean authSudo;
private final String jvmOptions;
private final String credentialsId;
private final Mode mode;

@DataBoundConstructor
@SuppressWarnings("rawtypes")
Expand All @@ -60,6 +61,7 @@ public JCloudsSlave(String cloudName, String name, String nodeDescription, Strin
this.waitPhoneHome = waitPhoneHome;
this.waitPhoneHomeTimeout = waitPhoneHomeTimeout;
this.credentialsId = credentialsId;
this.mode = mode;
}

/**
Expand All @@ -77,13 +79,14 @@ public JCloudsSlave(String cloudName, String name, String nodeDescription, Strin
* @param waitPhoneHome - if {@code true}, delay initial SSH connect until slave has "phoned home" back to jenkins.
* @param waitPhoneHomeTimeout - Timeout in minutes util giving up waiting for the "phone home" POST.
* @param credentialsId - Id of the credentials in Jenkin's global credentials database.
* @param mode - Jenkins usage mode for this node
* @throws IOException
* @throws Descriptor.FormException
*/
public JCloudsSlave(final String cloudName, final String fsRoot, NodeMetadata metadata, final String labelString,
final String description, final String numExecutors, final boolean stopOnTerminate, final int overrideRetentionTime,
String jvmOptions, final boolean waitPhoneHome, final int waitPhoneHomeTimeout, final String credentialsId) throws IOException, Descriptor.FormException {
this(cloudName, metadata.getName(), description, fsRoot, numExecutors, Mode.EXCLUSIVE, labelString,
String jvmOptions, final boolean waitPhoneHome, final int waitPhoneHomeTimeout, final String credentialsId, final Mode mode) throws IOException, Descriptor.FormException {
this(cloudName, metadata.getName(), description, fsRoot, numExecutors, mode, labelString,
new JCloudsLauncher(), new JCloudsRetentionStrategy(), Collections.<NodeProperty<?>>emptyList(),
stopOnTerminate, overrideRetentionTime, metadata.getCredentials().getUser(),
metadata.getCredentials().getPassword(), metadata.getCredentials().getPrivateKey(),
Expand Down Expand Up @@ -181,6 +184,10 @@ public String getCredentialsId() {
return credentialsId;
}

public Mode getMode() {
return mode;
}

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -24,6 +24,7 @@
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.model.Label;
import hudson.model.Node.Mode;
import hudson.model.ItemGroup;
import hudson.model.TaskListener;
import hudson.model.labels.LabelAtom;
Expand Down Expand Up @@ -113,6 +114,7 @@ public class JCloudsSlaveTemplate implements Describable<JCloudsSlaveTemplate>,
public final String networks;
public final String securityGroups;
public final String credentialsId;
public final Mode mode;

private transient Set<LabelAtom> labelSet;

Expand All @@ -125,7 +127,7 @@ public JCloudsSlaveTemplate(final String name, final String imageId, final Strin
final String vmUser, final boolean preInstalledJava, final String jvmOptions, final boolean preExistingJenkinsUser,
final String fsRoot, final boolean allowSudo, final boolean installPrivateKey, final int overrideRetentionTime, final int spoolDelayMs,
final boolean assignFloatingIp, final boolean waitPhoneHome, final int waitPhoneHomeTimeout, final String keyPairName,
final boolean assignPublicIp, final String networks, final String securityGroups, final String credentialsId) {
final boolean assignPublicIp, final String networks, final String securityGroups, final String credentialsId, final String mode) {

this.name = Util.fixEmptyAndTrim(name);
this.imageId = Util.fixEmptyAndTrim(imageId);
Expand Down Expand Up @@ -162,6 +164,7 @@ public JCloudsSlaveTemplate(final String name, final String imageId, final Strin
jenkinsUser = (null == credentialsId) ? "" : SSHLauncher.lookupSystemCredentials(credentialsId).getUsername();
this.vmPassword = Util.fixEmptyAndTrim(vmPassword);
this.vmUser = Util.fixEmptyAndTrim(vmUser);
this.mode = Mode.valueOf(Util.fixNull(mode));
readResolve();
}

Expand Down Expand Up @@ -215,7 +218,7 @@ public JCloudsSlave provisionSlave(TaskListener listener) throws IOException {
try {
return new JCloudsSlave(getCloud().getDisplayName(), getFsRoot(), nodeMetadata, labelString, description,
numExecutors, stopOnTerminate, overrideRetentionTime, getJvmOptions(), waitPhoneHome,
waitPhoneHomeTimeout, credentialsId);
waitPhoneHomeTimeout, credentialsId, mode);
} catch (Descriptor.FormException e) {
throw new AssertionError("Invalid configuration " + e.getMessage());
}
Expand Down
Expand Up @@ -18,6 +18,8 @@
<f:textbox />
</f:entry>

<f:slave-mode name="mode" node="${it}" />

<f:descriptorList title="${%Node Properties}" descriptors="${h.getNodePropertyDescriptors(descriptor.clazz)}" field="nodeProperties" />

<f:block>
Expand Down
Expand Up @@ -11,6 +11,7 @@
<f:entry title="Labels" field="labelString">
<f:textbox/>
</f:entry>
<f:slave-mode name="mode" node="${it}"/>
<f:entry title="Number of Executors" field="numExecutors">
<f:textbox/>
</f:entry>
Expand Down
Expand Up @@ -15,7 +15,7 @@ public void testConfigRoundtrip() throws Exception {
JCloudsSlaveTemplate originalTemplate = new JCloudsSlaveTemplate(name, "imageId", null, "hardwareId", 1, 512, "osFamily", "osVersion", "locationId",
"jclouds-slave-type1 jclouds-type2", "Description", "initScript", null, "1", false, null, null, true,
"jvmOptions", false, null, false,
false, 5, 0, true, false, 0, "jenkins", true, "network1_id,network2_id", "security_group1,security_group2", null);
false, 5, 0, true, false, 0, "jenkins", true, "network1_id,network2_id", "security_group1,security_group2", null, "NORMAL");

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

0 comments on commit d2d8494

Please sign in to comment.