mirror of https://github.com/apache/jclouds.git
Use enum for *Rule.state
This commit is contained in:
parent
b5bba81d05
commit
3af4d3a5bb
|
@ -90,7 +90,7 @@ public class CloudStackParserModule extends AbstractModule {
|
|||
private PortForwardingRule.Protocol protocol;
|
||||
@SerializedName("publicport")
|
||||
public int publicPort;
|
||||
private String state;
|
||||
private PortForwardingRule.State state;
|
||||
@SerializedName("virtualmachinedisplayname")
|
||||
private String virtualMachineDisplayName;
|
||||
@SerializedName("virtualmachineid")
|
||||
|
@ -148,7 +148,7 @@ public class CloudStackParserModule extends AbstractModule {
|
|||
@SerializedName("ipaddressid")
|
||||
private long ipAddressId;
|
||||
private FirewallRule.Protocol protocol;
|
||||
private String state;
|
||||
private FirewallRule.State state;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.omg.PortableInterceptor.ACTIVE;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -48,6 +50,29 @@ public class FirewallRule implements Comparable<FirewallRule> {
|
|||
}
|
||||
}
|
||||
|
||||
public static enum State {
|
||||
STAGED, // Rule been created but has never got through network rule conflict detection.
|
||||
// Rules in this state can not be sent to network elements.
|
||||
ADD, // Add means the rule has been created and has gone through network rule conflict detection.
|
||||
ACTIVE, // Rule has been sent to the network elements and reported to be active.
|
||||
DELETEING, // Revoke means this rule has been revoked. If this rule has been sent to the
|
||||
// network elements, the rule will be deleted from database.
|
||||
UNKNOWN;
|
||||
|
||||
public static State fromValue(String value) {
|
||||
try {
|
||||
return valueOf(value.toUpperCase());
|
||||
} catch(IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
@ -66,7 +91,7 @@ public class FirewallRule implements Comparable<FirewallRule> {
|
|||
private long ipAddressId;
|
||||
|
||||
private Protocol protocol;
|
||||
private String state;
|
||||
private State state;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
|
@ -113,7 +138,7 @@ public class FirewallRule implements Comparable<FirewallRule> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder state(String state) {
|
||||
public Builder state(State state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
@ -140,11 +165,11 @@ public class FirewallRule implements Comparable<FirewallRule> {
|
|||
@SerializedName("ipaddressid")
|
||||
private long ipAddressId;
|
||||
private Protocol protocol;
|
||||
private String state;
|
||||
private State state;
|
||||
|
||||
public FirewallRule(long id, Set<String> CIDRs, int startPort, int endPort,
|
||||
String icmpCode, String icmpType, String ipAddress, long ipAddressId,
|
||||
Protocol protocol, String state) {
|
||||
Protocol protocol, State state) {
|
||||
this.id = id;
|
||||
this.CIDRs = ImmutableSet.copyOf(CIDRs);
|
||||
this.startPort = startPort;
|
||||
|
@ -198,7 +223,7 @@ public class FirewallRule implements Comparable<FirewallRule> {
|
|||
return protocol;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.cloudstack.domain;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
@ -48,6 +49,29 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
}
|
||||
}
|
||||
|
||||
public static enum State {
|
||||
STAGED, // Rule been created but has never got through network rule conflict detection.
|
||||
// Rules in this state can not be sent to network elements.
|
||||
ADD, // Add means the rule has been created and has gone through network rule conflict detection.
|
||||
ACTIVE, // Rule has been sent to the network elements and reported to be active.
|
||||
DELETEING, // Revoke means this rule has been revoked. If this rule has been sent to the
|
||||
// network elements, the rule will be deleted from database.
|
||||
UNKNOWN;
|
||||
|
||||
public static State fromValue(String value) {
|
||||
try {
|
||||
return valueOf(value.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
@ -59,7 +83,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
private int privatePort;
|
||||
private Protocol protocol;
|
||||
public int publicPort;
|
||||
private String state;
|
||||
private State state;
|
||||
private String virtualMachineDisplayName;
|
||||
public long virtualMachineId;
|
||||
private String virtualMachineName;
|
||||
|
@ -97,7 +121,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder state(String state) {
|
||||
public Builder state(State state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
@ -148,7 +172,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
private Protocol protocol;
|
||||
@SerializedName("publicport")
|
||||
public int publicPort;
|
||||
private String state;
|
||||
private State state;
|
||||
@SerializedName("virtualmachinedisplayname")
|
||||
private String virtualMachineDisplayName;
|
||||
@SerializedName("virtualmachineid")
|
||||
|
@ -163,7 +187,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
private int publicEndPort;
|
||||
|
||||
public PortForwardingRule(long id, String iPAddress, long iPAddressId, int privatePort, Protocol protocol,
|
||||
int publicPort, String state, String virtualMachineDisplayName, long virtualMachineId,
|
||||
int publicPort, State state, String virtualMachineDisplayName, long virtualMachineId,
|
||||
String virtualMachineName, Set<String> CIDRs, int privateEndPort, int publicEndPort) {
|
||||
this.id = id;
|
||||
this.IPAddress = iPAddress;
|
||||
|
@ -230,7 +254,7 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
|||
/**
|
||||
* @return the state of the rule
|
||||
*/
|
||||
public String getState() {
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,11 +66,14 @@ public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest
|
|||
assertEquals(client.listFirewallRules(),
|
||||
ImmutableSet.of(
|
||||
FirewallRule.builder().id(2017).protocol(FirewallRule.Protocol.TCP).startPort(30)
|
||||
.endPort(35).ipAddressId(2).ipAddress("10.27.27.51").state("Active").CIDRs(CIDRs).build(),
|
||||
.endPort(35).ipAddressId(2).ipAddress("10.27.27.51").state(FirewallRule.State.ACTIVE)
|
||||
.CIDRs(CIDRs).build(),
|
||||
FirewallRule.builder().id(2016).protocol(FirewallRule.Protocol.TCP).startPort(22)
|
||||
.endPort(22).ipAddressId(2).ipAddress("10.27.27.51").state("Active").CIDRs(CIDRs).build(),
|
||||
.endPort(22).ipAddressId(2).ipAddress("10.27.27.51").state(FirewallRule.State.ACTIVE)
|
||||
.CIDRs(CIDRs).build(),
|
||||
FirewallRule.builder().id(10).protocol(FirewallRule.Protocol.TCP).startPort(22)
|
||||
.endPort(22).ipAddressId(8).ipAddress("10.27.27.57").state("Active").CIDRs(CIDRs).build()
|
||||
.endPort(22).ipAddressId(8).ipAddress("10.27.27.57").state(FirewallRule.State.ACTIVE)
|
||||
.CIDRs(CIDRs).build()
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -114,7 +117,7 @@ public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest
|
|||
|
||||
assertEquals(client.getFirewallRule(2017),
|
||||
FirewallRule.builder().id(2017).protocol(FirewallRule.Protocol.TCP).startPort(30)
|
||||
.endPort(35).ipAddressId(2).ipAddress("10.27.27.51").state("Active")
|
||||
.endPort(35).ipAddressId(2).ipAddress("10.27.27.51").state(FirewallRule.State.ACTIVE)
|
||||
.CIDRs(ImmutableSet.of("0.0.0.0/0")).build()
|
||||
);
|
||||
}
|
||||
|
@ -201,10 +204,12 @@ public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest
|
|||
|
||||
assertEquals(client.listPortForwardingRules(),
|
||||
ImmutableSet.<PortForwardingRule>of(
|
||||
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(PortForwardingRule.Protocol.TCP).publicPort(22).virtualMachineId(89)
|
||||
.virtualMachineName("i-3-89-VM").IPAddressId(34).IPAddress("72.52.126.63").state("Active").build())
|
||||
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(PortForwardingRule.State.ACTIVE).CIDRs(cidrs).build(),
|
||||
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(PortForwardingRule.State.ACTIVE).build())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -249,8 +254,9 @@ 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(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(15).privatePort(22).protocol(PortForwardingRule.Protocol.TCP)
|
||||
.publicPort(2022).virtualMachineId(3).virtualMachineName("i-3-3-VM").IPAddressId(3)
|
||||
.IPAddress("72.52.126.32").state(PortForwardingRule.State.ACTIVE).CIDRs(cidrs).build());
|
||||
}
|
||||
|
||||
public void testGetPortForwardingRuleWhenResponseIs404() {
|
||||
|
|
|
@ -61,11 +61,11 @@ public class ListFirewallRulesResponseTest extends BaseSetParserTest<FirewallRul
|
|||
Set<String> CIDRs = ImmutableSet.of("0.0.0.0/0");
|
||||
return ImmutableSet.of(
|
||||
FirewallRule.builder().id(2017).protocol(FirewallRule.Protocol.TCP).startPort(30)
|
||||
.endPort(35).ipAddressId(2).ipAddress("10.27.27.51").state("Active").CIDRs(CIDRs).build(),
|
||||
.endPort(35).ipAddressId(2).ipAddress("10.27.27.51").state(FirewallRule.State.ACTIVE).CIDRs(CIDRs).build(),
|
||||
FirewallRule.builder().id(2016).protocol(FirewallRule.Protocol.TCP).startPort(22)
|
||||
.endPort(22).ipAddressId(2).ipAddress("10.27.27.51").state("Active").CIDRs(CIDRs).build(),
|
||||
.endPort(22).ipAddressId(2).ipAddress("10.27.27.51").state(FirewallRule.State.ACTIVE).CIDRs(CIDRs).build(),
|
||||
FirewallRule.builder().id(10).protocol(FirewallRule.Protocol.TCP).startPort(22)
|
||||
.endPort(22).ipAddressId(8).ipAddress("10.27.27.57").state("Active").CIDRs(CIDRs).build()
|
||||
.endPort(22).ipAddressId(8).ipAddress("10.27.27.57").state(FirewallRule.State.ACTIVE).CIDRs(CIDRs).build()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,10 +61,12 @@ 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(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(PortForwardingRule.Protocol.TCP).publicPort(22).virtualMachineId(89)
|
||||
.virtualMachineName("i-3-89-VM").IPAddressId(34).IPAddress("72.52.126.63").state("Active").build());
|
||||
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(PortForwardingRule.State.ACTIVE).CIDRs(cidrs).build(),
|
||||
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(PortForwardingRule.State.ACTIVE).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue