You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2023/08/10 16:52:00 UTC
[solr] branch main updated: SOLR-16920: Add Test full package lifecycle (#1826), fix parsing of repository.json mimetype
This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 88990d640a8 SOLR-16920: Add Test full package lifecycle (#1826), fix parsing of repository.json mimetype
88990d640a8 is described below
commit 88990d640a89091a8f7b0b2493377ac24118afe8
Author: Eric Pugh <ep...@opensourceconnections.com>
AuthorDate: Thu Aug 10 12:51:53 2023 -0400
SOLR-16920: Add Test full package lifecycle (#1826), fix parsing of repository.json mimetype
Github is a common place to store the repository.json file used by Solr Packages. While the file is .json, the mimetype from Github is text/plain, so this fixes the client being used to load the repository.json to accept text/plain as well as application/json mimetypes.
---
solr/CHANGES.txt | 2 ++
.../packagemanager/DefaultPackageRepository.java | 20 +++++++++++++++++--
solr/packaging/test/test_packages.bats | 23 +++++++++++++++++++++-
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 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.java
index 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.bats
index 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=true
solr 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
+# }