Skip to content

Commit 69561ab

Browse files
committed
Applied patches of pull request jenkinsci#990: Test/implement windows ssh
1 parent 132eba5 commit 69561ab

File tree

13 files changed

+862
-1024
lines changed

13 files changed

+862
-1024
lines changed

src/main/java/hudson/plugins/ec2/AMITypeData.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import java.util.concurrent.TimeUnit;
66

77
public abstract class AMITypeData extends AbstractDescribableImpl<AMITypeData> {
8+
9+
public abstract boolean isWindowsSSH();
10+
811
public abstract boolean isWindows();
912

1013
public abstract boolean isUnix();

src/main/java/hudson/plugins/ec2/EC2OndemandSlave.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import hudson.plugins.ec2.ssh.EC2UnixLauncher;
88
import hudson.plugins.ec2.win.EC2WindowsLauncher;
99
import hudson.plugins.ec2.ssh.EC2MacLauncher;
10+
import hudson.plugins.ec2.ssh.EC2WindowsSSHLauncher;
1011
import hudson.slaves.NodeProperty;
1112

1213
import java.io.IOException;
1314
import java.util.Collections;
1415
import java.util.List;
15-
import java.util.concurrent.CountDownLatch;
1616
import java.util.logging.Level;
1717
import java.util.logging.Logger;
1818

@@ -73,8 +73,8 @@ public EC2OndemandSlave(String name, String instanceId, String templateDescripti
7373
@DataBoundConstructor
7474
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)
7575
throws FormException, IOException {
76-
super(name, instanceId, templateDescription, remoteFS, numExecutors, mode, labelString, (amiType.isWindows() ? new EC2WindowsLauncher() : (amiType.isMac() ? new EC2MacLauncher():
77-
new EC2UnixLauncher())), new EC2RetentionStrategy(idleTerminationMinutes), initScript, tmpDir, nodeProperties, remoteAdmin, javaPath, jvmopts, stopOnTerminate, idleTerminationMinutes, tags, cloudName, launchTimeout, amiType, connectionStrategy, maxTotalUses, tenancy, metadataEndpointEnabled, metadataTokensRequired, metadataHopsLimit, metadataSupported);
76+
super(name, instanceId, templateDescription, remoteFS, numExecutors, mode, labelString, (amiType.isWindows() ? new EC2WindowsLauncher() : (amiType.isMac() ? new EC2MacLauncher(): (amiType.isWindowsSSH() ? new EC2WindowsSSHLauncher() :
77+
new EC2UnixLauncher()))), new EC2RetentionStrategy(idleTerminationMinutes), initScript, tmpDir, nodeProperties, remoteAdmin, javaPath, jvmopts, stopOnTerminate, idleTerminationMinutes, tags, cloudName, launchTimeout, amiType, connectionStrategy, maxTotalUses, tenancy, metadataEndpointEnabled, metadataTokensRequired, metadataHopsLimit, metadataSupported);
7878
this.publicDNS = publicDNS;
7979
this.privateDNS = privateDNS;
8080
}

src/main/java/hudson/plugins/ec2/MacData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ protected Object readResolve() {
2929
return this;
3030
}
3131

32+
@Override
33+
public boolean isWindowsSSH() {
34+
return false;
35+
}
36+
3237
@Override
3338
public boolean isWindows() {
3439
return false;
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package hudson.plugins.ec2;
2+
3+
import jenkins.model.Jenkins;
4+
import org.apache.commons.lang.StringUtils;
5+
6+
public abstract class SSHData extends AMITypeData {
7+
protected final String rootCommandPrefix;
8+
protected final String slaveCommandPrefix;
9+
protected final String slaveCommandSuffix;
10+
protected final String sshPort;
11+
protected final String bootDelay;
12+
13+
protected SSHData(String rootCommandPrefix, String slaveCommandPrefix, String slaveCommandSuffix, String sshPort, String bootDelay) {
14+
this.rootCommandPrefix = rootCommandPrefix;
15+
this.slaveCommandPrefix = slaveCommandPrefix;
16+
this.slaveCommandSuffix = slaveCommandSuffix;
17+
this.sshPort = sshPort;
18+
this.bootDelay = bootDelay;
19+
20+
this.readResolve();
21+
}
22+
23+
protected Object readResolve() {
24+
Jenkins j = Jenkins.getInstanceOrNull();
25+
if (j != null) {
26+
j.checkPermission(Jenkins.ADMINISTER);
27+
}
28+
return this;
29+
}
30+
31+
@Override
32+
public boolean isWindowsSSH() {
33+
return false;
34+
}
35+
36+
@Override
37+
public boolean isWindows() {
38+
return false;
39+
}
40+
41+
@Override
42+
public boolean isUnix() {
43+
return false;
44+
}
45+
46+
@Override
47+
public boolean isMac() {
48+
return false;
49+
}
50+
51+
public String getRootCommandPrefix() {
52+
return rootCommandPrefix;
53+
}
54+
55+
public String getSlaveCommandPrefix() {
56+
return slaveCommandPrefix;
57+
}
58+
59+
public String getSlaveCommandSuffix() {
60+
return slaveCommandSuffix;
61+
}
62+
63+
public String getSshPort() {
64+
return sshPort == null || sshPort.isEmpty() ? "22" : sshPort;
65+
}
66+
67+
public String getBootDelay() {
68+
return bootDelay;
69+
}
70+
71+
@Override
72+
public int hashCode() {
73+
final int prime = 31;
74+
int result = 1;
75+
result = prime * result + ((rootCommandPrefix == null) ? 0 : rootCommandPrefix.hashCode());
76+
result = prime * result + ((slaveCommandPrefix == null) ? 0 : slaveCommandPrefix.hashCode());
77+
result = prime * result + ((slaveCommandSuffix == null) ? 0 : slaveCommandSuffix.hashCode());
78+
result = prime * result + ((sshPort == null) ? 0 : sshPort.hashCode());
79+
result = prime * result + ((bootDelay == null) ? 0 : bootDelay.hashCode());
80+
return result;
81+
}
82+
83+
@Override
84+
public boolean equals(Object obj) {
85+
if (this == obj)
86+
return true;
87+
if (obj == null)
88+
return false;
89+
if (this.getClass() != obj.getClass())
90+
return false;
91+
final SSHData other = (SSHData) obj;
92+
if (StringUtils.isEmpty(rootCommandPrefix)) {
93+
if (!StringUtils.isEmpty(other.rootCommandPrefix))
94+
return false;
95+
} else if (!rootCommandPrefix.equals(other.rootCommandPrefix))
96+
return false;
97+
if (StringUtils.isEmpty(slaveCommandPrefix)) {
98+
if (!StringUtils.isEmpty(other.slaveCommandPrefix))
99+
return false;
100+
} else if (!slaveCommandPrefix.equals(other.slaveCommandPrefix))
101+
return false;
102+
if (StringUtils.isEmpty(slaveCommandSuffix)) {
103+
if (!StringUtils.isEmpty(other.slaveCommandSuffix))
104+
return false;
105+
} else if (!slaveCommandSuffix.equals(other.slaveCommandSuffix))
106+
return false;
107+
if (StringUtils.isEmpty(sshPort)) {
108+
if (!StringUtils.isEmpty(other.sshPort))
109+
return false;
110+
} else if (!sshPort.equals(other.sshPort))
111+
return false;
112+
if (bootDelay == null) {
113+
if (other.bootDelay != null)
114+
return false;
115+
} else if (!bootDelay.equals(other.bootDelay))
116+
return false;
117+
return true;
118+
}
119+
}
Lines changed: 4 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,28 @@
11
package hudson.plugins.ec2;
22

3+
import edu.umd.cs.findbugs.annotations.NonNull;
34
import hudson.Extension;
45
import hudson.model.Descriptor;
5-
import jenkins.model.Jenkins;
6-
import org.apache.commons.lang.StringUtils;
76
import org.kohsuke.stapler.DataBoundConstructor;
87

9-
public class UnixData extends AMITypeData {
10-
private final String rootCommandPrefix;
11-
private final String slaveCommandPrefix;
12-
private final String slaveCommandSuffix;
13-
private final String sshPort;
14-
private final String bootDelay;
8+
public class UnixData extends SSHData {
159

1610
@DataBoundConstructor
1711
public UnixData(String rootCommandPrefix, String slaveCommandPrefix, String slaveCommandSuffix, String sshPort, String bootDelay) {
18-
this.rootCommandPrefix = rootCommandPrefix;
19-
this.slaveCommandPrefix = slaveCommandPrefix;
20-
this.slaveCommandSuffix = slaveCommandSuffix;
21-
this.sshPort = sshPort;
22-
this.bootDelay = bootDelay;
23-
24-
this.readResolve();
25-
}
26-
27-
protected Object readResolve() {
28-
Jenkins j = Jenkins.getInstanceOrNull();
29-
if (j != null) {
30-
j.checkPermission(Jenkins.ADMINISTER);
31-
}
32-
return this;
33-
}
34-
35-
@Override
36-
public boolean isWindows() {
37-
return false;
12+
super(rootCommandPrefix, slaveCommandPrefix, slaveCommandSuffix, sshPort, bootDelay);
3813
}
3914

4015
@Override
4116
public boolean isUnix() {
4217
return true;
4318
}
4419

45-
@Override
46-
public boolean isMac() {
47-
return false;
48-
}
49-
5020
@Extension
5121
public static class DescriptorImpl extends Descriptor<AMITypeData> {
5222
@Override
23+
@NonNull
5324
public String getDisplayName() {
5425
return "unix";
5526
}
5627
}
57-
58-
public String getRootCommandPrefix() {
59-
return rootCommandPrefix;
60-
}
61-
62-
public String getSlaveCommandPrefix() {
63-
return slaveCommandPrefix;
64-
}
65-
66-
public String getSlaveCommandSuffix() {
67-
return slaveCommandSuffix;
68-
}
69-
70-
public String getSshPort() {
71-
return sshPort == null || sshPort.isEmpty() ? "22" : sshPort;
72-
}
73-
74-
public String getBootDelay() {
75-
return bootDelay;
76-
}
77-
78-
@Override
79-
public int hashCode() {
80-
final int prime = 31;
81-
int result = 1;
82-
result = prime * result + ((rootCommandPrefix == null) ? 0 : rootCommandPrefix.hashCode());
83-
result = prime * result + ((slaveCommandPrefix == null) ? 0 : slaveCommandPrefix.hashCode());
84-
result = prime * result + ((slaveCommandSuffix == null) ? 0 : slaveCommandSuffix.hashCode());
85-
result = prime * result + ((sshPort == null) ? 0 : sshPort.hashCode());
86-
result = prime * result + ((bootDelay == null) ? 0 : bootDelay.hashCode());
87-
return result;
88-
}
89-
90-
@Override
91-
public boolean equals(Object obj) {
92-
if (this == obj)
93-
return true;
94-
if (obj == null)
95-
return false;
96-
if (this.getClass() != obj.getClass())
97-
return false;
98-
final UnixData other = (UnixData) obj;
99-
if (StringUtils.isEmpty(rootCommandPrefix)) {
100-
if (!StringUtils.isEmpty(other.rootCommandPrefix))
101-
return false;
102-
} else if (!rootCommandPrefix.equals(other.rootCommandPrefix))
103-
return false;
104-
if (StringUtils.isEmpty(slaveCommandPrefix)) {
105-
if (!StringUtils.isEmpty(other.slaveCommandPrefix))
106-
return false;
107-
} else if (!slaveCommandPrefix.equals(other.slaveCommandPrefix))
108-
return false;
109-
if (StringUtils.isEmpty(slaveCommandSuffix)) {
110-
if (!StringUtils.isEmpty(other.slaveCommandSuffix))
111-
return false;
112-
} else if (!slaveCommandSuffix.equals(other.slaveCommandSuffix))
113-
return false;
114-
if (StringUtils.isEmpty(sshPort)) {
115-
if (!StringUtils.isEmpty(other.sshPort))
116-
return false;
117-
} else if (!sshPort.equals(other.sshPort))
118-
return false;
119-
if (bootDelay == null) {
120-
if (other.bootDelay != null)
121-
return false;
122-
} else if (!bootDelay.equals(other.bootDelay))
123-
return false;
124-
return true;
125-
}
12628
}

src/main/java/hudson/plugins/ec2/WindowsData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public WindowsData(String password, boolean useHTTPS, String bootDelay) {
4040
this(password, useHTTPS, bootDelay, false);
4141
}
4242

43+
@Override
44+
public boolean isWindowsSSH() {
45+
return false;
46+
}
47+
4348
@Override
4449
public boolean isWindows() {
4550
return true;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package hudson.plugins.ec2;
2+
3+
import edu.umd.cs.findbugs.annotations.NonNull;
4+
import hudson.Extension;
5+
import hudson.model.Descriptor;
6+
import org.kohsuke.stapler.DataBoundConstructor;
7+
8+
9+
public class WindowsSSHData extends SSHData {
10+
11+
@DataBoundConstructor
12+
public WindowsSSHData(String rootCommandPrefix, String slaveCommandPrefix, String slaveCommandSuffix, String sshPort, String bootDelay) {
13+
super(rootCommandPrefix, slaveCommandPrefix, slaveCommandSuffix, sshPort, bootDelay);
14+
}
15+
16+
@Override
17+
public boolean isWindowsSSH() {
18+
return true;
19+
}
20+
21+
22+
@Extension
23+
public static class DescriptorImpl extends Descriptor<AMITypeData> {
24+
@Override
25+
@NonNull
26+
public String getDisplayName() {
27+
return "windows-ssh";
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)