Permalink
Browse files

Use new EC2 Galaxy location format

  • Loading branch information...
1 parent bd0445b commit d167e29986ff49432fb58a7da05b48c5cfb6bb98 @electrum committed Apr 17, 2012
@@ -27,22 +27,24 @@
import static com.google.common.base.Preconditions.checkNotNull;
/**
- * EC2 Galaxy location: {@code /ec2/region/zone/instance/slot}
+ * EC2 Galaxy location: {@code /ec2/region/zone/instance/agent/installation}
*/
@Immutable
public class Ec2Location
{
private final String region;
private final String availabilityZone;
private final String instanceId;
- private final String slot;
+ private final String agent;
+ private final String installation;
- public Ec2Location(String region, String availabilityZone, String instanceId, String slot)
+ public Ec2Location(String region, String availabilityZone, String instanceId, String agent, String installation)
{
this.region = checkNotNull(region, "region is null");
this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone is null");
this.instanceId = checkNotNull(instanceId, "instanceId is null");
- this.slot = checkNotNull(slot, "slot is null");
+ this.agent = checkNotNull(agent, "agent is null");
+ this.installation = checkNotNull(installation, "installation is null");
}
public String getRegion()
@@ -60,9 +62,14 @@ public String getInstanceId()
return instanceId;
}
- public String getSlot()
+ public String getAgent()
{
- return slot;
+ return agent;
+ }
+
+ public String getInstallation()
+ {
+ return installation;
}
@Override
@@ -78,19 +85,20 @@ public boolean equals(Object o)
return equal(region, x.region) &&
equal(availabilityZone, x.availabilityZone) &&
equal(instanceId, x.instanceId) &&
- equal(slot, x.slot);
+ equal(agent, x.agent) &&
+ equal(installation, x.installation);
}
@Override
public int hashCode()
{
- return Objects.hashCode(region, availabilityZone, instanceId, slot);
+ return Objects.hashCode(region, availabilityZone, instanceId, agent, installation);
}
@Override
public String toString()
{
- return Joiner.on('/').join("ec2", region, availabilityZone, instanceId, slot);
+ return Joiner.on('/').join("ec2", region, availabilityZone, instanceId, agent, installation);
}
/**
@@ -111,9 +119,9 @@ public static Ec2Location valueOf(String location)
if (!parts.get(0).equals("ec2")) {
throw new IllegalArgumentException("not an EC2 location");
}
- if (parts.size() != 5) {
+ if (parts.size() != 6) {
throw new IllegalArgumentException("wrong number of parts");
}
- return new Ec2Location(parts.get(1), parts.get(2), parts.get(3), parts.get(4));
+ return new Ec2Location(parts.get(1), parts.get(2), parts.get(3), parts.get(4), parts.get(5));
}
}
@@ -24,11 +24,12 @@
@Test
public void testParseLocation()
{
- Ec2Location location = Ec2Location.valueOf("/ec2/us-east-1/us-east-1a/i-3ea74257/discovery");
+ Ec2Location location = Ec2Location.valueOf("/ec2/us-east-1/us-east-1a/i-3ea74257/agent/discovery");
assertEquals(location.getRegion(), "us-east-1");
assertEquals(location.getAvailabilityZone(), "us-east-1a");
assertEquals(location.getInstanceId(), "i-3ea74257");
- assertEquals(location.getSlot(), "discovery");
+ assertEquals(location.getAgent(), "agent");
+ assertEquals(location.getInstallation(), "discovery");
}
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "location must start with a slash")
@@ -46,12 +47,12 @@ public void testNonEc2Location()
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "wrong number of parts")
public void testTooFewParts()
{
- Ec2Location.valueOf("/ec2/abc/xyz/123");
+ Ec2Location.valueOf("/ec2/region/zone/instance/agent");
}
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "wrong number of parts")
public void testTooManyParts()
{
- Ec2Location.valueOf("/ec2/abc/xyz/123/foo/bar");
+ Ec2Location.valueOf("/ec2/region/zone/instance/agent/installation/extra");
}
}

0 comments on commit d167e29

Please sign in to comment.