From 471467f65865f8f53713dec1d24fc7c2b456cd77 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Thu, 25 Jul 2019 14:11:43 +0200 Subject: [PATCH 1/5] Allow defining node properties on template --- .../hudson/plugins/ec2/SlaveTemplate.java | 44 +++++++++++++++++-- .../plugins/ec2/SlaveTemplate/config.jelly | 2 + 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java index 5e7a59e7f..4f1c10058 100644 --- a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java +++ b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java @@ -67,6 +67,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; @@ -150,6 +153,8 @@ public class SlaveTemplate implements Describable { public int maxTotalUses; + public /* almost final */DescribableList, NodePropertyDescriptor> nodeProperties; + public int nextSubnet; public String currentSubnetId; @@ -187,8 +192,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> 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 @@ -223,6 +228,7 @@ public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, Stri this.useDedicatedTenancy = useDedicatedTenancy; this.connectBySSHProcess = connectBySSHProcess; this.maxTotalUses = maxTotalUses; + this.nodeProperties = new DescribableList,NodePropertyDescriptor>(Saveable.NOOP, nodeProperties); this.monitoring = monitoring; this.nextSubnet = 0; @@ -252,6 +258,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 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, @@ -559,6 +581,15 @@ public int getMaxTotalUses() { return maxTotalUses; } + public List getNodePropertyDescriptors() { + return NodePropertyDescriptor.for_(NodeProperty.all(), EC2AbstractSlave.class); + } + + public DescribableList, NodePropertyDescriptor> getNodeProperties() { + assert nodeProperties != null; + return nodeProperties; + } + public enum ProvisionOptions { ALLOW_CREATE, FORCE_CREATE } /** @@ -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) @@ -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) @@ -1298,6 +1329,11 @@ protected Object readResolve() { maxTotalUses = -1; } + // 1.45 new parameters + if (nodeProperties == null) { + nodeProperties = new DescribableList<>(Saveable.NOOP); + } + return this; } diff --git a/src/main/resources/hudson/plugins/ec2/SlaveTemplate/config.jelly b/src/main/resources/hudson/plugins/ec2/SlaveTemplate/config.jelly index 8c6fe48fa..3c1b87282 100644 --- a/src/main/resources/hudson/plugins/ec2/SlaveTemplate/config.jelly +++ b/src/main/resources/hudson/plugins/ec2/SlaveTemplate/config.jelly @@ -182,6 +182,8 @@ THE SOFTWARE. + + From ccaa4c40af4b0a02b227b31fa4c97457f6f3d0bd Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Thu, 25 Jul 2019 21:43:07 +0200 Subject: [PATCH 2/5] Fixes --- src/main/java/hudson/plugins/ec2/SlaveTemplate.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java index 4f1c10058..e35e18ec2 100644 --- a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java +++ b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java @@ -153,7 +153,7 @@ public class SlaveTemplate implements Describable { public int maxTotalUses; - public /* almost final */DescribableList, NodePropertyDescriptor> nodeProperties; + private /* lazily initialized */ DescribableList, NodePropertyDescriptor> nodeProperties; public int nextSubnet; @@ -586,8 +586,7 @@ public List getNodePropertyDescriptors() { } public DescribableList, NodePropertyDescriptor> getNodeProperties() { - assert nodeProperties != null; - return nodeProperties; + return Objects.requireNonNull(nodeProperties); } public enum ProvisionOptions { ALLOW_CREATE, FORCE_CREATE } From d842e6753f0645220e7afded78f868113f72407f Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Tue, 10 Sep 2019 19:10:18 +0200 Subject: [PATCH 3/5] Rebase and fix --- src/main/java/hudson/plugins/ec2/SlaveTemplate.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java index e35e18ec2..6b5ff6793 100644 --- a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java +++ b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java @@ -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; From e5a59e6a0f207c43cb9074fcec80c959531f2a55 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Wed, 30 Oct 2019 15:08:28 +0100 Subject: [PATCH 4/5] Apply suggestions --- src/main/java/hudson/plugins/ec2/SlaveTemplate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java index 6b5ff6793..e1ea58cbc 100644 --- a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java +++ b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java @@ -229,7 +229,7 @@ public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, Stri this.useDedicatedTenancy = useDedicatedTenancy; this.connectBySSHProcess = connectBySSHProcess; this.maxTotalUses = maxTotalUses; - this.nodeProperties = new DescribableList,NodePropertyDescriptor>(Saveable.NOOP, nodeProperties); + this.nodeProperties = new DescribableList<>(Saveable.NOOP, Util.fixNull(nodeProperties)); this.monitoring = monitoring; this.nextSubnet = 0; From da04051a469cfe75136ca569bc3b429b8aa3cd9a Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Wed, 30 Oct 2019 21:47:11 +0100 Subject: [PATCH 5/5] Apply suggestions --- src/main/java/hudson/plugins/ec2/SlaveTemplate.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java index e1ea58cbc..5c4018b69 100644 --- a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java +++ b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java @@ -1329,7 +1329,6 @@ protected Object readResolve() { maxTotalUses = -1; } - // 1.45 new parameters if (nodeProperties == null) { nodeProperties = new DescribableList<>(Saveable.NOOP); }