diff options
Diffstat (limited to 'config-application-package/src/main/java/com/yahoo/config')
5 files changed, 51 insertions, 26 deletions
diff --git a/config-application-package/src/main/java/com/yahoo/config/application/ValidationProcessor.java b/config-application-package/src/main/java/com/yahoo/config/application/ValidationProcessor.java new file mode 100644 index 00000000000..5f430f70584 --- /dev/null +++ b/config-application-package/src/main/java/com/yahoo/config/application/ValidationProcessor.java @@ -0,0 +1,18 @@ +package com.yahoo.config.application; + +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import javax.xml.transform.TransformerException; +import java.io.IOException; + +public class ValidationProcessor implements PreProcessor { + + @Override + public Document process(Document input) throws IOException, TransformerException { + NodeList includeitems = input.getElementsByTagNameNS("http://www.w3.org/2001/XInclude", "*"); + if (includeitems.getLength() > 0) + throw new UnsupportedOperationException("XInclude not supported, use preprocess:include instead"); + return input; + } +}
\ No newline at end of file diff --git a/config-application-package/src/main/java/com/yahoo/config/application/XmlPreProcessor.java b/config-application-package/src/main/java/com/yahoo/config/application/XmlPreProcessor.java index 640cc7bcfa7..ba68894c9f9 100644 --- a/config-application-package/src/main/java/com/yahoo/config/application/XmlPreProcessor.java +++ b/config-application-package/src/main/java/com/yahoo/config/application/XmlPreProcessor.java @@ -5,6 +5,7 @@ import com.yahoo.config.application.FileSystemWrapper.FileWrapper; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.RegionName; +import com.yahoo.text.XML; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -57,7 +58,7 @@ public class XmlPreProcessor { } public Document run() throws ParserConfigurationException, IOException, SAXException, TransformerException { - DocumentBuilder docBuilder = Xml.getPreprocessDocumentBuilder(); + DocumentBuilder docBuilder = XML.getDocumentBuilder(); Document document = docBuilder.parse(new InputSource(xmlInput)); return execute(document); } @@ -74,6 +75,7 @@ public class XmlPreProcessor { chain.add(new IncludeProcessor(applicationDir)); chain.add(new OverrideProcessor(instance, environment, region)); chain.add(new PropertiesProcessor()); + chain.add(new ValidationProcessor()); // must be last in chain return chain; } diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/DeployData.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/DeployData.java index b21f8677984..279af646a8c 100644 --- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/DeployData.java +++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/DeployData.java @@ -10,9 +10,6 @@ import com.yahoo.config.provision.ApplicationId; */ public class DeployData { - /** Which user deployed */ - private final String deployedByUser; - private final ApplicationId applicationId; /** The absolute path to the directory holding the application */ @@ -28,14 +25,23 @@ public class DeployData { private final long generation; private final long currentlyActiveGeneration; - public DeployData(String deployedByUser, + // TODO: Remove when oldest version in use is 8.13 + public DeployData(String ignored, String deployedFromDir, ApplicationId applicationId, Long deployTimestamp, boolean internalRedeploy, Long generation, long currentlyActiveGeneration) { - this.deployedByUser = deployedByUser; + this(deployedFromDir, applicationId, deployTimestamp, internalRedeploy, generation, currentlyActiveGeneration); + } + + public DeployData(String deployedFromDir, + ApplicationId applicationId, + Long deployTimestamp, + boolean internalRedeploy, + Long generation, + long currentlyActiveGeneration) { this.deployedFromDir = deployedFromDir; this.applicationId = applicationId; this.deployTimestamp = deployTimestamp; @@ -44,8 +50,6 @@ public class DeployData { this.currentlyActiveGeneration = currentlyActiveGeneration; } - public String getDeployedByUser() { return deployedByUser; } - public String getDeployedFromDir() { return deployedFromDir; } public long getDeployTimestamp() { return deployTimestamp; } 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 826cf85798a..7b483d0603c 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 @@ -134,8 +134,7 @@ public class FilesApplicationPackage extends AbstractApplicationPackage { } private static ApplicationMetaData metaDataFromDeployData(File appDir, DeployData deployData) { - return new ApplicationMetaData(deployData.getDeployedByUser(), - deployData.getDeployedFromDir(), + return new ApplicationMetaData(deployData.getDeployedFromDir(), deployData.getDeployTimestamp(), deployData.isInternalRedeploy(), deployData.getApplicationId(), @@ -480,7 +479,6 @@ public class FilesApplicationPackage extends AbstractApplicationPackage { private static ApplicationMetaData readMetaData(File appDir) { String originalAppDir = preprocessed.equals(appDir.getName()) ? appDir.getParentFile().getName() : appDir.getName(); ApplicationMetaData defaultMetaData = new ApplicationMetaData("n/a", - "n/a", 0L, false, ApplicationId.from(TenantName.defaultName(), @@ -573,7 +571,7 @@ public class FilesApplicationPackage extends AbstractApplicationPackage { } @Override - public void writeMetaData() throws IOException { + public void writeMetaData() { File metaFile = applicationFile(appDir, META_FILE_NAME); IOUtils.writeFile(metaFile, metaData.asJsonBytes()); } diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidators.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidators.java index 57dca2293e6..8bd92d13511 100644 --- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidators.java +++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/SchemaValidators.java @@ -63,8 +63,6 @@ public class SchemaValidators { routingStandaloneXmlValidator = createValidator(schemaDir, routingStandaloneXmlSchemaName); } catch (IOException ioe) { throw new RuntimeException(ioe); - } catch (Exception e) { - throw e; } finally { if (schemaDir != null) IOUtils.recursiveDeleteDir(schemaDir); @@ -96,7 +94,7 @@ public class SchemaValidators { } /** - * Look for the schema files in config-model.jar and saves them on temp dir. Uses schema files + * Looks for schema files in config-model.jar and saves them in a temp dir. Uses schema files * in $VESPA_HOME/share/vespa/schema/[major-version].x/ otherwise * * @return the directory the schema files are stored in @@ -104,30 +102,29 @@ public class SchemaValidators { */ private File saveSchemasFromJar(File tmpBase, Version vespaVersion) throws IOException { Class<? extends SchemaValidators> schemaValidatorClass = this.getClass(); - ClassLoader classLoader = schemaValidatorClass.getClassLoader(); - Enumeration<URL> uris = classLoader.getResources("schema"); + Enumeration<URL> uris = schemaValidatorClass.getClassLoader().getResources("schema"); if (uris == null) throw new IllegalArgumentException("Could not find XML schemas "); File tmpDir = createTempDirectory(tmpBase.toPath(), "vespa").toFile(); log.log(Level.FINE, () -> "Will save all XML schemas for " + vespaVersion + " to " + tmpDir); + boolean schemasFound = false; while (uris.hasMoreElements()) { URL u = uris.nextElement(); - log.log(Level.FINE, () -> "uri for resource 'schema'=" + u.toString()); - // TODO: When is this the case? Remove? + // Used when building standalone-container if ("jar".equals(u.getProtocol())) { JarURLConnection jarConnection = (JarURLConnection) u.openConnection(); JarFile jarFile = jarConnection.getJarFile(); for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) { JarEntry je = entries.nextElement(); if (je.getName().startsWith("schema/") && je.getName().endsWith(".rnc")) { + schemasFound = true; writeContentsToFile(tmpDir, je.getName(), jarFile.getInputStream(je)); } } jarFile.close(); } else if ("bundle".equals(u.getProtocol())) { Bundle bundle = getBundle(schemaValidatorClass); - log.log(Level.FINE, () -> "bundle=" + bundle); - // TODO: Hack to handle cases where bundle=null (which seems to always be the case with config-model-fat-amended.jar) + // Use schemas on disk when bundle is null (which is the case when using config-model-fat-amended.jar) if (bundle == null) { String pathPrefix = getDefaults().underVespaHome("share/vespa/schema/"); File schemaPath = new File(pathPrefix + "version/" + vespaVersion.getMajor() + ".x/schema/"); @@ -137,22 +134,28 @@ public class SchemaValidators { schemaPath = new File(pathPrefix); } log.log(Level.FINE, "Using schemas found in " + schemaPath); + schemasFound = true; copySchemas(schemaPath, tmpDir); } else { log.log(Level.FINE, () -> String.format("Saving schemas for model bundle %s:%s", bundle.getSymbolicName(), bundle.getVersion())); - for (Enumeration<URL> entries = bundle.findEntries("schema", "*.rnc", true); - entries.hasMoreElements(); ) { - + for (Enumeration<URL> entries = bundle.findEntries("schema", "*.rnc", true); entries.hasMoreElements(); ) { URL url = entries.nextElement(); writeContentsToFile(tmpDir, url.getFile(), url.openStream()); + schemasFound = true; } } - // TODO: When is this the case? Remove? - } else if ("file".equals(u.getProtocol())) { + } else if ("file".equals(u.getProtocol())) { // Used when running unit tests File schemaPath = new File(u.getPath()); copySchemas(schemaPath, tmpDir); + schemasFound = true; } } + + if ( ! schemasFound) { + IOUtils.recursiveDeleteDir(tmpDir); + throw new IllegalArgumentException("Could not find schemas for version " + vespaVersion); + } + return tmpDir; } |