summaryrefslogtreecommitdiffstats
path: root/config-provisioning
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2019-05-14 14:08:53 +0200
committerGitHub <noreply@github.com>2019-05-14 14:08:53 +0200
commit20f5d44523c606086df50382203fb2693a466c1b (patch)
tree2b79c7b5a279fd89a19a1f6c1fedff7eb629b58b /config-provisioning
parent38e69232e7483dad5110b9a2bebd753e141a5705 (diff)
parent74b966fd17049a52a0df9543720a3ab919dd9648 (diff)
Merge pull request #9395 from vespa-engine/hmusum/add-system-to-ZoneId
Add methods for creating ZoneId with system
Diffstat (limited to 'config-provisioning')
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneId.java40
-rw-r--r--config-provisioning/src/test/java/com/yahoo/config/provision/ZoneIdTest.java57
2 files changed, 92 insertions, 5 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneId.java b/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneId.java
index 7eeae10eeb8..be967c0cbfa 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneId.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneId.java
@@ -4,6 +4,7 @@ package com.yahoo.config.provision.zone;
import com.yahoo.config.provision.CloudName;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
+import com.yahoo.config.provision.SystemName;
import java.util.Objects;
@@ -17,24 +18,32 @@ import java.util.Objects;
public class ZoneId {
// TODO: Replace usages of environment + region with usages of this.
+ // TODO: Remove static factory methods not specifying cloud and system
+
private final Environment environment;
private final RegionName region;
private final CloudName cloud;
+ private final SystemName system;
- private ZoneId(Environment environment, RegionName region, CloudName cloud) {
+ private ZoneId(Environment environment, RegionName region, CloudName cloud, SystemName system) {
this.environment = Objects.requireNonNull(environment, "environment must be non-null");
this.region = Objects.requireNonNull(region, "region must be non-null");
this.cloud = Objects.requireNonNull(cloud, "cloud must be non-null");
+ this.system = Objects.requireNonNull(system, "system must be non-null");
}
private ZoneId(Environment environment, RegionName region) {
- this(environment, region, CloudName.defaultName());
+ this(environment, region, CloudName.defaultName(), SystemName.defaultSystem());
}
public static ZoneId from(Environment environment, RegionName region) {
return new ZoneId(environment, region);
}
+ public static ZoneId from(Environment environment, RegionName region, CloudName cloud, SystemName system) {
+ return new ZoneId(environment, region, cloud, system);
+ }
+
public static ZoneId from(String environment, String region) {
return from(Environment.from(environment), RegionName.from(region));
}
@@ -42,15 +51,26 @@ public class ZoneId {
/** Create from a serialised ZoneId. Inverse of {@code ZoneId.value()}. */
public static ZoneId from(String value) {
String[] parts = value.split("\\.");
- return from(parts[0], parts[1]);
+ switch (parts.length) {
+ case 2:
+ return from(parts[0], parts[1]);
+ case 4:
+ return from(parts[2], parts[3], parts[0], parts[1]);
+ default:
+ throw new IllegalArgumentException("Cannot deserialize zone id '" + value + "'");
+ }
}
public static ZoneId from(Environment environment, RegionName region, CloudName cloud) {
- return new ZoneId(environment, region, cloud);
+ return new ZoneId(environment, region, cloud, SystemName.defaultSystem());
}
public static ZoneId from(String environment, String region, String cloud) {
- return new ZoneId(Environment.from(environment), RegionName.from(region), CloudName.from(cloud));
+ return new ZoneId(Environment.from(environment), RegionName.from(region), CloudName.from(cloud), SystemName.defaultSystem());
+ }
+
+ public static ZoneId from(String environment, String region, String cloud, String system) {
+ return new ZoneId(Environment.from(environment), RegionName.from(region), CloudName.from(cloud), SystemName.from(system));
}
public Environment environment() {
@@ -65,17 +85,27 @@ public class ZoneId {
return cloud;
}
+ public SystemName system() {
+ return system;
+ }
+
/** Returns the serialised value of this. Inverse of {@code ZoneId.from(String value)}. */
public String value() {
return environment + "." + region;
+ // TODO: Change to the below when there only methods use constructor including cloud and system are used and
+ // all serialized values contain cloud and system
+ // return cloud + "." + system + "." + environment + "." + region;
}
@Override
public String toString() {
return "zone " + value() + " in " + cloud;
+ // TODO: Use the below (need to fix some use of toString() in tests first)
+ //return "zone " + cloud + "." + system + "." + environment + "." + region;
}
@Override
+ // TODO: Update to check cloud and system when everyone use methods that specify cloud and system
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/ZoneIdTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/ZoneIdTest.java
new file mode 100644
index 00000000000..a546d429291
--- /dev/null
+++ b/config-provisioning/src/test/java/com/yahoo/config/provision/ZoneIdTest.java
@@ -0,0 +1,57 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config.provision;
+
+import com.yahoo.config.provision.zone.ZoneId;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author hmusum
+ */
+public class ZoneIdTest {
+
+ private static final Environment environment = Environment.prod;
+ private static final RegionName region = RegionName.from("moon-dark-side-1");
+ private static final CloudName cloud = CloudName.from("aws");
+ private static final SystemName system = SystemName.Public;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void testCreatingZoneId() {
+ ZoneId zoneId = ZoneId.from(environment, region);
+ assertEquals(region, zoneId.region());
+ assertEquals(environment, zoneId.environment());
+ assertEquals(CloudName.defaultName(), zoneId.cloud());
+ assertEquals(SystemName.defaultSystem(), zoneId.system());
+
+ ZoneId zoneIdWithCloudAndSystem = ZoneId.from(environment, region, cloud, system);
+ assertEquals(region, zoneIdWithCloudAndSystem.region());
+ assertEquals(environment, zoneIdWithCloudAndSystem.environment());
+ assertEquals(cloud, zoneIdWithCloudAndSystem.cloud());
+ assertEquals(system, zoneIdWithCloudAndSystem.system());
+ }
+
+ @Test
+ public void testSerializingAndDeserializing() {
+ ZoneId zoneId = ZoneId.from(environment, region);
+ assertEquals(environment.value() + "." + region.value(), zoneId.value());
+ assertEquals(ZoneId.from(zoneId.value()), zoneId);
+
+ ZoneId zoneIdWithCloudAndSystem = ZoneId.from(environment, region, cloud, system);
+ assertEquals(environment.value() + "." + region.value(), zoneIdWithCloudAndSystem.value());
+ assertEquals(ZoneId.from(zoneIdWithCloudAndSystem.value()), zoneIdWithCloudAndSystem);
+ // TODO: Expect cloud and system to be part of deserialized value when the new format is supported everywhere
+ //assertEquals(cloud.value() + "." + system.name() + "." + environment.value() + "." + region.value() , zoneId.value());
+
+ String serializedZoneId = "some.illegal.value";
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Cannot deserialize zone id '" + serializedZoneId + "'");
+ ZoneId.from(serializedZoneId);
+ }
+
+}