mirror of https://github.com/apache/jclouds.git
Use enum for PortForwardingRule protocol
This commit is contained in:
parent
6f463f1f79
commit
ef8438d59a
|
@ -85,7 +85,7 @@ public class CloudStackParserModule extends AbstractModule {
|
|||
private long IPAddressId;
|
||||
@SerializedName("privateport")
|
||||
private int privatePort;
|
||||
private String protocol;
|
||||
private PortForwardingRule.Protocol protocol;
|
||||
@SerializedName("publicport")
|
||||
public int publicPort;
|
||||
private String state;
|
||||
|
|
|
@ -26,9 +26,30 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
* @author Adrian Cole, Andrei Savu
|
||||
*/
|
||||
public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
||||
|
||||
public static enum Protocol {
|
||||
TCP,
|
||||
UDP,
|
||||
ICMP,
|
||||
UNKNOWN;
|
||||
|
||||
public static Protocol fromValue(String value) {
|
||||
try {
|
||||
return valueOf(value.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
@ -38,7 +59,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
private String IPAddress;
|
||||
private long IPAddressId;
|
||||
private int privatePort;
|
||||
private String protocol;
|
||||
private Protocol protocol;
|
||||
public int publicPort;
|
||||
private String state;
|
||||
private String virtualMachineDisplayName;
|
||||
|
@ -68,7 +89,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder protocol(String protocol) {
|
||||
public Builder protocol(Protocol protocol) {
|
||||
this.protocol = protocol;
|
||||
return this;
|
||||
}
|
||||
|
@ -115,7 +136,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
|
||||
public PortForwardingRule build() {
|
||||
return new PortForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state,
|
||||
virtualMachineDisplayName, virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort);
|
||||
virtualMachineDisplayName, virtualMachineId, virtualMachineName, CIDRs, privateEndPort, publicEndPort);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +147,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
private long IPAddressId;
|
||||
@SerializedName("privateport")
|
||||
private int privatePort;
|
||||
private String protocol;
|
||||
private Protocol protocol;
|
||||
@SerializedName("publicport")
|
||||
public int publicPort;
|
||||
private String state;
|
||||
|
@ -143,7 +164,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
@SerializedName("publicendport")
|
||||
private int publicEndPort;
|
||||
|
||||
public PortForwardingRule(long id, String iPAddress, long iPAddressId, int privatePort, String protocol,
|
||||
public PortForwardingRule(long id, String iPAddress, long iPAddressId, int privatePort, Protocol protocol,
|
||||
int publicPort, String state, String virtualMachineDisplayName, long virtualMachineId,
|
||||
String virtualMachineName, Set<String> CIDRs, int privateEndPort, int publicEndPort) {
|
||||
this.id = id;
|
||||
|
@ -197,7 +218,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
/**
|
||||
* @return the protocol of the port forwarding rule
|
||||
*/
|
||||
public String getProtocol() {
|
||||
public Protocol getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
|
@ -324,20 +345,20 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "PortForwardingRule{" +
|
||||
"id=" + id +
|
||||
", IPAddress='" + IPAddress + '\'' +
|
||||
", IPAddressId=" + IPAddressId +
|
||||
", privatePort=" + privatePort +
|
||||
", protocol='" + protocol + '\'' +
|
||||
", publicPort=" + publicPort +
|
||||
", state='" + state + '\'' +
|
||||
", virtualMachineDisplayName='" + virtualMachineDisplayName + '\'' +
|
||||
", virtualMachineId=" + virtualMachineId +
|
||||
", virtualMachineName='" + virtualMachineName + '\'' +
|
||||
", CIDRs=" + getCIDRs() +
|
||||
", privateEndPort=" + privateEndPort +
|
||||
", publicEndPort=" + publicEndPort +
|
||||
'}';
|
||||
"id=" + id +
|
||||
", IPAddress='" + IPAddress + '\'' +
|
||||
", IPAddressId=" + IPAddressId +
|
||||
", privatePort=" + privatePort +
|
||||
", protocol='" + protocol + '\'' +
|
||||
", publicPort=" + publicPort +
|
||||
", state='" + state + '\'' +
|
||||
", virtualMachineDisplayName='" + virtualMachineDisplayName + '\'' +
|
||||
", virtualMachineId=" + virtualMachineId +
|
||||
", virtualMachineName='" + virtualMachineName + '\'' +
|
||||
", CIDRs=" + getCIDRs() +
|
||||
", privateEndPort=" + privateEndPort +
|
||||
", publicEndPort=" + publicEndPort +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public interface FirewallAsyncClient {
|
|||
@Unwrap
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<AsyncCreateResponse> createPortForwardingRuleForVirtualMachine(
|
||||
@QueryParam("ipaddressid") long ipAddressId, @QueryParam("protocol") String protocol,
|
||||
@QueryParam("ipaddressid") long ipAddressId, @QueryParam("protocol") PortForwardingRule.Protocol protocol,
|
||||
@QueryParam("publicport") int publicPort, @QueryParam("virtualmachineid") long virtualMachineId,
|
||||
@QueryParam("privateport") int privatePort);
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public interface FirewallClient {
|
|||
* @return response used to track creation
|
||||
*/
|
||||
AsyncCreateResponse createPortForwardingRuleForVirtualMachine(long ipAddressId,
|
||||
String protocol, int publicPort, long virtualMachineId, int privatePort);
|
||||
PortForwardingRule.Protocol protocol, int publicPort, long virtualMachineId, int privatePort);
|
||||
|
||||
/**
|
||||
* Deletes an port forwarding rule
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
|
|||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.cloudstack.domain.PortForwardingRule;
|
||||
import org.jclouds.cloudstack.options.ListPortForwardingRulesOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
|
@ -82,12 +83,12 @@ public class FirewallAsyncClientTest extends BaseCloudStackAsyncClientTest<Firew
|
|||
public void testCreatePortForwardingRuleForVirtualMachine() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = FirewallAsyncClient.class.getMethod("createPortForwardingRuleForVirtualMachine", long.class,
|
||||
long.class, String.class, int.class, int.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 6, 7, "tcp", 22, 22);
|
||||
PortForwardingRule.Protocol.class, int.class, long.class, int.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 6L, PortForwardingRule.Protocol.TCP, 22, 7L, 22);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=createPortForwardingRule&virtualmachineid=6&protocol=tcp&ipaddressid=7&privateport=22&publicport=22 HTTP/1.1");
|
||||
"GET http://localhost:8080/client/api?response=json&command=createPortForwardingRule&ipaddressid=6&publicport=22&protocol=tcp&virtualmachineid=7&privateport=22 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
|
|
@ -199,9 +199,9 @@ public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest
|
|||
|
||||
assertEquals(client.listPortForwardingRules(),
|
||||
ImmutableSet.<PortForwardingRule>of(
|
||||
PortForwardingRule.builder().id(15).privatePort(22).protocol("tcp").publicPort(2022).virtualMachineId(3)
|
||||
PortForwardingRule.builder().id(15).privatePort(22).protocol(PortForwardingRule.Protocol.TCP).publicPort(2022).virtualMachineId(3)
|
||||
.virtualMachineName("i-3-3-VM").IPAddressId(3).IPAddress("72.52.126.32").state("Active").CIDRs(cidrs).build(),
|
||||
PortForwardingRule.builder().id(18).privatePort(22).protocol("tcp").publicPort(22).virtualMachineId(89)
|
||||
PortForwardingRule.builder().id(18).privatePort(22).protocol(PortForwardingRule.Protocol.TCP).publicPort(22).virtualMachineId(89)
|
||||
.virtualMachineName("i-3-89-VM").IPAddressId(34).IPAddress("72.52.126.63").state("Active").build())
|
||||
);
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest
|
|||
Set<String> cidrs = ImmutableSet.of("0.0.0.0/1", "128.0.0.0/1");
|
||||
|
||||
assertEquals(client.getPortForwardingRule(15),
|
||||
PortForwardingRule.builder().id(15).privatePort(22).protocol("tcp").publicPort(2022).virtualMachineId(3)
|
||||
PortForwardingRule.builder().id(15).privatePort(22).protocol(PortForwardingRule.Protocol.TCP).publicPort(2022).virtualMachineId(3)
|
||||
.virtualMachineName("i-3-3-VM").IPAddressId(3).IPAddress("72.52.126.32").state("Active").CIDRs(cidrs).build());
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,8 @@ public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest
|
|||
.build())
|
||||
.getFirewallClient();
|
||||
|
||||
AsyncCreateResponse response = client.createPortForwardingRuleForVirtualMachine(2, "tcp", 22, 1234, 22);
|
||||
AsyncCreateResponse response = client.createPortForwardingRuleForVirtualMachine(
|
||||
2, PortForwardingRule.Protocol.TCP, 22, 1234, 22);
|
||||
assertEquals(response.getJobId(), 2035);
|
||||
assertEquals(response.getId(), 2015);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
ip = reuseOrAssociate.apply(network);
|
||||
try {
|
||||
AsyncCreateResponse job = client.getFirewallClient()
|
||||
.createPortForwardingRuleForVirtualMachine(ip.getId(), "tcp", 22, vm.getId(), 22);
|
||||
.createPortForwardingRuleForVirtualMachine(ip.getId(), PortForwardingRule.Protocol.TCP, 22, vm.getId(), 22);
|
||||
assertTrue(jobComplete.apply(job.getJobId()));
|
||||
portForwardingRule = client.getFirewallClient().getPortForwardingRule(job.getId());
|
||||
|
||||
|
|
|
@ -61,9 +61,9 @@ public class ListPortForwardingRulesResponseTest extends BaseSetParserTest<PortF
|
|||
public Set<PortForwardingRule> expected() {
|
||||
Set<String> cidrs = ImmutableSet.of("0.0.0.0/1", "128.0.0.0/1");
|
||||
return ImmutableSet.<PortForwardingRule> of(
|
||||
PortForwardingRule.builder().id(15).privatePort(22).protocol("tcp").publicPort(2022).virtualMachineId(3)
|
||||
PortForwardingRule.builder().id(15).privatePort(22).protocol(PortForwardingRule.Protocol.TCP).publicPort(2022).virtualMachineId(3)
|
||||
.virtualMachineName("i-3-3-VM").IPAddressId(3).IPAddress("72.52.126.32").state("Active").CIDRs(cidrs).build(),
|
||||
PortForwardingRule.builder().id(18).privatePort(22).protocol("tcp").publicPort(22).virtualMachineId(89)
|
||||
PortForwardingRule.builder().id(18).privatePort(22).protocol(PortForwardingRule.Protocol.TCP).publicPort(22).virtualMachineId(89)
|
||||
.virtualMachineName("i-3-89-VM").IPAddressId(34).IPAddress("72.52.126.63").state("Active").build());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue