diff options
author | gjoranv <gv@yahoo-inc.com> | 2017-01-30 15:40:51 +0100 |
---|---|---|
committer | gjoranv <gv@yahoo-inc.com> | 2017-01-30 15:49:47 +0100 |
commit | a6ee706439c77d86d761898f1645ec9f82bae772 (patch) | |
tree | d7166c743704f2c820cce1cc50958432e74c9c7a /config-model/src | |
parent | 308c9f1ff7091cbfd9421b5991cb1c5dcc1f526c (diff) |
Add ApplicationType to ConfigModelContext.
Diffstat (limited to 'config-model/src')
-rw-r--r-- | config-model/src/main/java/com/yahoo/config/model/ConfigModelContext.java | 67 | ||||
-rw-r--r-- | config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java | 26 |
2 files changed, 75 insertions, 18 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/ConfigModelContext.java b/config-model/src/main/java/com/yahoo/config/model/ConfigModelContext.java index b5382b09193..ae6d4b6bf7b 100644 --- a/config-model/src/main/java/com/yahoo/config/model/ConfigModelContext.java +++ b/config-model/src/main/java/com/yahoo/config/model/ConfigModelContext.java @@ -8,6 +8,7 @@ import com.yahoo.config.model.producer.AbstractConfigProducer; import org.w3c.dom.Element; import java.util.Optional; +import java.util.stream.Stream; /** * This class contains a context that is passed to a model builder, and can be used to retrieve the application package, @@ -16,15 +17,20 @@ import java.util.Optional; * @author lulf * @since 5.1 */ -public class ConfigModelContext { +public final class ConfigModelContext { private final AbstractConfigProducer parent; private final String producerId; private final DeployState deployState; private final ConfigModelRepoAdder configModelRepoAdder; + private final ApplicationType applicationType; - private ConfigModelContext(DeployState deployState, ConfigModelRepoAdder configModelRepoAdder, - AbstractConfigProducer parent, String producerId) { + private ConfigModelContext(ApplicationType applicationType, + DeployState deployState, + ConfigModelRepoAdder configModelRepoAdder, + AbstractConfigProducer parent, + String producerId) { + this.applicationType = applicationType; this.deployState = deployState; this.configModelRepoAdder = configModelRepoAdder; this.parent = parent; @@ -36,6 +42,7 @@ public class ConfigModelContext { public AbstractConfigProducer getParentProducer() { return parent; } public DeployLogger getDeployLogger() { return deployState.getDeployLogger(); } public DeployState getDeployState() { return deployState; } + public ApplicationType getApplicationType() { return applicationType; } /** Returns write access to the config model repo, or null (only) if this is improperly initialized during testing */ public ConfigModelRepoAdder getConfigModelRepoAdder() { return configModelRepoAdder; } @@ -53,6 +60,18 @@ public class ConfigModelContext { /** * Create an application context from a parent producer and an id. * + * @param parent the parent to be used for the config model. + * @param producerId the id to be used for the config model. + * @return a model context that can be passed to a model. + */ + public static ConfigModelContext create(ConfigModelRepoAdder configModelRepoAdder, + AbstractConfigProducer parent, String producerId) { + return create(parent.getRoot().getDeployState(), configModelRepoAdder, parent, producerId); + } + + /** + * Create an application context from a parent producer and an id. + * * @param deployState the global deploy state for this model * @param parent the parent to be used for the config model * @param producerId the id to be used for the config model @@ -60,19 +79,43 @@ public class ConfigModelContext { */ public static ConfigModelContext create(DeployState deployState, ConfigModelRepoAdder configModelRepoAdder, AbstractConfigProducer parent, String producerId) { - return new ConfigModelContext(deployState, configModelRepoAdder, parent, producerId); + return new ConfigModelContext(ApplicationType.DEFAULT, deployState, configModelRepoAdder, parent, producerId); } /** - * Create an application context from a parent producer and an id. - * - * @param parent the parent to be used for the config model. - * @param producerId the id to be used for the config model. - * @return a model context that can be passed to a model. + * Create an application context from an application type, a parent producer and an id. + * + * @param applicationType the application type + * @param deployState the global deploy state for this model + * @param parent the parent to be used for the config model + * @param producerId the id to be used for the config model + * @return a model context that can be passed to a model */ - public static ConfigModelContext create(ConfigModelRepoAdder configModelRepoAdder, - AbstractConfigProducer parent, String producerId) { - return create(parent.getRoot().getDeployState(), configModelRepoAdder, parent, producerId); + public static ConfigModelContext create(ApplicationType applicationType, + DeployState deployState, + ConfigModelRepoAdder configModelRepoAdder, + AbstractConfigProducer parent, + String producerId) { + return new ConfigModelContext(applicationType, deployState, configModelRepoAdder, parent, producerId); } + public enum ApplicationType { + DEFAULT("default"), + HOSTED_INFRASTRUCTURE("hosted-infrastructure"); + + private final String type; + + ApplicationType(String type) { + this.type = type; + } + + public static ApplicationType fromString(String value) { + return Stream.of(ApplicationType.values()) + .filter(applicationType -> applicationType.type.equals(value)) + .findFirst() + .orElse(DEFAULT); + + } + + } } diff --git a/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java index d4b6751c356..fbe392f698a 100644 --- a/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java +++ b/config-model/src/main/java/com/yahoo/config/model/ConfigModelRepo.java @@ -3,6 +3,7 @@ package com.yahoo.config.model; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.application.api.ApplicationPackage; +import com.yahoo.config.model.ConfigModelContext.ApplicationType; import com.yahoo.config.model.deploy.DeployState; import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.builder.xml.ConfigModelId; @@ -90,7 +91,6 @@ public class ConfigModelRepo implements ConfigModelRepoAdder, Serializable, Iter private List<Element> getServiceElements(Element servicesRoot) { if (servicesRoot.getTagName().equals("services")) return XML.getChildren(servicesRoot); - List<Element> singleServiceList = new ArrayList<>(1); singleServiceList.add(servicesRoot); return singleServiceList; @@ -139,11 +139,17 @@ public class ConfigModelRepo implements ConfigModelRepoAdder, Serializable, Iter } for (ModelNode node : graphBuilder.build().topologicalSort()) - buildModels(node, deployState, root, model2Element.get(node.builder)); + buildModels(node, getApplicationType(servicesRoot), deployState, root, model2Element.get(node.builder)); for (ConfigModel model : configModels) model.initialize(ConfigModelRepo.this); } + private ApplicationType getApplicationType(Element servicesRoot) { + return XmlHelper.getOptionalAttribute(servicesRoot, "application-type") + .map(ApplicationType::fromString) + .orElse(ApplicationType.DEFAULT); + } + private Collection<Element> getPermanentServices(DeployState deployState) throws IOException, SAXException { List<Element> permanentServices = new ArrayList<>(); Optional<ApplicationPackage> applicationPackage = deployState.getPermanentApplicationPackage(); @@ -164,17 +170,25 @@ public class ConfigModelRepo implements ConfigModelRepoAdder, Serializable, Iter return doc.getDocumentElement(); } - private void buildModels(ModelNode node, DeployState deployState, AbstractConfigProducer parent, List<Element> elements) { + private void buildModels(ModelNode node, + ApplicationType applicationType, + DeployState deployState, + AbstractConfigProducer parent, + List<Element> elements) { for (Element servicesElement : elements) { - ConfigModel model = buildModel(node, deployState, parent, servicesElement); + ConfigModel model = buildModel(node, applicationType, deployState, parent, servicesElement); if (model.isServing()) add(model); } } - private ConfigModel buildModel(ModelNode node, DeployState deployState, AbstractConfigProducer parent, Element servicesElement) { + private ConfigModel buildModel(ModelNode node, + ApplicationType applicationType, + DeployState deployState, + AbstractConfigProducer parent, + Element servicesElement) { ConfigModelBuilder builder = node.builder; - ConfigModelContext context = ConfigModelContext.create(deployState, this, parent, getIdString(servicesElement)); + ConfigModelContext context = ConfigModelContext.create(applicationType, deployState, this, parent, getIdString(servicesElement)); return builder.build(node, servicesElement, context); } |