Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/main/java/hudson/plugins/ec2/AMITypeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.concurrent.TimeUnit;

public abstract class AMITypeData extends AbstractDescribableImpl<AMITypeData> {

public abstract boolean isWindowsSSH();

public abstract boolean isWindows();

public abstract boolean isUnix();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/hudson/plugins/ec2/EC2OndemandSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import hudson.plugins.ec2.ssh.EC2UnixLauncher;
import hudson.plugins.ec2.win.EC2WindowsLauncher;
import hudson.plugins.ec2.ssh.EC2MacLauncher;
import hudson.plugins.ec2.ssh.EC2WindowsSSHLauncher;
import hudson.slaves.NodeProperty;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -73,8 +73,8 @@ public EC2OndemandSlave(String name, String instanceId, String templateDescripti
@DataBoundConstructor
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 javaPath, 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, Boolean metadataEndpointEnabled, Boolean metadataTokensRequired, Integer metadataHopsLimit, Boolean metadataSupported)
throws FormException, IOException {
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, javaPath, jvmopts, stopOnTerminate, idleTerminationMinutes, tags, cloudName, launchTimeout, amiType, connectionStrategy, maxTotalUses, tenancy, metadataEndpointEnabled, metadataTokensRequired, metadataHopsLimit, metadataSupported);
super(name, instanceId, templateDescription, remoteFS, numExecutors, mode, labelString, (amiType.isWindows() ? new EC2WindowsLauncher() : (amiType.isMac() ? new EC2MacLauncher(): (amiType.isWindowsSSH() ? new EC2WindowsSSHLauncher() :
new EC2UnixLauncher()))), new EC2RetentionStrategy(idleTerminationMinutes), initScript, tmpDir, nodeProperties, remoteAdmin, javaPath, jvmopts, stopOnTerminate, idleTerminationMinutes, tags, cloudName, launchTimeout, amiType, connectionStrategy, maxTotalUses, tenancy, metadataEndpointEnabled, metadataTokensRequired, metadataHopsLimit, metadataSupported);
this.publicDNS = publicDNS;
this.privateDNS = privateDNS;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/plugins/ec2/MacData.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ protected Object readResolve() {
return this;
}

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

@Override
public boolean isWindows() {
return false;
Expand Down
119 changes: 119 additions & 0 deletions src/main/java/hudson/plugins/ec2/SSHData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package hudson.plugins.ec2;

import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;

public abstract class SSHData extends AMITypeData {
protected final String rootCommandPrefix;
protected final String slaveCommandPrefix;
protected final String slaveCommandSuffix;
protected final String sshPort;
protected final String bootDelay;

protected SSHData(String rootCommandPrefix, String slaveCommandPrefix, String slaveCommandSuffix, String sshPort, String bootDelay) {
this.rootCommandPrefix = rootCommandPrefix;
this.slaveCommandPrefix = slaveCommandPrefix;
this.slaveCommandSuffix = slaveCommandSuffix;
this.sshPort = sshPort;
this.bootDelay = bootDelay;

this.readResolve();
}

protected Object readResolve() {
Jenkins j = Jenkins.getInstanceOrNull();
if (j != null) {
j.checkPermission(Jenkins.ADMINISTER);
}
return this;
}

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

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

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

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

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;
}

public String getBootDelay() {
return bootDelay;
}

@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());
result = prime * result + ((bootDelay == null) ? 0 : bootDelay.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 SSHData other = (SSHData) 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;
if (bootDelay == null) {
if (other.bootDelay != null)
return false;
} else if (!bootDelay.equals(other.bootDelay))
return false;
return true;
}
}
106 changes: 4 additions & 102 deletions src/main/java/hudson/plugins/ec2/UnixData.java
Original file line number Diff line number Diff line change
@@ -1,126 +1,28 @@
package hudson.plugins.ec2;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

public class UnixData extends AMITypeData {
private final String rootCommandPrefix;
private final String slaveCommandPrefix;
private final String slaveCommandSuffix;
private final String sshPort;
private final String bootDelay;
public class UnixData extends SSHData {

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

this.readResolve();
}

protected Object readResolve() {
Jenkins j = Jenkins.getInstanceOrNull();
if (j != null) {
j.checkPermission(Jenkins.ADMINISTER);
}
return this;
}

@Override
public boolean isWindows() {
return false;
super(rootCommandPrefix, slaveCommandPrefix, slaveCommandSuffix, sshPort, bootDelay);
}

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

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

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

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;
}

public String getBootDelay() {
return bootDelay;
}

@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());
result = prime * result + ((bootDelay == null) ? 0 : bootDelay.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 UnixData other = (UnixData) 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;
if (bootDelay == null) {
if (other.bootDelay != null)
return false;
} else if (!bootDelay.equals(other.bootDelay))
return false;
return true;
}
}
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 @@ -40,6 +40,11 @@ public WindowsData(String password, boolean useHTTPS, String bootDelay) {
this(password, useHTTPS, bootDelay, false);
}

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

@Override
public boolean isWindows() {
return true;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/hudson/plugins/ec2/WindowsSSHData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hudson.plugins.ec2;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Descriptor;
import org.kohsuke.stapler.DataBoundConstructor;


public class WindowsSSHData extends SSHData {

@DataBoundConstructor
public WindowsSSHData(String rootCommandPrefix, String slaveCommandPrefix, String slaveCommandSuffix, String sshPort, String bootDelay) {
super(rootCommandPrefix, slaveCommandPrefix, slaveCommandSuffix, sshPort, bootDelay);
}

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


@Extension
public static class DescriptorImpl extends Descriptor<AMITypeData> {
@Override
@NonNull
public String getDisplayName() {
return "windows-ssh";
}
}
}
Loading