mirror of https://github.com/apache/jclouds.git
Issue 27: stopped setting availability zone state as an enum, as it isn't required to be by spec
This commit is contained in:
parent
41e3ec6709
commit
23c9bbe33c
|
@ -33,28 +33,12 @@ import com.google.common.collect.Sets;
|
||||||
*/
|
*/
|
||||||
public class AvailabilityZoneInfo implements Comparable<AvailabilityZoneInfo>{
|
public class AvailabilityZoneInfo implements Comparable<AvailabilityZoneInfo>{
|
||||||
|
|
||||||
public static enum State {
|
|
||||||
UNKNOWN, AVAILABLE;
|
|
||||||
public String value() {
|
|
||||||
return name().toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static State fromValue(String state) {
|
|
||||||
return valueOf(checkNotNull(state, "state").toUpperCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String zone;
|
private final String zone;
|
||||||
private final State state;
|
private final String state;
|
||||||
private final String region;
|
private final String region;
|
||||||
private final Set<String> messages = Sets.newHashSet();
|
private final Set<String> messages = Sets.newHashSet();
|
||||||
|
|
||||||
public AvailabilityZoneInfo(String zone, State zoneState,
|
public AvailabilityZoneInfo(String zone, String zoneState,
|
||||||
String region, Iterable<String> messages) {
|
String region, Iterable<String> messages) {
|
||||||
this.zone = checkNotNull(zone, "zone");
|
this.zone = checkNotNull(zone, "zone");
|
||||||
this.state = checkNotNull(zoneState, "zoneState");
|
this.state = checkNotNull(zoneState, "zoneState");
|
||||||
|
@ -72,7 +56,7 @@ public class AvailabilityZoneInfo implements Comparable<AvailabilityZoneInfo>{
|
||||||
/**
|
/**
|
||||||
* State of the Availability Zone.
|
* State of the Availability Zone.
|
||||||
*/
|
*/
|
||||||
public State getState() {
|
public String getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.Set;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
|
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
|
||||||
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo.State;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
@ -43,7 +42,7 @@ public class DescribeAvailabilityZonesResponseHandler extends
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private String region;
|
private String region;
|
||||||
private State zoneState;
|
private String zoneState;
|
||||||
private boolean inMessageSet;
|
private boolean inMessageSet;
|
||||||
private Set<String> messages = Sets.newHashSet();
|
private Set<String> messages = Sets.newHashSet();
|
||||||
|
|
||||||
|
@ -68,19 +67,13 @@ public class DescribeAvailabilityZonesResponseHandler extends
|
||||||
region = "UNKNOWN";
|
region = "UNKNOWN";
|
||||||
}
|
}
|
||||||
} else if (qName.equals("zoneState")) {
|
} else if (qName.equals("zoneState")) {
|
||||||
try {
|
zoneState = currentText.toString().trim();
|
||||||
zoneState = AvailabilityZoneInfo.State.fromValue(currentText.toString().trim());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
logger.warn(e, "unsupported zoneState: %s", currentText.toString().trim());
|
|
||||||
zoneState = AvailabilityZoneInfo.State.UNKNOWN;
|
|
||||||
}
|
|
||||||
} else if (qName.equals("message")) {
|
} else if (qName.equals("message")) {
|
||||||
messages.add(currentText.toString().trim());
|
messages.add(currentText.toString().trim());
|
||||||
} else if (qName.equals("messageSet")) {
|
} else if (qName.equals("messageSet")) {
|
||||||
inMessageSet = false;
|
inMessageSet = false;
|
||||||
} else if (qName.equals("item") && !inMessageSet) {
|
} else if (qName.equals("item") && !inMessageSet) {
|
||||||
availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region,
|
availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region, messages));
|
||||||
messages));
|
|
||||||
this.zone = null;
|
this.zone = null;
|
||||||
this.region = null;
|
this.region = null;
|
||||||
this.zoneState = null;
|
this.zoneState = null;
|
||||||
|
|
|
@ -45,20 +45,15 @@ public class DescribeAvailabilityZonesResponseHandlerTest extends BaseHandlerTes
|
||||||
|
|
||||||
Set<AvailabilityZoneInfo> expected = ImmutableSet.<AvailabilityZoneInfo> of(
|
Set<AvailabilityZoneInfo> expected = ImmutableSet.<AvailabilityZoneInfo> of(
|
||||||
|
|
||||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1A,
|
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1A, "available", Region.US_EAST_1,
|
||||||
AvailabilityZoneInfo.State.AVAILABLE, Region.US_EAST_1, ImmutableSet
|
ImmutableSet.<String> of()), new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1B,
|
||||||
.<String> of()),
|
"available", Region.US_EAST_1, ImmutableSet.<String> of()),
|
||||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1B,
|
|
||||||
AvailabilityZoneInfo.State.AVAILABLE,
|
|
||||||
Region.US_EAST_1, ImmutableSet.<String> of()),
|
|
||||||
|
|
||||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1C,
|
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1C, "available", Region.US_EAST_1,
|
||||||
AvailabilityZoneInfo.State.AVAILABLE, Region.US_EAST_1, ImmutableSet
|
ImmutableSet.<String> of("our service is awesome")),
|
||||||
.<String> of("our service is awesome")),
|
|
||||||
|
|
||||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1D,
|
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1D, "downlikeaclown", Region.US_EAST_1,
|
||||||
AvailabilityZoneInfo.State.UNKNOWN, Region.US_EAST_1, ImmutableSet
|
ImmutableSet.<String> of()));
|
||||||
.<String> of()));
|
|
||||||
Set<AvailabilityZoneInfo> result = factory.create(
|
Set<AvailabilityZoneInfo> result = factory.create(
|
||||||
injector.getInstance(DescribeAvailabilityZonesResponseHandler.class)).parse(is);
|
injector.getInstance(DescribeAvailabilityZonesResponseHandler.class)).parse(is);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue