diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-04-08 14:23:27 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-04-08 14:23:27 +0200 |
commit | f778fa7fe0caf463cd766b08d1fd66644191c335 (patch) | |
tree | f50625846838643b40c47390faca31c87e881cba /config-provisioning | |
parent | 6974b8557e43c118fde578e8def9a621551a6cd8 (diff) |
Move ZoneId to config-provisioning
Diffstat (limited to 'config-provisioning')
-rw-r--r-- | config-provisioning/abi-spec.json | 22 | ||||
-rw-r--r-- | config-provisioning/src/main/java/com/yahoo/config/provision/ZoneId.java | 89 |
2 files changed, 111 insertions, 0 deletions
diff --git a/config-provisioning/abi-spec.json b/config-provisioning/abi-spec.json index 6e110b708cf..d122748cd6d 100644 --- a/config-provisioning/abi-spec.json +++ b/config-provisioning/abi-spec.json @@ -762,5 +762,27 @@ "public int hashCode()" ], "fields": [] + }, + "com.yahoo.config.provision.ZoneId": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ + "public" + ], + "methods": [ + "public static com.yahoo.config.provision.ZoneId from(com.yahoo.config.provision.Environment, com.yahoo.config.provision.RegionName)", + "public static com.yahoo.config.provision.ZoneId from(java.lang.String, java.lang.String)", + "public static com.yahoo.config.provision.ZoneId from(java.lang.String)", + "public static com.yahoo.config.provision.ZoneId from(com.yahoo.config.provision.Environment, com.yahoo.config.provision.RegionName, com.yahoo.config.provision.CloudName)", + "public static com.yahoo.config.provision.ZoneId from(java.lang.String, java.lang.String, java.lang.String)", + "public com.yahoo.config.provision.Environment environment()", + "public com.yahoo.config.provision.RegionName region()", + "public com.yahoo.config.provision.CloudName cloud()", + "public java.lang.String value()", + "public java.lang.String toString()", + "public boolean equals(java.lang.Object)", + "public int hashCode()" + ], + "fields": [] } }
\ No newline at end of file diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ZoneId.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ZoneId.java new file mode 100644 index 00000000000..1954940528d --- /dev/null +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ZoneId.java @@ -0,0 +1,89 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.provision; + +import java.util.Objects; + +/** + * Unique identifier for a Zone; use when referencing them. + * + * Serialised form is 'environment.region'. + * + * @author jonmv + */ +public class ZoneId { + // TODO: Replace usages of environment + region with usages of this. + + private final Environment environment; + private final RegionName region; + private final CloudName cloud; + + private ZoneId(Environment environment, RegionName region, CloudName cloud) { + 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"); + } + + private ZoneId(Environment environment, RegionName region) { + this(environment, region, CloudName.defaultName()); + } + + public static ZoneId from(Environment environment, RegionName region) { + return new ZoneId(environment, region); + } + + public static ZoneId from(String environment, String region) { + return from(Environment.from(environment), RegionName.from(region)); + } + + /** 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]); + } + + public static ZoneId from(Environment environment, RegionName region, CloudName cloud) { + return new ZoneId(environment, region, cloud); + } + + public static ZoneId from(String environment, String region, String cloud) { + return new ZoneId(Environment.from(environment), RegionName.from(region), CloudName.from(cloud)); + } + + public Environment environment() { + return environment; + } + + public RegionName region() { + return region; + } + + public CloudName cloud() { + return cloud; + } + + /** Returns the serialised value of this. Inverse of {@code ZoneId.from(String value)}. */ + public String value() { + return environment + "." + region; + } + + @Override + public String toString() { + return "zone " + value() + " in " + cloud; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ZoneId zoneId = (ZoneId) o; + return environment == zoneId.environment && + Objects.equals(region, zoneId.region); + } + + @Override + public int hashCode() { + return Objects.hash(environment, region); + } + +} + |