diff options
author | Morten Tokle <mortent@oath.com> | 2017-11-22 13:44:48 +0100 |
---|---|---|
committer | Morten Tokle <mortent@oath.com> | 2017-11-22 13:44:48 +0100 |
commit | 4fa8521f1d23a64c0c0bc1b8fb11c1be7a7c3762 (patch) | |
tree | 02c33d68d7c6c209643e57249b4bb71bc47f88d5 /config-model/src/main/java/com/yahoo | |
parent | 28f6fb192d3ba9d019fa9265b2770cc4325d5240 (diff) |
Move deployment spec ContainerCluster -> ContainerModelBuilder
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
3 files changed, 80 insertions, 93 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java index 1e9dc569ff5..4383e55e45d 100755 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java @@ -9,15 +9,10 @@ import com.yahoo.component.ComponentSpecification; import com.yahoo.config.FileReference; import com.yahoo.config.application.api.ApplicationMetaData; import com.yahoo.config.application.api.ComponentInfo; -import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.docproc.DocprocConfig; import com.yahoo.config.docproc.SchemamappingConfig; import com.yahoo.config.model.ApplicationConfigProducerRoot; -import com.yahoo.config.model.api.ConfigServerSpec; import com.yahoo.config.model.producer.AbstractConfigProducer; -import com.yahoo.config.model.producer.AbstractConfigProducerRoot; -import com.yahoo.config.provision.HostName; -import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.Zone; import com.yahoo.container.BundlesConfig; import com.yahoo.container.ComponentsConfig; @@ -87,7 +82,6 @@ import com.yahoo.vespaclient.config.FeederConfig; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import java.io.Reader; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -234,7 +228,6 @@ public final class ContainerCluster addSimpleComponent("com.yahoo.container.core.slobrok.SlobrokConfigurator"); addSimpleComponent("com.yahoo.container.handler.VipStatus"); addJaxProviders(); - addIdentity(); } public void setZone(Zone zone) { @@ -307,36 +300,6 @@ public final class ContainerCluster addSimpleComponent(XPathFactoryProvider.class); } - public void addIdentity() { - getDeploymentSpec().ifPresent(deploymentSpec -> { - deploymentSpec.athenzDomain().ifPresent(domain -> { - - String service = deploymentSpec.athenzService(zone.environment(), zone.region()) - .orElseThrow(() -> new RuntimeException("Missing Athenz service configuration")); - - Identity identity = new Identity(domain.trim(), service.trim(), getLoadBalancerName()); - addComponent(identity); - - getContainers().forEach(container -> { - container.setProp("identity.domain", domain); - container.setProp("identity.service", service); - }); - }); - }); - } - - private HostName getLoadBalancerName() { - // Set lbaddress, or use first hostname if not specified. - // TODO: Remove the orElseGet part when this is set up in all zones - return Optional.ofNullable(getRoot().getDeployState().getProperties().loadBalancerName()) - .orElseGet( - () -> HostName.from(getRoot().getDeployState().getProperties().configServerSpecs().stream() - .findFirst() - .map(ConfigServerSpec::getHostName) - .orElse("unknown") // Currently unable to test this, hence the unknown - )); - } - public final void addComponent(Component<?, ?> component) { if (clusterVerifier.acceptComponent(component)) { componentGroup.addComponent(component); @@ -415,8 +378,6 @@ public final class ContainerCluster container.setClusterName(name); container.setProp("clustername", name) .setProp("index", this.containers.size()); - setRotations(container, getRotations(), getGlobalServiceId(), name); - container.setProp("activeRotation", Boolean.toString(getActiveRotation())); containers.add(container); } @@ -426,55 +387,6 @@ public final class ContainerCluster } } - private Optional<String> getGlobalServiceId() { - Optional<DeploymentSpec> deploymentSpec = getDeploymentSpec(); - if (deploymentSpec.isPresent()) return deploymentSpec.get().globalServiceId(); - return Optional.empty(); - } - - private Set<Rotation> getRotations() { - return Optional.ofNullable(getRoot()) - .map(root -> root.getDeployState().getRotations()) - .orElse(Collections.emptySet()); - } - - private boolean getActiveRotation() { - return Optional.ofNullable(getRoot()) - .map(root -> root.getDeployState().getProperties().zone()) - .map(this::zoneHasActiveRotation) - .orElse(false); - } - - private boolean zoneHasActiveRotation(Zone zone) { - Optional<DeploymentSpec> spec = getDeploymentSpec(); - if (!spec.isPresent()) { - return false; - } - return spec.get().zones().stream() - .anyMatch(declaredZone -> declaredZone.deploysTo(zone.environment(), Optional.of(zone.region())) && - declaredZone.active()); - } - - private Optional<DeploymentSpec> getDeploymentSpec() { - Optional<DeploymentSpec> deploymentSpec = Optional.empty(); - AbstractConfigProducerRoot root = getRoot(); - if (root != null) { - final Optional<Reader> deployment = root.getDeployState().getApplicationPackage().getDeployment(); - if (deployment.isPresent()) { - deploymentSpec = Optional.of(DeploymentSpec.fromXml(deployment.get())); - } - } - return deploymentSpec; - } - - private void setRotations(Container container, Set<Rotation> rotations, Optional<String> globalServiceId, String containerClusterName) { - if ( ! rotations.isEmpty() && globalServiceId.isPresent()) { - if (containerClusterName.equals(globalServiceId.get())) { - container.setProp("rotations", rotations.stream().map(Rotation::getId).collect(Collectors.joining(","))); - } - } - } - public void setProcessingChains(ProcessingChains processingChains, String... serverBindings) { if (this.processingChains != null) throw new IllegalStateException("ProcessingChains should only be set once."); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/Identity.java b/config-model/src/main/java/com/yahoo/vespa/model/container/Identity.java index bc7a6e20361..bf5a7757149 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/Identity.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/Identity.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.container; +import com.yahoo.config.provision.AthenzDomain; +import com.yahoo.config.provision.AthenzService; import com.yahoo.config.provision.HostName; import com.yahoo.container.core.identity.IdentityConfig; import com.yahoo.container.jdisc.athenz.impl.AthenzIdentityProviderImpl; @@ -12,11 +14,11 @@ import com.yahoo.vespa.model.container.component.SimpleComponent; public class Identity extends SimpleComponent implements IdentityConfig.Producer { public static final String CLASS = AthenzIdentityProviderImpl.class.getName(); - private final String domain; - private final String service; + private final AthenzDomain domain; + private final AthenzService service; private final HostName loadBalancerName; - public Identity(String domain, String service, HostName loadBalancerName) { + public Identity(AthenzDomain domain, AthenzService service, HostName loadBalancerName) { super(CLASS); this.domain = domain; this.service = service; @@ -25,8 +27,8 @@ public class Identity extends SimpleComponent implements IdentityConfig.Producer @Override public void getConfig(IdentityConfig.Builder builder) { - builder.domain(domain); - builder.service(service); + builder.domain(domain.value()); + builder.service(service.value()); // Current interpretation of loadbalancer address is: hostname. // Config should be renamed or send the uri builder.loadBalancerAddress(loadBalancerName.value()); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 121039a248d..4dba9f923a8 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -6,16 +6,22 @@ import com.yahoo.component.Version; import com.yahoo.config.application.Xml; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.DeployLogger; +import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.model.ConfigModelContext; +import com.yahoo.config.model.api.ConfigServerSpec; import com.yahoo.config.model.application.provider.IncludeDirs; import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.builder.xml.ConfigModelId; import com.yahoo.config.model.producer.AbstractConfigProducer; +import com.yahoo.config.provision.AthenzService; import com.yahoo.config.provision.Capacity; import com.yahoo.config.provision.ClusterMembership; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.NodeType; +import com.yahoo.config.provision.Rotation; +import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.config.MetricDefaultsConfig; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.text.XML; @@ -37,6 +43,7 @@ import com.yahoo.vespa.model.clients.ContainerDocumentApi; import com.yahoo.vespa.model.container.Container; import com.yahoo.vespa.model.container.ContainerCluster; import com.yahoo.vespa.model.container.ContainerModel; +import com.yahoo.vespa.model.container.Identity; import com.yahoo.vespa.model.container.component.Component; import com.yahoo.vespa.model.container.component.FileStatusHandlerComponent; import com.yahoo.vespa.model.container.component.chain.ProcessingHandler; @@ -61,6 +68,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.function.Consumer; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -85,6 +93,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private final boolean standaloneBuilder; private final Networking networking; protected DeployLogger log; + private Optional<DeploymentSpec> deploymentSpec; public static final List<ConfigModelId> configModelIds = ImmutableList.of(ConfigModelId.fromName("container"), ConfigModelId.fromName("jdisc")); @@ -108,6 +117,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { @Override public void doBuild(ContainerModel model, Element spec, ConfigModelContext modelContext) { app = modelContext.getApplicationPackage(); + deploymentSpec = app.getDeployment().map(DeploymentSpec::fromXml); checkVersion(spec); this.log = modelContext.getDeployLogger(); @@ -162,9 +172,43 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { addServerProviders(spec, cluster); addLegacyFilters(spec, cluster); // TODO: Remove for Vespa 7 + // Athenz copper argos + // NOTE: Must be done after addNodes() + addIdentity(cluster, + context.getDeployState().getProperties().configServerSpecs(), + context.getDeployState().getProperties().loadBalancerName(), + context.getDeployState().zone()); + + addRotationInfo(cluster, context.getDeployState().zone(), context.getDeployState().getRotations()); + //TODO: overview handler, see DomQrserverClusterBuilder } + private void addRotationInfo(ContainerCluster cluster, Zone zone, Set<Rotation> rotations) { + Optional<String> globalServiceId = deploymentSpec.flatMap(DeploymentSpec::globalServiceId); + cluster.getContainers().forEach(container -> { + setRotations(container, rotations, globalServiceId, cluster.getName()); + container.setProp("activeRotation", Boolean.toString(zoneHasActiveRotation(zone))); + }); + } + + private boolean zoneHasActiveRotation(Zone zone) { + return deploymentSpec.map(DeploymentSpec::zones) + .map(List::stream) + .map(x -> x.anyMatch(declaredZone -> declaredZone.deploysTo(zone.environment(), Optional.of(zone.region())) && + declaredZone.active())) + .orElse(false); + } + + private void setRotations(Container container, Set<Rotation> rotations, Optional<String> globalServiceId, String containerClusterName) { + + if ( ! rotations.isEmpty() && globalServiceId.isPresent()) { + if (containerClusterName.equals(globalServiceId.get())) { + container.setProp("rotations", rotations.stream().map(Rotation::getId).collect(Collectors.joining(","))); + } + } + } + private void addRoutingAliases(ContainerCluster cluster, Element spec, Environment environment) { if (environment != Environment.prod) return; @@ -688,6 +732,35 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { } } + private void addIdentity(ContainerCluster cluster, List<ConfigServerSpec> configServerSpecs, HostName loadBalancerName, Zone zone) { + deploymentSpec.ifPresent(spec -> { + spec.athenzDomain().ifPresent(domain -> { + AthenzService service = spec.athenzService(zone.environment(), zone.region()) + .orElseThrow(() -> new RuntimeException("Missing Athenz service configuration")); + Identity identity = new Identity(domain, service, getLoadBalancerName(loadBalancerName, configServerSpecs)); + cluster.addComponent(identity); + + cluster.getContainers().forEach(container -> { + container.setProp("identity.domain", domain.value()); + container.setProp("identity.service", service.value()); + }); + }); + }); + } + + private HostName getLoadBalancerName(HostName loadbalancerName, List<ConfigServerSpec> configServerSpecs) { + // Set lbaddress, or use first hostname if not specified. + // TODO: Remove this method and use the loadbalancerName directly + return Optional.ofNullable(loadbalancerName) + .orElseGet( + () -> HostName.from(configServerSpecs.stream() + .findFirst() + .map(ConfigServerSpec::getHostName) + .orElse("unknown") // Currently unable to test this, hence the unknown + )); + } + + /** * Disallow renderers named "DefaultRenderer" or "JsonRenderer" */ |