Apache Solr open-source search software
SOLR-16820: Allow semVer style collection names (amongst others) (#1688)
Will White5dc56ac47355
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 0db629d08f5..e496d71f78e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -176,6 +176,8 @@ Improvementsthen uses the weights to decide the optimal strategy for placing new replicas or balancing existing replicas.(Houston Putman, Tomás Fernández Löbbe, Jason Gerlowski, Radu Gheorghe)+* SOLR-16820: Align allowed collection names and the validation of them in the CreateCollectionAPI and the PackageTool. (Will White via Eric Pugh)+Optimizations---------------------diff --git a/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java b/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.javaindex c813f400a37..97379a3a114 100644--- a/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java+++ b/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java@@ -16,6 +16,8 @@*/package org.apache.solr.packagemanager;+import static org.apache.solr.client.solrj.util.SolrIdentifierValidator.validateCollectionName;+import com.fasterxml.jackson.databind.ObjectMapper;import com.jayway.jsonpath.Configuration;import com.jayway.jsonpath.spi.json.JacksonJsonProvider;@@ -268,17 +270,8 @@ public class PackageUtils {}public static String[] validateCollections(String collections[]) {- String collectionNameRegex = "^[a-zA-Z0-9_-]*$";for (String c : collections) {- if (c.matches(collectionNameRegex) == false) {- throw new SolrException(- ErrorCode.BAD_REQUEST,- "Invalid collection name: "- + c- + ". Didn't match the pattern: '"- + collectionNameRegex- + "'");- }+ validateCollectionName(c);}return collections;}diff --git a/solr/packaging/test/test_packages.bats b/solr/packaging/test/test_packages.batsindex dc2ef88c618..6d7359bb7fd 100644--- a/solr/packaging/test/test_packages.bats+++ b/solr/packaging/test/test_packages.bats@@ -46,3 +46,22 @@ teardown() {run solr package list-availableassert_output --partial "Available packages:"}++@test "deploying and undeploying of packages" {+ run solr start -c -Denable.packages=true++ solr create_collection -c foo-1.2++ # Deploy package - the package doesn't need to exist before the collection validation kicks in+ run solr package deploy PACKAGE_NAME -collections foo-1.2+ # assert_output --partial "Deployment successful"+ refute_output --partial "Invalid collection"++ # Until PACKAGE_NAME refers to an actual installable package, this is as far as we get.+ assert_output --partial "Package instance doesn't exist: PACKAGE_NAME:null"++ # Undeploy package+ run solr package undeploy PACKAGE_NAME -collections foo-1.2+ refute_output --partial "Invalid collection"+ assert_output --partial "Package PACKAGE_NAME not deployed on collection foo-1.2"+}