summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/main/java/com')
-rwxr-xr-xconfig-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java55
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/IdentityProvider.java (renamed from config-model/src/main/java/com/yahoo/vespa/model/container/Identity.java)14
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java85
3 files changed, 68 insertions, 86 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 91d5b7fe267..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,13 +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.producer.AbstractConfigProducer;
-import com.yahoo.config.model.producer.AbstractConfigProducerRoot;
-import com.yahoo.config.provision.Rotation;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.BundlesConfig;
import com.yahoo.container.ComponentsConfig;
@@ -85,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;
@@ -382,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);
}
@@ -393,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/IdentityProvider.java
index bc7a6e20361..0368f7eaf3e 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/IdentityProvider.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;
@@ -9,14 +11,14 @@ import com.yahoo.vespa.model.container.component.SimpleComponent;
/**
* @author mortent
*/
-public class Identity extends SimpleComponent implements IdentityConfig.Producer {
+public class IdentityProvider 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 IdentityProvider(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 d59846cd5e2..81fc464327e 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,18 +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;
@@ -39,7 +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.IdentityProvider;
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;
@@ -64,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;
@@ -167,14 +172,42 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> {
// Athenz copper argos
// NOTE: Must be done after addNodes()
- addIdentity(spec,
- cluster,
- context.getDeployState().getProperties().configServerSpecs(),
- context.getDeployState().getProperties().loadBalancerName());
+ app.getDeployment().map(DeploymentSpec::fromXml)
+ .ifPresent(deploymentSpec -> {
+ addIdentityProvider(cluster,
+ context.getDeployState().getProperties().configServerSpecs(),
+ context.getDeployState().getProperties().loadBalancerName(),
+ context.getDeployState().zone(),
+ deploymentSpec);
+
+ addRotationProperties(cluster, context.getDeployState().zone(), context.getDeployState().getRotations(), deploymentSpec);
+ });
//TODO: overview handler, see DomQrserverClusterBuilder
}
+ private void addRotationProperties(ContainerCluster cluster, Zone zone, Set<Rotation> rotations, DeploymentSpec spec) {
+ cluster.getContainers().forEach(container -> {
+ setRotations(container, rotations, spec.globalServiceId(), cluster.getName());
+ container.setProp("activeRotation", Boolean.toString(zoneHasActiveRotation(zone, spec)));
+ });
+ }
+
+ private boolean zoneHasActiveRotation(Zone zone, DeploymentSpec spec) {
+ return spec.zones().stream()
+ .anyMatch(declaredZone -> declaredZone.deploysTo(zone.environment(), Optional.of(zone.region())) &&
+ declaredZone.active());
+ }
+
+ 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;
@@ -698,31 +731,33 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> {
}
}
- private void addIdentity(Element element, ContainerCluster cluster, List<ConfigServerSpec> configServerSpecs, HostName loadBalancerName) {
- Element identityElement = XML.getChild(element, "identity");
- if(identityElement != null) {
- String domain = XML.getValue(XML.getChild(identityElement, "domain"));
- String service = XML.getValue(XML.getChild(identityElement, "service"));
-
- // Set lbaddress, or use first hostname if not specified.
- HostName lbName = Optional.ofNullable(loadBalancerName)
- .orElseGet(
- () -> HostName.from(configServerSpecs.stream()
- .findFirst()
- .map(ConfigServerSpec::getHostName)
- .orElse("unknown") // Currently unable to test this, hence the unknown
- ));
-
- Identity identity = new Identity(domain.trim(), service.trim(), lbName);
- cluster.addComponent(identity);
+ private void addIdentityProvider(ContainerCluster cluster, List<ConfigServerSpec> configServerSpecs, HostName loadBalancerName, Zone zone, DeploymentSpec spec) {
+ spec.athenzDomain().ifPresent(domain -> {
+ AthenzService service = spec.athenzService(zone.environment(), zone.region())
+ .orElseThrow(() -> new RuntimeException("Missing Athenz service configuration"));
+ IdentityProvider identityProvider = new IdentityProvider(domain, service, getLoadBalancerName(loadBalancerName, configServerSpecs));
+ cluster.addComponent(identityProvider);
cluster.getContainers().forEach(container -> {
- container.setProp("identity.domain", domain);
- container.setProp("identity.service", service);
+ 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"
*/