diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-11-07 11:19:34 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-11-07 11:19:34 +0100 |
commit | c4d93cc28d1f60c8b1c0da528a5c5be5fa73ec10 (patch) | |
tree | 63763b1cf16006bebead6bc6e9e54767586df5bc /controller-api | |
parent | 725f1158944463c07aaa45f61dd801cf45948301 (diff) |
Add FlagTarget interface with controller and configserver impls
Diffstat (limited to 'controller-api')
4 files changed, 165 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ConfigserverFlagsTarget.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ConfigserverFlagsTarget.java new file mode 100644 index 00000000000..6863b68ba72 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ConfigserverFlagsTarget.java @@ -0,0 +1,51 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.systemflags.v1; + +import com.yahoo.config.provision.SystemName; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.athenz.api.AthenzIdentity; + +import java.net.URI; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import static com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget.defaultFile; +import static com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget.environmentFile; +import static com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget.systemFile; +import static com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget.zoneFile; + +/** + * @author bjorncs + */ +class ConfigserverFlagsTarget implements FlagsTarget { + private final SystemName system; + private final ZoneId zone; + private final URI endpoint; + private final AthenzIdentity identity; + + ConfigserverFlagsTarget(SystemName system, ZoneId zone, URI endpoint, AthenzIdentity identity) { + this.system = Objects.requireNonNull(system); + this.zone = Objects.requireNonNull(zone); + this.endpoint = Objects.requireNonNull(endpoint); + this.identity = Objects.requireNonNull(identity); + } + + @Override public List<String> flagDataFilesPrioritized() { return List.of(zoneFile(system, zone), environmentFile(system, zone.environment()), systemFile(system), defaultFile()); } + @Override public URI endpoint() { return endpoint; } + @Override public Optional<AthenzIdentity> athenzHttpsIdentity() { return Optional.of(identity); } + @Override public String asString() { return String.format("%s.%s", system.value(), zone.value()); } + + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ConfigserverFlagsTarget that = (ConfigserverFlagsTarget) o; + return system == that.system && + Objects.equals(zone, that.zone) && + Objects.equals(endpoint, that.endpoint) && + Objects.equals(identity, that.identity); + } + + @Override public int hashCode() { return Objects.hash(system, zone, endpoint, identity); } +} + diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ControllerFlagsTarget.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ControllerFlagsTarget.java new file mode 100644 index 00000000000..a22a9cc63de --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ControllerFlagsTarget.java @@ -0,0 +1,38 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.systemflags.v1; + +/** + * @author bjorncs + */ + +import com.yahoo.config.provision.SystemName; +import com.yahoo.vespa.athenz.api.AthenzIdentity; + +import java.net.URI; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import static com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget.controllerFile; +import static com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget.defaultFile; +import static com.yahoo.vespa.hosted.controller.api.systemflags.v1.FlagsTarget.systemFile; + +class ControllerFlagsTarget implements FlagsTarget { + private final SystemName system; + + ControllerFlagsTarget(SystemName system) { this.system = Objects.requireNonNull(system); } + + @Override public List<String> flagDataFilesPrioritized() { return List.of(controllerFile(system), systemFile(system), defaultFile()); } + @Override public URI endpoint() { return URI.create("https://localhost:4443/"); } // Note: Cannot use VIPs for controllers due to network configuration on AWS + @Override public Optional<AthenzIdentity> athenzHttpsIdentity() { return Optional.empty(); } + @Override public String asString() { return String.format("%s.controller", system.value()); } + + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ControllerFlagsTarget that = (ControllerFlagsTarget) o; + return system == that.system; + } + + @Override public int hashCode() { return Objects.hash(system); } +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/FlagsTarget.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/FlagsTarget.java new file mode 100644 index 00000000000..7b63cfbdcf2 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/FlagsTarget.java @@ -0,0 +1,68 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.systemflags.v1; + +import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.SystemName; +import com.yahoo.config.provision.zone.ZoneApi; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.athenz.api.AthenzIdentity; +import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +/** + * Represents either configservers in a zone or controllers in a system. + * + * Defines the location and precedence of the flags data files for the given target. + * + * Naming rules for flags data files: + * <ul> + * <li>zone specific: {@code <system>.<environment>.<region>.json}</li> + * <li>controller specific: {@code <system>.controller.json}</li> + * <li>environment specific: {@code <system>.<environment>.json}</li> + * <li>system specific: {@code <system>.json}</li> + * <li>global default: {@code default.json}</li> + * </ul> + * + * @author bjorncs + */ +public interface FlagsTarget { + + List<String> flagDataFilesPrioritized(); + URI endpoint(); + Optional<AthenzIdentity> athenzHttpsIdentity(); + String asString(); + + static Set<FlagsTarget> getAllTargetsInSystem(ZoneRegistry registry) { + SystemName system = registry.system(); + Set<FlagsTarget> targets = new HashSet<>(); + for (ZoneApi zone : registry.zones().reachable().zones()) { + targets.add(forConfigserver(registry, zone.getId())); + } + targets.add(forController(system)); + return targets; + } + + static FlagsTarget forController(SystemName systemName) { + return new ControllerFlagsTarget(systemName); + } + + static FlagsTarget forConfigserver(ZoneRegistry registry, ZoneId zoneId) { + return new ConfigserverFlagsTarget( + registry.system(), zoneId, registry.getConfigServerVipUri(zoneId), registry.getConfigServerHttpsIdentity(zoneId)); + } + + static String defaultFile() { return jsonFile("default"); } + static String systemFile(SystemName system) { return jsonFile(system.value()); } + static String environmentFile(SystemName system, Environment environment) { return jsonFile(system.value() + "." + environment); } + static String zoneFile(SystemName system, ZoneId zone) { return jsonFile(system.value() + "." + zone.environment().value() + "." + zone.region().value()); } + static String controllerFile(SystemName system) { return jsonFile(system.value() + ".controller"); } + + private static String jsonFile(String nameWithoutExtension) { return nameWithoutExtension + ".json"; } +} + + diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/package-info.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/package-info.java new file mode 100644 index 00000000000..0fe377db08c --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/package-info.java @@ -0,0 +1,8 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +/** + * @author bjorncs + */ +@ExportPackage +package com.yahoo.vespa.hosted.controller.api.systemflags.v1; + +import com.yahoo.osgi.annotation.ExportPackage;
\ No newline at end of file |