summaryrefslogtreecommitdiffstats
path: root/config-application-package
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-04-07 16:49:04 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2017-04-07 16:49:04 +0200
commit025167b28f847e56333db4922d7a7543fcad7a1a (patch)
treea2466cbccc5fcffa89eb23464a915c83b83ef051 /config-application-package
parentb2f526a6b79965b9ff871d8cdfe283dccc1eefe8 (diff)
Pass wanted node Vespa version around
Diffstat (limited to 'config-application-package')
-rw-r--r--config-application-package/pom.xml6
-rw-r--r--config-application-package/src/main/java/com/yahoo/config/model/application/provider/ApplicationPackageXmlFilesValidator.java20
-rw-r--r--config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java6
-rw-r--r--config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidator.java33
-rw-r--r--config-application-package/src/main/java/com/yahoo/config/model/application/provider/SimpleApplicationValidator.java6
5 files changed, 42 insertions, 29 deletions
diff --git a/config-application-package/pom.xml b/config-application-package/pom.xml
index 7f49e9fb8b6..8236458c532 100644
--- a/config-application-package/pom.xml
+++ b/config-application-package/pom.xml
@@ -27,6 +27,12 @@
</dependency>
<dependency>
<groupId>com.yahoo.vespa</groupId>
+ <artifactId>component</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
<artifactId>vespajlib</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/ApplicationPackageXmlFilesValidator.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/ApplicationPackageXmlFilesValidator.java
index 201c18527bb..3bc956ae377 100644
--- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/ApplicationPackageXmlFilesValidator.java
+++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/ApplicationPackageXmlFilesValidator.java
@@ -2,8 +2,8 @@
package com.yahoo.config.model.application.provider;
import com.yahoo.collections.Tuple2;
+import com.yahoo.component.Version;
import com.yahoo.config.application.api.ApplicationPackage;
-import com.yahoo.config.provision.Version;
import com.yahoo.path.Path;
import com.yahoo.io.reader.NamedReader;
@@ -21,22 +21,24 @@ import java.util.Optional;
public class ApplicationPackageXmlFilesValidator {
private final AppSubDirs appDirs;
- private final Optional<Version> vespaVersion;
+
+ /** The Vespa version this package tshould be validated against */
+ private final Version vespaVersion;
private static final FilenameFilter xmlFilter = (dir, name) -> name.endsWith(".xml");
- public ApplicationPackageXmlFilesValidator(AppSubDirs appDirs, Optional<Version> vespaVersion) {
+ public ApplicationPackageXmlFilesValidator(AppSubDirs appDirs, Version vespaVersion) {
this.appDirs = appDirs;
this.vespaVersion = vespaVersion;
}
- public static ApplicationPackageXmlFilesValidator createDefaultXMLValidator(File appDir, Optional<Version> vespaVersion) {
+ public static ApplicationPackageXmlFilesValidator createDefaultXMLValidator(File appDir, Version vespaVersion) {
return new ApplicationPackageXmlFilesValidator(new AppSubDirs(appDir), vespaVersion);
}
- public static ApplicationPackageXmlFilesValidator createTestXmlValidator(File appDir) {
- return new ApplicationPackageXmlFilesValidator(new AppSubDirs(appDir), Optional.empty());
+ public static ApplicationPackageXmlFilesValidator createTestXmlValidator(File appDir, Version vespaVersion) {
+ return new ApplicationPackageXmlFilesValidator(new AppSubDirs(appDir), vespaVersion);
}
@SuppressWarnings("deprecation")
@@ -56,11 +58,11 @@ public class ApplicationPackageXmlFilesValidator {
}
// For testing
- public static void checkIncludedDirs(ApplicationPackage app) throws IOException {
+ public static void checkIncludedDirs(ApplicationPackage app, Version vespaVersion) throws IOException {
for (String includedDir : app.getUserIncludeDirs()) {
List<NamedReader> includedFiles = app.getFiles(Path.fromString(includedDir), ".xml", true);
for (NamedReader file : includedFiles) {
- createSchemaValidator("container-include.rnc", Optional.empty()).validate(file);
+ createSchemaValidator("container-include.rnc", vespaVersion).validate(file);
}
}
}
@@ -115,7 +117,7 @@ public class ApplicationPackageXmlFilesValidator {
}
}
- private static SchemaValidator createSchemaValidator(String schemaFile, Optional<Version> vespaVersion) {
+ private static SchemaValidator createSchemaValidator(String schemaFile, Version vespaVersion) {
return new SchemaValidator(schemaFile, new BaseDeployLogger(), vespaVersion);
}
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java
index 06e74e08307..63f19e9abf3 100644
--- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java
+++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java
@@ -1,6 +1,7 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.application.provider;
+import com.yahoo.component.Vtag;
import com.yahoo.config.application.ConfigDefinitionDir;
import com.yahoo.config.application.Xml;
import com.yahoo.config.application.XmlPreProcessor;
@@ -630,9 +631,10 @@ public class FilesApplicationPackage implements ApplicationPackage {
@Override
public void validateXML(Optional<Version> vespaVersion) throws IOException {
- ApplicationPackageXmlFilesValidator xmlFilesValidator = ApplicationPackageXmlFilesValidator.createDefaultXMLValidator(appDir, vespaVersion);
+ com.yahoo.component.Version modelVersion = vespaVersion.map(v -> new com.yahoo.component.Version(vespaVersion.toString())).orElse(Vtag.currentVersion);
+ ApplicationPackageXmlFilesValidator xmlFilesValidator = ApplicationPackageXmlFilesValidator.createDefaultXMLValidator(appDir, modelVersion);
xmlFilesValidator.checkApplication();
- ApplicationPackageXmlFilesValidator.checkIncludedDirs(this);
+ ApplicationPackageXmlFilesValidator.checkIncludedDirs(this, modelVersion);
}
@Override
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidator.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidator.java
index 698fa8fdce7..fd1156d435a 100644
--- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidator.java
+++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidator.java
@@ -6,8 +6,8 @@ import com.thaiopensource.util.PropertyMapBuilder;
import com.thaiopensource.validate.ValidateProperty;
import com.thaiopensource.validate.ValidationDriver;
import com.thaiopensource.validate.rng.CompactSchemaReader;
+import com.yahoo.component.Version;
import com.yahoo.config.application.api.DeployLogger;
-import com.yahoo.config.provision.Version;
import com.yahoo.io.IOUtils;
import com.yahoo.io.reader.NamedReader;
import com.yahoo.log.LogLevel;
@@ -27,7 +27,6 @@ import java.io.Reader;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
-import java.util.Optional;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
@@ -53,8 +52,9 @@ public class SchemaValidator {
* Initializes the validator by using the given file as schema file
* @param schema a schema file in RNC format
* @param logger a logger
+ * @param vespaVersion the version of Vespa we should validate against
*/
- public SchemaValidator(String schema, DeployLogger logger, Optional<Version> vespaVersion) {
+ public SchemaValidator(String schema, DeployLogger logger, Version vespaVersion) {
this.deployLogger = logger;
driver = new ValidationDriver(PropertyMap.EMPTY, instanceProperties(), CompactSchemaReader.getInstance());
File schemaDir = new File(schemaDirBase);
@@ -70,26 +70,27 @@ public class SchemaValidator {
/**
* Initializes the validator by using the given file as schema file
* @param schema a schema file in RNC format
+ * @param vespaVersion the version we should validate against
* @throws IOException if it is not possible to read schema files
*/
- public SchemaValidator(String schema) throws IOException {
- this(schema, new BaseDeployLogger(), Optional.empty());
+ public SchemaValidator(String schema, Version vespaVersion) throws IOException {
+ this(schema, new BaseDeployLogger(), vespaVersion);
}
/**
* Create a validator for services.xml for tests
* @throws IOException if it is not possible to read schema files
*/
- public static SchemaValidator createTestValidatorServices() throws IOException {
- return new SchemaValidator(servicesXmlSchemaName);
+ public static SchemaValidator createTestValidatorServices(Version vespaVersion) throws IOException {
+ return new SchemaValidator(servicesXmlSchemaName, vespaVersion);
}
/**
* Create a validator for hosts.xml for tests
* @throws IOException if it is not possible to read schema files
*/
- public static SchemaValidator createTestValidatorHosts() throws IOException {
- return new SchemaValidator(hostsXmlSchemaName);
+ public static SchemaValidator createTestValidatorHosts(Version vespaVersion) throws IOException {
+ return new SchemaValidator(hostsXmlSchemaName, vespaVersion);
}
/**
@@ -97,8 +98,8 @@ public class SchemaValidator {
*
* @throws IOException if it is not possible to read schema files
*/
- public static SchemaValidator createTestValidatorDeployment() throws IOException {
- return new SchemaValidator(deploymentXmlSchemaName);
+ public static SchemaValidator createTestValidatorDeployment(Version vespaVersion) throws IOException {
+ return new SchemaValidator(deploymentXmlSchemaName, vespaVersion);
}
private class CustomErrorHandler implements ErrorHandler {
@@ -129,7 +130,7 @@ public class SchemaValidator {
* @return the directory the schema files are stored in
* @throws IOException if it is not possible to read schema files
*/
- public File saveSchemasFromJar(File tmpBase, Optional<Version> vespaVersion) throws IOException {
+ private File saveSchemasFromJar(File tmpBase, Version vespaVersion) throws IOException {
final Class<? extends SchemaValidator> schemaValidatorClass = this.getClass();
final ClassLoader classLoader = schemaValidatorClass.getClassLoader();
Enumeration<URL> uris = classLoader.getResources("schema");
@@ -158,7 +159,7 @@ public class SchemaValidator {
// TODO: Hack to handle cases where bundle=null
if (bundle == null) {
File schemaPath;
- if (vespaVersion.isPresent() && vespaVersion.get().getMajor() == 5) {
+ if (vespaVersion.getMajor() == 5) {
schemaPath = new File(Defaults.getDefaults().vespaHome() + "share/vespa/schema/version/5.x/schema/");
} else {
schemaPath = new File(Defaults.getDefaults().vespaHome() + "share/vespa/schema/");
@@ -234,12 +235,12 @@ public class SchemaValidator {
errorHandler.fileName = (fileName == null ? " input" : fileName);
try {
if ( ! driver.validate(inputSource)) {
- //Shouldn't happen, error handler should have thrown
+ // Shouldn't happen, error handler should have thrown
throw new RuntimeException("Aborting due to earlier XML errors.");
}
} catch (SAXException e) {
- //This should never happen, as it is handled by the ErrorHandler
- //installed for the driver.
+ // This should never happen, as it is handled by the ErrorHandler
+ // installed for the driver.
throw new IllegalArgumentException(
"XML error in " + (fileName == null ? " input" : fileName) + ": " + Exceptions.toMessageString(e));
}
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SimpleApplicationValidator.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SimpleApplicationValidator.java
index 2d960f00d66..97b989617b3 100644
--- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SimpleApplicationValidator.java
+++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SimpleApplicationValidator.java
@@ -1,6 +1,8 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.application.provider;
+import com.yahoo.component.Version;
+
import java.io.IOException;
import java.io.Reader;
@@ -11,7 +13,7 @@ import java.io.Reader;
*/
public class SimpleApplicationValidator {
- public static void checkServices(Reader reader) throws IOException {
- SchemaValidator.createTestValidatorServices().validate(reader);
+ public static void checkServices(Reader reader, Version version) throws IOException {
+ SchemaValidator.createTestValidatorServices(version).validate(reader);
}
}