diff options
-rw-r--r-- | model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModels.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModels.java b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModels.java index 05ff1aba877..f0cd0b01fa5 100644 --- a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModels.java +++ b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModels.java @@ -15,6 +15,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; +import java.util.regex.Pattern; /** * All models imported from the models/ directory in the application package. @@ -86,6 +87,7 @@ public class ImportedMlModels { Arrays.stream(dir.listFiles()).sorted().forEach(child -> { Optional<MlModelImporter> importer = findImporterOf(child, importers); if (importer.isPresent()) { + validateModelPath(child); String name = toName(child); Future<ImportedMlModel> existing = models.get(name); if (existing != null) { @@ -139,4 +141,27 @@ public class ImportedMlModels { return result.substring(0, result.length()-1); } + private static void validateModelPath(File modelFile) { + Pattern nameRegexp = Pattern.compile("[A-Za-z0-9_.]*"); + + Path path = Path.fromString(modelFile.toString()); + if (modelFile.isFile()) + path = stripFileEnding(path); + + boolean afterModels = false; + for (String element : path.elements()) { + if (afterModels) { + if ( ! nameRegexp.matcher(element).matches()) { + throw new IllegalArgumentException("When Vespa imports a model from the 'models' directory, it " + + "uses the directory structure under 'models' to determine the " + + "name of the model. The directory or file name '" + element + "' " + + "is not valid. Please rename this to only contain letters, " + + "numbers or underscores."); + } + } else if (element.equals("models")) { + afterModels = true; + } + } + } + } |