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

Adding Mac AMI Type support to launch mac1.metal instances by ec2-plugin #585

Merged
merged 30 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6424127
Add Support for Host Tenancy Option
yogeshkhandelwal Sep 2, 2020
af8422c
Add Support for Host Tenancy Option
yogeshkhandelwal Sep 2, 2020
0d6205d
Add Support for Host Tenancy Option
yogeshkhandelwal Sep 3, 2020
ec7c1e3
Fixing padding
yogeshkhandelwal Sep 3, 2020
e88d6e6
Fixing padding
yogeshkhandelwal Sep 3, 2020
3045a13
Fixing padding
yogeshkhandelwal Sep 3, 2020
23b9f2c
Fixing padding
yogeshkhandelwal Sep 3, 2020
3729123
Fixing padding
yogeshkhandelwal Sep 3, 2020
760620f
Fixing padding
yogeshkhandelwal Sep 3, 2020
a513eba
fixing tests
yogeshkhandelwal Sep 7, 2020
b663d3e
fixing tests
yogeshkhandelwal Sep 7, 2020
b2a38e0
fixing padding
yogeshkhandelwal Sep 7, 2020
1e974f0
fixing padding
yogeshkhandelwal Sep 7, 2020
3105e56
fixing padding
yogeshkhandelwal Sep 7, 2020
176ea49
fixing padding
yogeshkhandelwal Sep 7, 2020
035c747
Adding Tenancy attribute as drop down
yogeshkhandelwal Jan 4, 2021
0636321
Adding Tenancy attribute as drop down
yogeshkhandelwal Jan 4, 2021
e7e305d
Adding Tenancy attribute as drop down
yogeshkhandelwal Jan 4, 2021
9ac980b
Fixing builds
yogeshkhandelwal Jan 5, 2021
c78128b
Adding review comment
yogeshkhandelwal Mar 6, 2021
5a6cd71
Adding review comment
yogeshkhandelwal Mar 6, 2021
29a280d
migrating old tenancy value to new variable
yogeshkhandelwal Mar 19, 2021
035a820
Merge remote-tracking branch 'upstream/master' into macSupport
yogeshkhandelwal Mar 19, 2021
37d4fbd
Adding mac support in ec2-plugin
yogeshkhandelwal Mar 22, 2021
94fcc98
Adding backword compatibility for useDedicatedTenancy
yogeshkhandelwal Mar 23, 2021
c9b8c12
Merge branch 'master' of https://github.com/ykhandelwal913/ec2-plugin…
yogeshkhandelwal Mar 23, 2021
d517c91
fixing the resolve conflict
yogeshkhandelwal Apr 5, 2021
2ce8282
fixing resolve conflict
yogeshkhandelwal Apr 5, 2021
cd7f509
Fixing build
yogeshkhandelwal Apr 5, 2021
3e67a96
renaming the mac slave to mac agent
yogeshkhandelwal Apr 9, 2021
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
2 changes: 2 additions & 0 deletions src/main/java/hudson/plugins/ec2/AMITypeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public abstract class AMITypeData extends AbstractDescribableImpl<AMITypeData> {
public abstract boolean isWindows();

public abstract boolean isUnix();

public abstract boolean isMac();
}
10 changes: 6 additions & 4 deletions src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ public EC2Cloud getCloud() {
return 240;
case M5a24xlarge:
return 240;
case Mac1Metal:
return 1;
// We don't have a suggestion, but we don't want to fail completely
// surely?
default:
Expand Down Expand Up @@ -515,21 +517,21 @@ public String getRemoteAdmin() {
}

String getRootCommandPrefix() {
String commandPrefix = amiType.isUnix() ? ((UnixData) amiType).getRootCommandPrefix() : "";
String commandPrefix = (amiType.isUnix() ? ((UnixData) amiType).getRootCommandPrefix() : (amiType.isMac() ? ((MacData) amiType).getRootCommandPrefix() : ""));
if (commandPrefix == null || commandPrefix.length() == 0)
return "";
return commandPrefix + " ";
}

String getSlaveCommandPrefix() {
String commandPrefix = amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandPrefix() : "";
String commandPrefix = (amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandPrefix() :(amiType.isMac() ? ((MacData) amiType).getSlaveCommandPrefix() : ""));
if (commandPrefix == null || commandPrefix.length() == 0)
return "";
return commandPrefix + " ";
}

String getSlaveCommandSuffix() {
String commandSuffix = amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandSuffix() : "";
String commandSuffix = (amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandSuffix() :(amiType.isMac() ? ((MacData) amiType).getSlaveCommandSuffix() : ""));
if (commandSuffix == null || commandSuffix.length() == 0)
return "";
return " " + commandSuffix;
Expand All @@ -540,7 +542,7 @@ String getJvmopts() {
}

public int getSshPort() {
String sshPort = amiType.isUnix() ? ((UnixData) amiType).getSshPort() : "22";
String sshPort = (amiType.isUnix() ? ((UnixData) amiType).getSshPort() :(amiType.isMac() ? ((MacData) amiType).getSshPort() : "22"));
if (sshPort == null || sshPort.length() == 0)
return 22;

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/hudson/plugins/ec2/EC2HostAddressProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,28 @@ public static String unix(Instance instance, ConnectionStrategy strategy) {
}
}

public static String mac(Instance instance, ConnectionStrategy strategy) {
switch (strategy) {
case PUBLIC_DNS:
return filterNonEmpty(getPublicDnsName(instance)).orElse(getPublicIpAddress(instance));
case PUBLIC_IP:
return getPublicIpAddress(instance);
case PRIVATE_DNS:
return filterNonEmpty(getPrivateDnsName(instance)).orElse(getPrivateIpAddress(instance));
case PRIVATE_IP:
return getPrivateIpAddress(instance);
default:
throw new IllegalArgumentException("Could not mac host address for strategy = " + strategy.toString());
}
}

public static String windows(Instance instance, ConnectionStrategy strategy) {
if (strategy.equals(PRIVATE_DNS) || strategy.equals(PRIVATE_IP)) {
return getPrivateIpAddress(instance);
} else if (strategy.equals(PUBLIC_DNS) || strategy.equals(PUBLIC_IP)) {
return getPublicIpAddress(instance);
} else {
throw new IllegalArgumentException("Could not unix host address for strategy = " + strategy.toString());
throw new IllegalArgumentException("Could not windows host address for strategy = " + strategy.toString());
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/ec2/EC2OndemandSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import hudson.model.Node;
import hudson.plugins.ec2.ssh.EC2UnixLauncher;
import hudson.plugins.ec2.win.EC2WindowsLauncher;
import hudson.plugins.ec2.ssh.EC2MacLauncher;
import hudson.slaves.NodeProperty;

import java.io.IOException;
Expand Down Expand Up @@ -62,8 +63,8 @@ public EC2OndemandSlave(String name, String instanceId, String templateDescripti
public EC2OndemandSlave(String name, String instanceId, String templateDescription, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType, ConnectionStrategy connectionStrategy, int maxTotalUses, Tenancy tenancy)
throws FormException, IOException {

super(name, instanceId, templateDescription, remoteFS, numExecutors, mode, labelString, amiType.isWindows() ? new EC2WindowsLauncher()
: new EC2UnixLauncher(), new EC2RetentionStrategy(idleTerminationMinutes), initScript, tmpDir, nodeProperties, remoteAdmin, jvmopts, stopOnTerminate, idleTerminationMinutes, tags, cloudName, launchTimeout, amiType, connectionStrategy, maxTotalUses, tenancy);
super(name, instanceId, templateDescription, remoteFS, numExecutors, mode, labelString, (amiType.isWindows() ? new EC2WindowsLauncher() : (amiType.isMac() ? new EC2MacLauncher():
new EC2UnixLauncher())), new EC2RetentionStrategy(idleTerminationMinutes), initScript, tmpDir, nodeProperties, remoteAdmin, jvmopts, stopOnTerminate, idleTerminationMinutes, tags, cloudName, launchTimeout, amiType, connectionStrategy, maxTotalUses, tenancy);

this.publicDNS = publicDNS;
this.privateDNS = privateDNS;
Expand Down
142 changes: 142 additions & 0 deletions src/main/java/hudson/plugins/ec2/MacData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package hudson.plugins.ec2;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

public class MacData extends AMITypeData {
private final String rootCommandPrefix;
private final String slaveCommandPrefix;
private final String slaveCommandSuffix;
private final String sshPort;

@DataBoundConstructor
public MacData(String rootCommandPrefix, String slaveCommandPrefix, String slaveCommandSuffix, String sshPort) {
this.rootCommandPrefix = rootCommandPrefix;
this.slaveCommandPrefix = slaveCommandPrefix;
this.slaveCommandSuffix = slaveCommandSuffix;
this.sshPort = sshPort;

this.readResolve();
}

protected Object readResolve() {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
return this;
}

@Override
public boolean isWindows() {
return false;
}

@Override
public boolean isUnix() {
return false;
}

@Override
public boolean isMac() {
return true;
}

@Extension
public static class DescriptorImpl extends Descriptor<AMITypeData> {
@Override
public String getDisplayName() {
return "mac";
}

@Restricted(NoExternalUse.class)
public FormValidation doCheckRootCommandPrefix(@QueryParameter String value){
if(StringUtils.isBlank(value) || Jenkins.get().hasPermission(Jenkins.ADMINISTER)){
return FormValidation.ok();
}else{
return FormValidation.error(Messages.General_MissingPermission());
}
}

@Restricted(NoExternalUse.class)
public FormValidation doCheckSlaveCommandPrefix(@QueryParameter String value){
if(StringUtils.isBlank(value) || Jenkins.get().hasPermission(Jenkins.ADMINISTER)){
return FormValidation.ok();
}else{
return FormValidation.error(Messages.General_MissingPermission());
}
}

@Restricted(NoExternalUse.class)
public FormValidation doCheckSlaveCommandSuffix(@QueryParameter String value){
if(StringUtils.isBlank(value) || Jenkins.get().hasPermission(Jenkins.ADMINISTER)){
return FormValidation.ok();
}else{
return FormValidation.error(Messages.General_MissingPermission());
}
}
}

public String getRootCommandPrefix() {
return rootCommandPrefix;
}

public String getSlaveCommandPrefix() {
return slaveCommandPrefix;
}

public String getSlaveCommandSuffix() {
return slaveCommandSuffix;
}

public String getSshPort() {
return sshPort == null || sshPort.isEmpty() ? "22" : sshPort;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((rootCommandPrefix == null) ? 0 : rootCommandPrefix.hashCode());
result = prime * result + ((slaveCommandPrefix == null) ? 0 : slaveCommandPrefix.hashCode());
result = prime * result + ((slaveCommandSuffix == null) ? 0 : slaveCommandSuffix.hashCode());
result = prime * result + ((sshPort == null) ? 0 : sshPort.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
final MacData other = (MacData) obj;
if (StringUtils.isEmpty(rootCommandPrefix)) {
if (!StringUtils.isEmpty(other.rootCommandPrefix))
return false;
} else if (!rootCommandPrefix.equals(other.rootCommandPrefix))
return false;
if (StringUtils.isEmpty(slaveCommandPrefix)) {
if (!StringUtils.isEmpty(other.slaveCommandPrefix))
return false;
} else if (!slaveCommandPrefix.equals(other.slaveCommandPrefix))
return false;
if (StringUtils.isEmpty(slaveCommandSuffix)) {
if (!StringUtils.isEmpty(other.slaveCommandSuffix))
return false;
} else if (!slaveCommandSuffix.equals(other.slaveCommandSuffix))
return false;
if (StringUtils.isEmpty(sshPort)) {
if (!StringUtils.isEmpty(other.sshPort))
return false;
} else if (!sshPort.equals(other.sshPort))
return false;
return true;
}
}
13 changes: 10 additions & 3 deletions src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ public int getSshPort() {
if (amiType.isUnix()) {
sshPort = ((UnixData) amiType).getSshPort();
}
if (amiType.isMac()) {
sshPort = ((MacData) amiType).getSshPort();
}
return Integer.parseInt(sshPort);
} catch (NumberFormatException e) {
return 22;
Expand All @@ -660,15 +663,15 @@ public String getRemoteAdmin() {
}

public String getRootCommandPrefix() {
return amiType.isUnix() ? ((UnixData) amiType).getRootCommandPrefix() : "";
return (amiType.isUnix() ? ((UnixData) amiType).getRootCommandPrefix() : (amiType.isMac() ? ((MacData) amiType).getRootCommandPrefix():""));
}

public String getSlaveCommandPrefix() {
return amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandPrefix() : "";
return (amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandPrefix() : (amiType.isMac() ? ((MacData) amiType).getSlaveCommandPrefix() : ""));
}

public String getSlaveCommandSuffix() {
return amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandSuffix() : "";
return (amiType.isUnix() ? ((UnixData) amiType).getSlaveCommandSuffix() : (amiType.isMac() ? ((MacData) amiType).getSlaveCommandSuffix() : ""));
}

public String chooseSubnetId() {
Expand Down Expand Up @@ -1738,6 +1741,10 @@ public boolean isUnixSlave() {
return amiType.isUnix();
}

public boolean isMacAgent() {
return amiType.isMac();
}

public Secret getAdminPassword() {
return amiType.isWindows() ? ((WindowsData) amiType).getPassword() : Secret.fromString("");
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/plugins/ec2/UnixData.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public boolean isUnix() {
return true;
}

@Override
public boolean isMac() {
return false;
}

@Extension
public static class DescriptorImpl extends Descriptor<AMITypeData> {
@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/plugins/ec2/WindowsData.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public boolean isUnix() {
return false;
}

@Override
public boolean isMac() {
return false;
}

public Secret getPassword() {
return password;
}
Expand Down
Loading