Skip to content
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

Allow defining node properties on template #382

Merged
merged 5 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -67,6 +68,9 @@
import hudson.model.*;
import hudson.model.Descriptor.FormException;
import hudson.model.labels.LabelAtom;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;

Expand Down Expand Up @@ -150,6 +154,8 @@ public class SlaveTemplate implements Describable<SlaveTemplate> {

public int maxTotalUses;

private /* lazily initialized */ DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties;

public int nextSubnet;

public String currentSubnetId;
Expand Down Expand Up @@ -187,8 +193,8 @@ public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, Stri
String instanceCapStr, String iamInstanceProfile, boolean deleteRootOnTermination,
boolean useEphemeralDevices, boolean useDedicatedTenancy, String launchTimeoutStr, boolean associatePublicIp,
String customDeviceMapping, boolean connectBySSHProcess, boolean monitoring,
boolean t2Unlimited, ConnectionStrategy connectionStrategy, int maxTotalUses) {

boolean t2Unlimited, ConnectionStrategy connectionStrategy, int maxTotalUses,
List<? extends NodeProperty<?>> nodeProperties) {
if(StringUtils.isNotBlank(remoteAdmin) || StringUtils.isNotBlank(jvmopts) || StringUtils.isNotBlank(tmpDir)){
LOGGER.log(Level.FINE, "As remoteAdmin, jvmopts or tmpDir is not blank, we must ensure the user has RUN_SCRIPTS rights.");
// Can be null during tests
Expand Down Expand Up @@ -223,6 +229,7 @@ public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, Stri
this.useDedicatedTenancy = useDedicatedTenancy;
this.connectBySSHProcess = connectBySSHProcess;
this.maxTotalUses = maxTotalUses;
this.nodeProperties = new DescribableList<>(Saveable.NOOP, Util.fixNull(nodeProperties));
this.monitoring = monitoring;
this.nextSubnet = 0;

Expand Down Expand Up @@ -252,6 +259,22 @@ public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, Stri
readResolve(); // initialize
}

@Deprecated
public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, String securityGroups, String remoteFS,
InstanceType type, boolean ebsOptimized, String labelString, Node.Mode mode, String description, String initScript,
String tmpDir, String userData, String numExecutors, String remoteAdmin, AMITypeData amiType, String jvmopts,
boolean stopOnTerminate, String subnetId, List<EC2Tag> tags, String idleTerminationMinutes, int minimumNumberOfInstances,
String instanceCapStr, String iamInstanceProfile, boolean deleteRootOnTermination,
boolean useEphemeralDevices, boolean useDedicatedTenancy, String launchTimeoutStr, boolean associatePublicIp,
String customDeviceMapping, boolean connectBySSHProcess, boolean monitoring,
boolean t2Unlimited, ConnectionStrategy connectionStrategy, int maxTotalUses) {
this(ami, zone, spotConfig, securityGroups, remoteFS, type, ebsOptimized, labelString, mode, description, initScript,
tmpDir, userData, numExecutors, remoteAdmin, amiType, jvmopts, stopOnTerminate, subnetId, tags,
idleTerminationMinutes, minimumNumberOfInstances, instanceCapStr, iamInstanceProfile, deleteRootOnTermination,
useEphemeralDevices, useDedicatedTenancy, launchTimeoutStr, associatePublicIp, customDeviceMapping,
connectBySSHProcess, monitoring, t2Unlimited, connectionStrategy, maxTotalUses, Collections.emptyList());
}

@Deprecated
public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, String securityGroups, String remoteFS,
InstanceType type, boolean ebsOptimized, String labelString, Node.Mode mode, String description, String initScript,
Expand Down Expand Up @@ -559,6 +582,14 @@ public int getMaxTotalUses() {
return maxTotalUses;
}

public List<NodePropertyDescriptor> getNodePropertyDescriptors() {
return NodePropertyDescriptor.for_(NodeProperty.all(), EC2AbstractSlave.class);
}

public DescribableList<NodeProperty<?>, NodePropertyDescriptor> getNodeProperties() {
return Objects.requireNonNull(nodeProperties);
mildsunrise marked this conversation as resolved.
Show resolved Hide resolved
}

public enum ProvisionOptions { ALLOW_CREATE, FORCE_CREATE }

/**
Expand Down Expand Up @@ -1120,7 +1151,7 @@ protected EC2OndemandSlave newOndemandSlave(Instance inst) throws FormException,
.withMode(mode)
.withInitScript(initScript)
.withTmpDir(tmpDir)
.withNodeProperties(Collections.emptyList())
.withNodeProperties(nodeProperties.toList())
.withRemoteAdmin(remoteAdmin)
.withJvmopts(jvmopts)
.withStopOnTerminate(stopOnTerminate)
Expand Down Expand Up @@ -1149,7 +1180,7 @@ protected EC2SpotSlave newSpotSlave(SpotInstanceRequest sir) throws FormExceptio
.withInitScript(initScript)
.withTmpDir(tmpDir)
.withLabelString(labels)
.withNodeProperties(Collections.emptyList())
.withNodeProperties(nodeProperties.toList())
.withRemoteAdmin(remoteAdmin)
.withJvmopts(jvmopts)
.withIdleTerminationMinutes(idleTerminationMinutes)
Expand Down Expand Up @@ -1298,6 +1329,10 @@ protected Object readResolve() {
maxTotalUses = -1;
}

if (nodeProperties == null) {
nodeProperties = new DescribableList<>(Saveable.NOOP);
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ THE SOFTWARE.
<f:textbox default="-1"/>
</f:entry>

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

</f:advanced>

<f:entry title="">
Expand Down