diff options
author | Harald Musum <musum@yahoo-inc.com> | 2016-11-23 13:52:02 +0100 |
---|---|---|
committer | Harald Musum <musum@yahoo-inc.com> | 2016-11-23 13:52:02 +0100 |
commit | cfa979971e676d85481570582606acda8cc7ac7b (patch) | |
tree | 3678ebec0c2aac1cad2c4fec5bafc910bcaf6fcd /config-model | |
parent | 24ce067331f3546cfa0060e9e8427777e884e5cb (diff) |
Remove special handling of deployment of routing application
* Routing application uses nodes from node repo in all zones now,
handle as other applications
VESPA-5118
Diffstat (limited to 'config-model')
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java | 48 | ||||
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java | 96 |
2 files changed, 5 insertions, 139 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java index 3aef44d1f90..35ea2134813 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java @@ -16,23 +16,16 @@ import com.yahoo.config.model.api.ModelCreateResult; import com.yahoo.config.model.api.ModelFactory; import com.yahoo.config.model.application.provider.ApplicationPackageXmlFilesValidator; import com.yahoo.config.model.builder.xml.ConfigModelBuilder; -import com.yahoo.config.model.builder.xml.XmlHelper; import com.yahoo.config.model.deploy.DeployProperties; import com.yahoo.config.model.deploy.DeployState; -import com.yahoo.config.model.provision.HostsXmlProvisioner; -import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Version; import com.yahoo.config.provision.Zone; -import com.yahoo.text.XML; import com.yahoo.vespa.config.VespaVersion; import com.yahoo.vespa.model.application.validation.Validation; -import org.w3c.dom.Document; -import org.w3c.dom.Element; import org.xml.sax.SAXException; import java.io.IOException; -import java.io.Reader; import java.time.Clock; import java.util.ArrayList; import java.util.List; @@ -147,45 +140,8 @@ public class VespaModelFactory implements ModelFactory { } private static HostProvisioner createHostProvisioner(ModelContext modelContext) { - // TODO: Remove this (use only else part of if statement) when zone applications uses nodes in node repo in all zones - if (isHostedVespaRoutingApplication(modelContext) && ! useRoutingNodesInNodeRepo(modelContext.applicationPackage().getServices())) { - //TODO: This belongs in HostedVespaProvisioner. - //Added here for now since com.yahoo.config.model.api.HostProvisioner is not created per application, - //and allocation is independent of ApplicationPackage. - return new HostsXmlProvisioner(hostsXml(modelContext)); - } else { - return modelContext.hostProvisioner().orElse( - DeployState.getDefaultModelHostProvisioner(modelContext.applicationPackage())); - } - } - - // Returns true if nodes element has an attribute 'type', false otherwise - public static boolean useRoutingNodesInNodeRepo(Reader servicesReader) { - Document services = XmlHelper.getDocument(servicesReader); - - Element jdisc = XML.getChild(services.getDocumentElement(), "jdisc"); - if (jdisc == null) return false; - - Element nodes = XML.getChild(jdisc, "nodes"); - if (nodes == null) return false; - - return nodes.hasAttribute("type"); - } - - private static Reader hostsXml(ModelContext modelContext) { - Reader hosts = modelContext.applicationPackage().getHosts(); - if (hosts == null) { - //TODO: throw InvalidApplicationException directly. Not possible now, as it resides in the configserver module. - //SessionPreparer maps IllegalArgumentException -> InvalidApplicationException - throw new IllegalArgumentException("Hosted vespa routing application must use " + ApplicationPackage.HOSTS - + " to allocate hosts."); - } - return hosts; - } - - private static boolean isHostedVespaRoutingApplication(ModelContext modelContext) { - ApplicationId id = modelContext.properties().applicationId(); - return modelContext.properties().hostedVespa() && id.isHostedVespaRoutingApplication(); + return modelContext.hostProvisioner().orElse( + DeployState.getDefaultModelHostProvisioner(modelContext.applicationPackage())); } private void validateXML(ApplicationPackage applicationPackage, boolean ignoreValidationErrors) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java b/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java index 9e149a8cf2e..671690030b6 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java @@ -10,7 +10,6 @@ import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.*; import org.junit.Before; import org.junit.Test; -import org.mockito.internal.stubbing.answers.ThrowsExceptionClass; import java.util.ArrayList; import java.util.Collections; @@ -23,9 +22,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * @author lulf @@ -72,94 +68,6 @@ public class VespaModelFactoryTest { assertTrue(createResult.getConfigChangeActions().isEmpty()); } - // TODO: This test seems to do exactly the same as hostedVespaZoneApplicationAllocatesNodesWithHostsXml() - @Test - public void hostedVespaRoutingApplicationAllocatesNodesWithHostsXml() { - String hostName = "test-host-name"; - String routingClusterName = "routing-cluster"; - - String hosts = - "<?xml version='1.0' encoding='utf-8' ?>\n" + - "<hosts>\n" + - " <host name='" + hostName + "'>\n" + - " <alias>proxy1</alias>\n" + - " </host>\n" + - "</hosts>"; - - String services = - "<?xml version='1.0' encoding='utf-8' ?>\n" + - "<services version='1.0' xmlns:deploy='vespa'>\n" + - " <admin version='2.0'>\n" + - " <adminserver hostalias='proxy1' />\n" + - " </admin>" + - " <jdisc id='" + routingClusterName + "' version='1.0'>\n" + - " <nodes>\n" + - " <node hostalias='proxy1' />\n" + - " </nodes>\n" + - " </jdisc>\n" + - "</services>"; - - HostProvisioner provisionerToOverride = - mock(HostProvisioner.class, new ThrowsExceptionClass(UnsupportedOperationException.class)); - ModelContext modelContext = createMockModelContext(hosts, services, provisionerToOverride); - Model model = new VespaModelFactory(new NullConfigModelRegistry()).createModel(modelContext); - - List<HostInfo> allocatedHosts = new ArrayList<>(model.getHosts()); - assertThat(allocatedHosts.size(), is(1)); - HostInfo hostInfo = allocatedHosts.get(0); - - assertThat(hostInfo.getHostname(), is(hostName)); - - assertTrue("Routing service should run on host " + hostName, - hostInfo.getServices().stream() - .map(ServiceInfo::getConfigId) - .anyMatch(configId -> configId.contains(routingClusterName))); - } - - @Test - public void hostedVespaZoneApplicationAllocatesNodesWithHostsXml() { - String hostName = "test-host-name"; - String routingClusterName = "routing-cluster"; - - String hosts = - "<?xml version='1.0' encoding='utf-8' ?>\n" + - "<hosts>\n" + - " <host name='" + hostName + "'>\n" + - " <alias>proxy1</alias>\n" + - " </host>\n" + - "</hosts>"; - - String services = - "<?xml version='1.0' encoding='utf-8' ?>\n" + - "<services version='1.0' xmlns:deploy='vespa'>\n" + - " <admin version='2.0'>\n" + - " <adminserver hostalias='proxy1' />\n" + - " </admin>" + - " <jdisc id='" + routingClusterName + "' version='1.0'>\n" + - " <nodes>\n" + - " <node hostalias='proxy1' />\n" + - " </nodes>\n" + - " </jdisc>\n" + - "</services>"; - - HostProvisioner provisionerToOverride = - mock(HostProvisioner.class, new ThrowsExceptionClass(UnsupportedOperationException.class)); - - ModelContext modelContext = createMockModelContext(hosts, services, provisionerToOverride); - Model model = new VespaModelFactory(new NullConfigModelRegistry()).createModel(modelContext); - - List<HostInfo> allocatedHosts = new ArrayList<>(model.getHosts()); - assertThat(allocatedHosts.size(), is(1)); - HostInfo hostInfo = allocatedHosts.get(0); - - assertThat(hostInfo.getHostname(), is(hostName)); - - assertTrue("Routing service should run on host " + hostName, - hostInfo.getServices().stream() - .map(ServiceInfo::getConfigId) - .anyMatch(configId -> configId.contains(routingClusterName))); - } - @Test public void hostedVespaZoneApplicationAllocatesNodesFromNodeRepo() { String hostName = "test-host-name"; @@ -257,7 +165,9 @@ public class VespaModelFactoryTest { @Override public ApplicationId applicationId() { - return ApplicationId.HOSTED_ZONE_APPLICATION_ID; + return ApplicationId.from(TenantName.from("hosted-vespa"), + ApplicationName.from("routing"), + InstanceName.defaultName()); } @Override |