From c4d93cc28d1f60c8b1c0da528a5c5be5fa73ec10 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Thu, 7 Nov 2019 11:19:34 +0100 Subject: Add FlagTarget interface with controller and configserver impls --- .../systemflags/v1/ConfigserverFlagsTarget.java | 51 ++++++++++++++++ .../api/systemflags/v1/ControllerFlagsTarget.java | 38 ++++++++++++ .../controller/api/systemflags/v1/FlagsTarget.java | 68 ++++++++++++++++++++++ .../api/systemflags/v1/package-info.java | 8 +++ 4 files changed, 165 insertions(+) create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ConfigserverFlagsTarget.java create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/ControllerFlagsTarget.java create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/FlagsTarget.java create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/systemflags/v1/package-info.java (limited to 'controller-api') 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 flagDataFilesPrioritized() { return List.of(zoneFile(system, zone), environmentFile(system, zone.environment()), systemFile(system), defaultFile()); } + @Override public URI endpoint() { return endpoint; } + @Override public Optional 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 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 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: + *
    + *
  • zone specific: {@code ...json}
  • + *
  • controller specific: {@code .controller.json}
  • + *
  • environment specific: {@code ..json}
  • + *
  • system specific: {@code .json}
  • + *
  • global default: {@code default.json}
  • + *
+ * + * @author bjorncs + */ +public interface FlagsTarget { + + List flagDataFilesPrioritized(); + URI endpoint(); + Optional athenzHttpsIdentity(); + String asString(); + + static Set getAllTargetsInSystem(ZoneRegistry registry) { + SystemName system = registry.system(); + Set 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 -- cgit v1.2.3