From d64c5c20b6de78f71ffb79f0249dd8a943d7c839 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Mon, 16 Dec 2019 08:04:33 +1100 Subject: [PATCH] SOLR-14087: disable package store API if -Denable.packages not set to true --- .../java/org/apache/solr/filestore/PackageStoreAPI.java | 6 +++++- solr/core/src/java/org/apache/solr/pkg/PackageAPI.java | 8 +++++++- .../apache/solr/filestore/TestDistribPackageStore.java | 8 ++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java b/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java index f1750eafe8c..5c09d5f22d4 100644 --- a/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java +++ b/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java @@ -47,6 +47,7 @@ import org.apache.solr.common.util.Utils; import org.apache.solr.core.BlobRepository; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.SolrCore; +import org.apache.solr.pkg.PackageAPI; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.security.PermissionNameProvider; @@ -64,7 +65,7 @@ import static org.apache.solr.handler.ReplicationHandler.FILE_STREAM; public class PackageStoreAPI { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - public static final String PACKAGESTORE_DIRECTORY = "filestore"; + public static final String PACKAGESTORE_DIRECTORY = "$filestore"; private final CoreContainer coreContainer; @@ -135,6 +136,9 @@ public class PackageStoreAPI { @Command public void upload(SolrQueryRequest req, SolrQueryResponse rsp) { + if(!coreContainer.getPackageLoader().getPackageAPI().isEnabled()) { + throw new RuntimeException(PackageAPI.ERR_MSG); + } try { coreContainer.getZkController().getZkClient().create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL, true); diff --git a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java index be4e9c9b612..1b93d894428 100644 --- a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java +++ b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java @@ -64,6 +64,8 @@ public class PackageAPI { public final boolean enablePackages = Boolean.parseBoolean(System.getProperty("enable.packages", "false")); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + public static final String ERR_MSG = "Package loading is not enabled , Start your nodes with -Denable.packages=true"; + final CoreContainer coreContainer; private final ObjectMapper mapper = SolrJacksonAnnotationInspector.createObjectMapper(); private final PackageLoader packageLoader; @@ -341,9 +343,13 @@ public class PackageAPI { } + public boolean isEnabled() { + return enablePackages; + } + private boolean checkEnabled(CommandOperation payload) { if (!enablePackages) { - payload.addError("Package loading is not enabled , Start your nodes with -Denable.packages=true"); + payload.addError(ERR_MSG); return false; } return true; diff --git a/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java b/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java index bd4b6bd99eb..64b1ef8e153 100644 --- a/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java +++ b/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java @@ -17,9 +17,6 @@ package org.apache.solr.filestore; -import static org.apache.solr.common.util.Utils.JAVABINCONSUMER; -import static org.apache.solr.core.TestDynamicLoading.getFileContent; - import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; @@ -30,6 +27,7 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.function.Predicate; +import com.google.common.collect.ImmutableSet; import org.apache.commons.codec.digest.DigestUtils; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; @@ -50,12 +48,14 @@ import org.apache.solr.util.LogLevel; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.server.ByteBufferInputStream; -import com.google.common.collect.ImmutableSet; +import static org.apache.solr.common.util.Utils.JAVABINCONSUMER; +import static org.apache.solr.core.TestDynamicLoading.getFileContent; @LogLevel("org.apache.solr.filestore.PackageStoreAPI=DEBUG;org.apache.solr.filestore.DistribPackageStore=DEBUG") public class TestDistribPackageStore extends SolrCloudTestCase { public void testPackageStoreManagement() throws Exception { + System.setProperty("enable.packages", "true"); MiniSolrCloudCluster cluster = configureCluster(4) .withJettyConfig(jetty -> jetty.enableV2(true))