You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by is...@apache.org on 2020/06/30 10:18:06 UTC
[lucene-solr] branch jira/solr-14599_1 updated: SOLR-14599:
Incorporating review feedback
This is an automated email from the ASF dual-hosted git repository.
ishan pushed a commit to branch jira/solr-14599_1
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/jira/solr-14599_1 by this push:
new 8337949 SOLR-14599: Incorporating review feedback
8337949 is described below
commit 833794973b323198f4501008f396474160abb030
Author: Ishan Chattopadhyaya <is...@apache.org>
AuthorDate: Tue Jun 30 15:47:48 2020 +0530
SOLR-14599: Incorporating review feedback
---
.../apache/solr/packagemanager/PackageManager.java | 27 +++++++++-----
solr/core/src/test-files/runtimecode/MyPlugin.java | 43 ++++++++++++++++++++++
2 files changed, 60 insertions(+), 10 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java b/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java
index 45e803d..0f477bf 100644
--- a/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java
+++ b/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java
@@ -35,6 +35,7 @@ import java.util.stream.Collectors;
import org.apache.commons.collections.map.MultiValueMap;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.client.solrj.request.beans.PluginMeta;
import org.apache.solr.common.NavigableObject;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
@@ -148,10 +149,16 @@ public class PackageManager implements Closeable {
solrBaseUrl + PackageUtils.CLUSTERPROPS_PATH, Utils.JSONCONSUMER);
Map<String, Object> clusterPlugins = (Map<String, Object>) result.getOrDefault("plugin", Collections.emptyMap());
for (String key: clusterPlugins.keySet()) {
- Map<String, String> pluginMeta = (Map<String, String>) clusterPlugins.get(key);
- if (pluginMeta.containsKey("class") && pluginMeta.get("class").contains(":")) {
- String packageName = pluginMeta.get("class").substring(0, pluginMeta.get("class").indexOf(':'));
- packageVersions.put(packageName, pluginMeta.get("version"));
+ // Map<String, String> pluginMeta = (Map<String, String>) clusterPlugins.get(key);
+ PluginMeta pluginMeta;
+ try {
+ pluginMeta = PackageUtils.getMapper().readValue(Utils.toJSON(clusterPlugins.get(key)), PluginMeta.class);
+ } catch (IOException e) {
+ throw new SolrException(ErrorCode.SERVER_ERROR, "Exception while fetching plugins from /clusterprops.json in ZK.", e);
+ }
+ if (pluginMeta.klass.contains(":")) {
+ String packageName = pluginMeta.klass.substring(0, pluginMeta.klass.indexOf(':'));
+ packageVersions.put(packageName, pluginMeta.version);
packagePlugins.put(packageName, pluginMeta);
}
}
@@ -183,7 +190,7 @@ public class PackageManager implements Closeable {
List<String> collections, boolean shouldDeployClusterPlugins, String[] overrides) {
// Install plugins of type "cluster"
- boolean cluasterSuccess = deployClusterPackage(packageInstance, isUpdate, noprompt, shouldDeployClusterPlugins,
+ boolean clusterSuccess = deployClusterPackage(packageInstance, isUpdate, noprompt, shouldDeployClusterPlugins,
overrides);
@@ -201,7 +208,7 @@ public class PackageManager implements Closeable {
PackageUtils.printGreen("Deployed on " + deployedCollections + " and verified package: " + packageInstance.name + ", version: " + packageInstance.version);
}
- return cluasterSuccess && previouslyDeployedOnCollections.isEmpty() && verifySuccess;
+ return clusterSuccess && previouslyDeployedOnCollections.isEmpty() && verifySuccess;
}
/**
@@ -328,11 +335,11 @@ public class PackageManager implements Closeable {
cluasterPluginFailed = true;
continue;
}
- for (Map<String, String> pluginMeta: (List<Map<String, String>>)deployedPackage.getCustomData()) {
+ for (PluginMeta pluginMeta: (List<PluginMeta>)deployedPackage.getCustomData()) {
PackageUtils.printGreen("Updating this plugin: " + pluginMeta);
try {
- String postBody = "{\"update\":{\"name\": \""+pluginMeta.get("name")+"\","
- + " \"class\": \""+pluginMeta.get("class")+"\", \"version\": \""+packageInstance.version+"\", \"path-prefix\": \""+pluginMeta.get("path-prefix")+"\"}}";
+ pluginMeta.version = packageInstance.version; // just update the version, let the other metadata same
+ String postBody = "{\"update\": " + Utils.toJSONString(pluginMeta) + "}";
PackageUtils.printGreen("Posting " + postBody + " to " + PackageUtils.CLUSTER_PLUGINS_PATH);
SolrCLI.postJsonToSolr(solrClient, PackageUtils.CLUSTER_PLUGINS_PATH, postBody);
} catch (Exception e) {
@@ -562,7 +569,7 @@ public class PackageManager implements Closeable {
ensureCollectionsExist(Arrays.asList(collections));
// Undeploy cluster level plugins
- {
+ if (shouldUndeployClusterPlugins) {
SolrPackageInstance deployedPackage = getPackagesDeployedAsClusterLevelPlugins().get(packageName);
if (deployedPackage == null) {
PackageUtils.printRed("Cluster level plugins from package "+packageName+" not deployed.");
diff --git a/solr/core/src/test-files/runtimecode/MyPlugin.java b/solr/core/src/test-files/runtimecode/MyPlugin.java
index e69de29..34cfb6e 100644
--- a/solr/core/src/test-files/runtimecode/MyPlugin.java
+++ b/solr/core/src/test-files/runtimecode/MyPlugin.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package runtimecode;
+
+import org.apache.solr.api.Command;
+import org.apache.solr.api.EndPoint;
+import org.apache.solr.client.solrj.SolrRequest.METHOD;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.security.PermissionNameProvider;
+
+@EndPoint(path = "/plugin/my/path",
+ method = METHOD.GET,
+ permission = PermissionNameProvider.Name.CONFIG_READ_PERM)
+public class MyPlugin {
+
+ private final CoreContainer coreContainer;
+
+ public MyPlugin(CoreContainer coreContainer) {
+ this.coreContainer = coreContainer;
+ }
+
+ @Command
+ public void call(SolrQueryRequest req, SolrQueryResponse rsp){
+ rsp.add("myplugin.version", "2.0");
+ }
+}