Apache Solr open-source search software
SOLR-16920: Add Test full package lifecycle (#1826), fix parsing of repository.json mimetype
Eric Pugh88990d640a89
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex d5d12bf7cf8..e961fdfa2ec 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -112,6 +112,8 @@ Bug Fixes* SOLR-16360: Atomic update on boolean fields doesn't reflect when value starts with "1", "t" or "T" (Rahul Goswami, Justin Sweeney, David Smiley)+* PR#1826: Allow looking up Solr Package repo when that URL references a raw repository.json hosted on Github when the file is JSON but the mimetype used is text/plain. (Eric Pugh)+Dependency Upgrades---------------------(No changes)diff --git a/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java b/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.javaindex 32533625e60..820391804e1 100644--- a/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java+++ b/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java@@ -23,7 +23,9 @@ import java.lang.invoke.MethodHandles;import java.net.URL;import java.nio.file.Files;import java.nio.file.Path;+import java.util.Collection;import java.util.Map;+import java.util.Set;import org.apache.commons.io.FileUtils;import org.apache.commons.io.FilenameUtils;import org.apache.solr.client.solrj.SolrRequest;@@ -106,13 +108,15 @@ public class DefaultPackageRepository extends PackageRepository {private void initPackages() {// We need http 1.1 protocol here because we are talking to the repository server and not to- // solr actually.+ // an actual Solr server.// We use an Http2SolrClient so that we do not need a raw jetty http client for this GET.+ // We may get a text/plain mimetype for the repository.json (for instance when looking up a repo+ // on Github), so use custom ResponseParser.try (Http2SolrClient client =new Http2SolrClient.Builder(repositoryURL).useHttp1_1(true).build()) {GenericSolrRequest request =new GenericSolrRequest(SolrRequest.METHOD.GET, "/repository.json");- request.setResponseParser(new JsonMapResponseParser());+ request.setResponseParser(new TalkToRepoResponseParser());NamedList<Object> resp = client.request(request);SolrPackage[] items =PackageUtils.getMapper().readValue("[" + resp.jsonStr() + "]", SolrPackage[].class);@@ -128,4 +132,16 @@ public class DefaultPackageRepository extends PackageRepository {log.debug("Found {} packages in repository '{}'", packages.size(), name);}}++ /**+ * Github links for repository.json are returned in JSON format but with text/plain mimetype, so+ * this works around that issue.+ */+ private static class TalkToRepoResponseParser extends JsonMapResponseParser {++ @Override+ public Collection<String> getContentTypes() {+ return Set.of("application/json", "text/plain");+ }+ }}diff --git a/solr/packaging/test/test_packages.bats b/solr/packaging/test/test_packages.batsindex fd7410b5dd8..3dda0e718e8 100644--- a/solr/packaging/test/test_packages.bats+++ b/solr/packaging/test/test_packages.bats@@ -47,7 +47,7 @@ teardown() {assert_output --partial "Available packages:"}-@test "deploying and undeploying of packages" {+@test "deploying and undeploying a collection level package" {run solr start -c -Denable.packages=truesolr create -c foo-1.2@@ -65,3 +65,24 @@ teardown() {refute_output --partial "Invalid collection"assert_output --partial "Package PACKAGE_NAME not deployed on collection foo-1.2"}++# This test is useful if you are debugging/working with packages.+# We have commented it out for now since it depends on a live internet+# connection to run. This could be updated with a local Repo server if we had+# a package that is part of the Solr project to use.+# @test "deploying and undeploying a cluster level package" {+# run solr start -c -Denable.packages=true++# run solr package add-repo splainer "https://raw.githubusercontent.com/o19s/splainer/main/solr-splainer-package/repo"+# assert_output --partial "Added repository: splainer"++# run solr package list-available+# assert_output --partial "solr-splainer Splainer for Solr"+# run solr package install solr-splainer+# assert_output --partial "solr-splainer installed."++# run solr package deploy solr-splainer -y -cluster+# assert_output --partial "Deployment successful"++# run -0 curl --fail http://localhost:8983/v2/splainer/index.html+# }