diff options
6 files changed, 59 insertions, 3 deletions
diff --git a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java index 4bdc586116e..0f783b00438 100644 --- a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java @@ -20,6 +20,7 @@ import java.io.FileReader; import java.io.IOException; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -90,6 +91,20 @@ public class FilesApplicationPackageTest { assertTrue(deployment.exists()); FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir); assertTrue(app.getDeployment().isPresent()); + assertFalse(app.getMajorVersion().isPresent()); assertThat(IOUtils.readAll(new FileReader(deployment)), is(IOUtils.readAll(app.getDeployment().get()))); } + + @Test + public void testPinningMajorVersion() throws IOException { + File appDir = new File("src/test/resources/app-pinning-major-version"); + final File deployment = new File(appDir, "deployment.xml"); + assertTrue(deployment.exists()); + FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir); + assertTrue(app.getDeployment().isPresent()); + assertTrue(app.getMajorVersion().isPresent()); + assertEquals(6, (int)app.getMajorVersion().get()); + assertThat(IOUtils.readAll(new FileReader(deployment)), is(IOUtils.readAll(app.getDeployment().get()))); + } + } diff --git a/config-application-package/src/test/resources/app-pinning-major-version/deployment.xml b/config-application-package/src/test/resources/app-pinning-major-version/deployment.xml new file mode 100644 index 00000000000..3eb207580f4 --- /dev/null +++ b/config-application-package/src/test/resources/app-pinning-major-version/deployment.xml @@ -0,0 +1,9 @@ +<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<deployment version='1.0' major-version='6'> + <test /> + <staging /> + <prod> + <region active="true">us-east</region> + <region active="false">us-west-1</region> + </prod> +</deployment> diff --git a/config-application-package/src/test/resources/app-pinning-major-version/hosts.xml b/config-application-package/src/test/resources/app-pinning-major-version/hosts.xml new file mode 100644 index 00000000000..5d2be9b0cde --- /dev/null +++ b/config-application-package/src/test/resources/app-pinning-major-version/hosts.xml @@ -0,0 +1,10 @@ +<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<hosts xmlns:deploy="vespa" xmlns:preprocess="properties"> + <preprocess:properties> + <node1.hostname>foo.yahoo.com</node1.hostname> + <node1.hostname deploy:environment="dev">bar.yahoo.com</node1.hostname> + </preprocess:properties> + <host name="${node1.hostname}"> + <alias>node1</alias> + </host> +</hosts> diff --git a/config-application-package/src/test/resources/app-pinning-major-version/searchdefinitions/music.sd b/config-application-package/src/test/resources/app-pinning-major-version/searchdefinitions/music.sd new file mode 100644 index 00000000000..c0190a4a7a8 --- /dev/null +++ b/config-application-package/src/test/resources/app-pinning-major-version/searchdefinitions/music.sd @@ -0,0 +1,8 @@ +# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +search music { + document music { + field f type string { + indexing: index | summary + } + } +} diff --git a/config-application-package/src/test/resources/app-pinning-major-version/services.xml b/config-application-package/src/test/resources/app-pinning-major-version/services.xml new file mode 100644 index 00000000000..33d1e6c5a20 --- /dev/null +++ b/config-application-package/src/test/resources/app-pinning-major-version/services.xml @@ -0,0 +1,12 @@ +<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<services version='1.0'> + <admin version='2.0'> + <adminserver hostalias='node0'/> + </admin> + <content version='1.0' id='foo'> + <redundancy>1</redundancy> + <documents> + <document type="music.sd" mode="index" /> + </documents> + </content> +</services> diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java index c7258d8aede..c6e44e3aef3 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java @@ -145,9 +145,11 @@ public interface ApplicationPackage { /** Returns the major version this application is valid for, or empty if it is valid for all versions */ default Optional<Integer> getMajorVersion() { - Element servicesElement = XML.getDocument(getServices()).getDocumentElement(); - if (servicesElement == null) return Optional.empty(); - String majorVersionString = servicesElement.getAttribute("major-version"); + if ( ! getDeployment().isPresent()) return Optional.empty(); + + Element deployElement = XML.getDocument(getDeployment().get()).getDocumentElement(); + if (deployElement == null) return Optional.empty(); + String majorVersionString = deployElement.getAttribute("major-version"); if (majorVersionString == null || majorVersionString.isEmpty()) return Optional.empty(); try { |