You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2020/09/23 07:29:58 UTC

[lucene-solr] branch jira/solr14890 created (now 1423dd4)

This is an automated email from the ASF dual-hosted git repository.

noble pushed a change to branch jira/solr14890
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git.


      at 1423dd4  SOLR-14890: Refactor code to use annotations for cluster API

This branch includes the following new commits:

     new 2d8b868  SOLR-14890: Refactor code to use annotations for cluster API
     new 1423dd4  SOLR-14890: Refactor code to use annotations for cluster API

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[lucene-solr] 01/02: SOLR-14890: Refactor code to use annotations for cluster API

Posted by no...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

noble pushed a commit to branch jira/solr14890
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 2d8b86840a1e756f09d946ca3472904ed3e52892
Author: noble <no...@apache.org>
AuthorDate: Wed Sep 23 17:10:22 2020 +1000

    SOLR-14890: Refactor code to use annotations for cluster API
---
 .../cloud/OverseerConfigSetMessageHandler.java     | 24 +++---
 .../java/org/apache/solr/cloud/ZkController.java   | 28 +------
 .../cloud/api/collections/CreateCollectionCmd.java | 19 ++---
 .../cloud/api/collections/DeleteCollectionCmd.java |  4 +-
 .../java/org/apache/solr/core/CoreContainer.java   |  1 +
 .../java/org/apache/solr/handler/ClusterAPI.java   | 50 +++++++++++-
 .../solr/handler/admin/ConfigSetsHandler.java      | 35 ++++----
 .../solr/handler/admin/ConfigSetsHandlerApi.java   | 93 ----------------------
 .../client/solrj/request/CollectionApiMapping.java | 75 -----------------
 .../solrj/request/beans/CreateConfigInfo.java}     | 23 +++---
 .../org/apache/solr/common/MapSerializable.java    |  3 +-
 .../src/java/org/apache/solr/common/MapWriter.java |  2 +-
 .../apispec/cluster.configs.Commands.json          | 34 --------
 .../resources/apispec/cluster.configs.delete.json  | 12 ---
 .../src/resources/apispec/cluster.configs.json     | 12 ---
 15 files changed, 104 insertions(+), 311 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java b/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java
index 4f5b28f..9af5a6f 100644
--- a/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java
+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java
@@ -16,6 +16,17 @@
  */
 package org.apache.solr.cloud;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.invoke.MethodHandles;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
 import org.apache.solr.common.cloud.DocCollection;
@@ -32,21 +43,10 @@ import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.lang.invoke.MethodHandles;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
 import static org.apache.solr.common.params.CommonParams.NAME;
 import static org.apache.solr.common.params.ConfigSetParams.ConfigSetAction.CREATE;
 import static org.apache.solr.common.util.Utils.toJSONString;
-import static org.apache.solr.handler.admin.ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME;
+import static org.apache.solr.handler.admin.ConfigSetsHandler.DEFAULT_CONFIGSET_NAME;
 
 /**
  * A {@link OverseerMessageHandler} that handles ConfigSets API related
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
index dc4c210..c29623d 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -65,30 +65,8 @@ import org.apache.solr.cloud.overseer.SliceMutator;
 import org.apache.solr.common.AlreadyClosedException;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.cloud.BeforeReconnect;
-import org.apache.solr.common.cloud.ClusterState;
-import org.apache.solr.common.cloud.ConnectionManager;
-import org.apache.solr.common.cloud.DefaultConnectionStrategy;
-import org.apache.solr.common.cloud.DefaultZkACLProvider;
-import org.apache.solr.common.cloud.DefaultZkCredentialsProvider;
-import org.apache.solr.common.cloud.DocCollection;
-import org.apache.solr.common.cloud.DocCollectionWatcher;
-import org.apache.solr.common.cloud.LiveNodesListener;
-import org.apache.solr.common.cloud.NodesSysPropsCacher;
-import org.apache.solr.common.cloud.OnReconnect;
-import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.*;
 import org.apache.solr.common.cloud.Replica.Type;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.cloud.ZkACLProvider;
-import org.apache.solr.common.cloud.ZkCmdExecutor;
-import org.apache.solr.common.cloud.ZkConfigManager;
-import org.apache.solr.common.cloud.ZkCoreNodeProps;
-import org.apache.solr.common.cloud.ZkCredentialsProvider;
-import org.apache.solr.common.cloud.ZkMaintenanceUtils;
-import org.apache.solr.common.cloud.ZkNodeProps;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.cloud.ZooKeeperException;
 import org.apache.solr.common.params.CollectionParams;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.CoreAdminParams;
@@ -106,7 +84,7 @@ import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.CoreDescriptor;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.core.SolrCoreInitializationException;
-import org.apache.solr.handler.admin.ConfigSetsHandlerApi;
+import org.apache.solr.handler.admin.ConfigSetsHandler;
 import org.apache.solr.handler.component.HttpShardHandler;
 import org.apache.solr.logging.MDCLoggingContext;
 import org.apache.solr.search.SolrIndexSearcher;
@@ -908,7 +886,7 @@ public class ZkController implements Closeable {
             , "intended to be the default. Current 'solr.default.confdir' value:"
             , System.getProperty(SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE));
       } else {
-        ZkMaintenanceUtils.upConfig(zkClient, Paths.get(configDirPath), ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME);
+        ZkMaintenanceUtils.upConfig(zkClient, Paths.get(configDirPath), ConfigSetsHandler.DEFAULT_CONFIGSET_NAME);
       }
     }
   }
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
index 854ee9a..d356788 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
@@ -32,11 +32,11 @@ import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-import org.apache.solr.client.solrj.cloud.DistribStateManager;
-import org.apache.solr.client.solrj.cloud.SolrCloudManager;
 import org.apache.solr.client.solrj.cloud.AlreadyExistsException;
 import org.apache.solr.client.solrj.cloud.BadVersionException;
+import org.apache.solr.client.solrj.cloud.DistribStateManager;
 import org.apache.solr.client.solrj.cloud.NotEmptyException;
+import org.apache.solr.client.solrj.cloud.SolrCloudManager;
 import org.apache.solr.client.solrj.cloud.VersionedData;
 import org.apache.solr.cloud.Overseer;
 import org.apache.solr.cloud.ZkController;
@@ -63,7 +63,6 @@ import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.common.util.TimeSource;
 import org.apache.solr.common.util.Utils;
-import org.apache.solr.handler.admin.ConfigSetsHandlerApi;
 import org.apache.solr.handler.component.ShardHandler;
 import org.apache.solr.handler.component.ShardRequest;
 import org.apache.solr.util.TimeOut;
@@ -86,6 +85,8 @@ import static org.apache.solr.common.params.CommonAdminParams.ASYNC;
 import static org.apache.solr.common.params.CommonAdminParams.WAIT_FOR_FINAL_STATE;
 import static org.apache.solr.common.params.CommonParams.NAME;
 import static org.apache.solr.common.util.StrUtils.formatString;
+import static org.apache.solr.handler.admin.ConfigSetsHandler.DEFAULT_CONFIGSET_NAME;
+import static org.apache.solr.handler.admin.ConfigSetsHandler.getSuffixedNameForAutoGeneratedConfigSet;
 
 public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -300,7 +301,7 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd
 
         // Emit a warning about production use of data driven functionality
         boolean defaultConfigSetUsed = message.getStr(COLL_CONF) == null ||
-            message.getStr(COLL_CONF).equals(ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME);
+            message.getStr(COLL_CONF).equals(DEFAULT_CONFIGSET_NAME);
         if (defaultConfigSetUsed) {
           results.add("warning", "Using _default configset. Data driven schema functionality"
               + " is enabled by default, which is NOT RECOMMENDED for production use. To turn it off:"
@@ -419,11 +420,11 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd
       List<String> configNames = null;
       try {
         configNames = ocmh.zkStateReader.getZkClient().getChildren(ZkConfigManager.CONFIGS_ZKNODE, null, true);
-        if (configNames.contains(ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME)) {
+        if (configNames.contains(DEFAULT_CONFIGSET_NAME)) {
           if (CollectionAdminParams.SYSTEM_COLL.equals(coll)) {
             return coll;
           } else {
-            String intendedConfigSetName = ConfigSetsHandlerApi.getSuffixedNameForAutoGeneratedConfigSet(coll);
+            String intendedConfigSetName = getSuffixedNameForAutoGeneratedConfigSet(coll);
             copyDefaultConfigSetTo(configNames, intendedConfigSetName);
             return intendedConfigSetName;
           }
@@ -452,7 +453,7 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd
     }
     // Copy _default into targetConfig
     try {
-      configManager.copyConfigDir(ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME, targetConfig, new HashSet<>());
+      configManager.copyConfigDir(DEFAULT_CONFIGSET_NAME, targetConfig, new HashSet<>());
     } catch (Exception e) {
       throw new SolrException(ErrorCode.INVALID_STATE, "Error while copying _default to " + targetConfig, e);
     }
@@ -580,9 +581,9 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd
         break;
       }
       // if _default exists, use that
-      if (configNames != null && configNames.contains(ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME)) {
+      if (configNames != null && configNames.contains(DEFAULT_CONFIGSET_NAME)) {
         log.info("Could not find explicit collection configName, but found _default config set - using that set.");
-        collectionProps.put(ZkController.CONFIGNAME_PROP, ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME);
+        collectionProps.put(ZkController.CONFIGNAME_PROP, DEFAULT_CONFIGSET_NAME);
         break;
       }
       // if there is only one conf, use that
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
index 352d9e9..5c08057 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
@@ -45,7 +45,7 @@ import org.apache.solr.common.util.TimeSource;
 import org.apache.solr.common.util.Utils;
 import org.apache.solr.core.SolrInfoBean;
 import org.apache.solr.core.snapshots.SolrSnapshotManager;
-import org.apache.solr.handler.admin.ConfigSetsHandlerApi;
+import org.apache.solr.handler.admin.ConfigSetsHandler;
 import org.apache.solr.handler.admin.MetricsHistoryHandler;
 import org.apache.solr.metrics.SolrMetricManager;
 import org.apache.zookeeper.KeeperException;
@@ -164,7 +164,7 @@ public class DeleteCollectionCmd implements OverseerCollectionMessageHandler.Cmd
       // delete related config set iff: it is auto generated AND not related to any other collection
       String configSetName = zkStateReader.readConfigName(collection);
 
-      if (ConfigSetsHandlerApi.isAutoGeneratedConfigSet(configSetName)) {
+      if (ConfigSetsHandler.isAutoGeneratedConfigSet(configSetName)) {
         boolean configSetIsUsedByOtherCollection = false;
 
         // make sure the configSet is not shared with other collections
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 9e0a890..8052833 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -723,6 +723,7 @@ public class CoreContainer {
     ClusterAPI clusterAPI = new ClusterAPI(collectionsHandler);
     containerHandlers.getApiBag().registerObject(clusterAPI);
     containerHandlers.getApiBag().registerObject(clusterAPI.commands);
+    containerHandlers.getApiBag().registerObject(clusterAPI.configSetCommands);
     /*
      * HealthCheckHandler needs to be initialized before InfoHandler, since the later one will call CoreContainer.getHealthCheckHandler().
      * We don't register the handler here because it'll be registered inside InfoHandler
diff --git a/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java b/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
index 5ce564e..d32db93 100644
--- a/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
+++ b/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
@@ -25,16 +25,21 @@ import org.apache.solr.api.Command;
 import org.apache.solr.api.EndPoint;
 import org.apache.solr.api.PayloadObj;
 import org.apache.solr.client.solrj.request.beans.ClusterPropInfo;
+import org.apache.solr.client.solrj.request.beans.CreateConfigInfo;
+import org.apache.solr.cloud.OverseerConfigSetMessageHandler;
 import org.apache.solr.cluster.placement.impl.PlacementPluginConfigImpl;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.annotation.JsonProperty;
 import org.apache.solr.common.cloud.ClusterProperties;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ConfigSetParams;
 import org.apache.solr.common.params.DefaultSolrParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.ReflectMapWriter;
 import org.apache.solr.common.util.Utils;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.handler.admin.CollectionsHandler;
+import org.apache.solr.handler.admin.ConfigSetsHandler;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.response.SolrQueryResponse;
 
@@ -48,19 +53,21 @@ import static org.apache.solr.common.params.CollectionParams.CollectionAction.OV
 import static org.apache.solr.common.params.CollectionParams.CollectionAction.REMOVEROLE;
 import static org.apache.solr.security.PermissionNameProvider.Name.COLL_EDIT_PERM;
 import static org.apache.solr.security.PermissionNameProvider.Name.COLL_READ_PERM;
+import static org.apache.solr.security.PermissionNameProvider.Name.CONFIG_EDIT_PERM;
+import static org.apache.solr.security.PermissionNameProvider.Name.CONFIG_READ_PERM;
 
 public class ClusterAPI {
   private final CoreContainer coreContainer;
   private final CollectionsHandler collectionsHandler;
 
   public  final Commands commands = new Commands();
+  public  final ConfigSetCommands configSetCommands = new ConfigSetCommands();
 
   public ClusterAPI(CollectionsHandler ch) {
     this.collectionsHandler = ch;
     this.coreContainer = ch.getCoreContainer();
   }
 
-
   @EndPoint(method = GET,
       path = "/cluster/overseer",
       permission = COLL_READ_PERM)
@@ -83,6 +90,44 @@ public class ClusterAPI {
     CollectionsHandler.CollectionOperation.DELETESTATUS_OP.execute(req, rsp, coreContainer.getCollectionsHandler());
   }
 
+  @EndPoint(method = DELETE,
+      path =   "/cluster/configs/{name}",
+      permission = CONFIG_EDIT_PERM
+  )
+  public void deleteConfigSet(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
+    req = wrapParams(req,
+        "action", ConfigSetParams.ConfigSetAction.DELETE.toString(),
+        CommonParams.NAME, req.getPathTemplateValues().get("name"));
+    coreContainer.getConfigSetsHandler().handleRequestBody(req, rsp);
+  }
+
+  @EndPoint(method = GET,
+      path = "/cluster/configs",
+      permission = CONFIG_READ_PERM)
+  public void listConfigSet(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
+    ConfigSetsHandler.ConfigSetOperation.LIST_OP.call(req, rsp, coreContainer.getConfigSetsHandler());
+  }
+
+  @EndPoint(method = POST,
+  path = "/cluster/configs",
+      permission = CONFIG_EDIT_PERM
+  )
+  public class ConfigSetCommands {
+
+    @Command(name = "create")
+    @SuppressWarnings("unchecked")
+    public void create(PayloadObj<CreateConfigInfo> obj) throws Exception {
+      Map<String, Object> mapVals = obj.get().toMap(new HashMap<>());
+      Map<String,Object> customProps = (Map<String, Object>) mapVals.remove("properties");
+      if(customProps!= null) {
+        customProps.forEach((k, o) -> mapVals.put(OverseerConfigSetMessageHandler.PROPERTY_PREFIX+"."+ k, o));
+      }
+      mapVals.put("action", ConfigSetParams.ConfigSetAction.CREATE.toString());
+      coreContainer.getConfigSetsHandler().handleRequestBody(wrapParams(obj.getRequest(), mapVals), obj.getResponse());
+    }
+
+  }
+
   public static SolrQueryRequest wrapParams(SolrQueryRequest req, Object... def) {
     Map<String, Object> m = Utils.makeMap(def);
     return wrapParams(req, m);
@@ -150,9 +195,8 @@ public class ClusterAPI {
     }
 
     @Command(name = "set-property")
-    @SuppressWarnings({"rawtypes", "unchecked"})
     public void setProperty(PayloadObj<Map<String,String>> obj) throws Exception {
-      Map m =  obj.get();
+      Map<String,Object> m =  obj.getDataMap();
       m.put("action", CLUSTERPROP.toString());
       collectionsHandler.handleRequestBody(wrapParams(obj.getRequest(),m ), obj.getResponse());
     }
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java
index 728bf9f..2f499b7 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java
@@ -19,7 +19,6 @@ package org.apache.solr.handler.admin;
 import java.io.InputStream;
 import java.lang.invoke.MethodHandles;
 import java.nio.charset.StandardCharsets;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -29,7 +28,6 @@ import java.util.zip.ZipInputStream;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.solr.api.Api;
 import org.apache.solr.client.solrj.SolrResponse;
 import org.apache.solr.cloud.OverseerSolrResponse;
 import org.apache.solr.cloud.OverseerSolrResponseSerializer;
@@ -66,17 +64,16 @@ import static org.apache.solr.common.params.CommonParams.NAME;
 import static org.apache.solr.common.params.ConfigSetParams.ConfigSetAction.CREATE;
 import static org.apache.solr.common.params.ConfigSetParams.ConfigSetAction.DELETE;
 import static org.apache.solr.common.params.ConfigSetParams.ConfigSetAction.LIST;
-import static org.apache.solr.handler.admin.ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME;
 
 /**
  * A {@link org.apache.solr.request.SolrRequestHandler} for ConfigSets API requests.
  */
 public class ConfigSetsHandler extends RequestHandlerBase implements PermissionNameProvider {
+  final public static String DEFAULT_CONFIGSET_NAME = "_default";
+  final public static String AUTOCREATED_CONFIGSET_SUFFIX = ".AUTOCREATED";
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   protected final CoreContainer coreContainer;
   public static long DEFAULT_ZK_TIMEOUT = 300 * 1000;
-  private final ConfigSetsHandlerApi configSetsHandlerApi = new ConfigSetsHandlerApi(this);
-
   /**
    * Overloaded ctor to inject CoreContainer into the handler.
    *
@@ -86,6 +83,14 @@ public class ConfigSetsHandler extends RequestHandlerBase implements PermissionN
     this.coreContainer = coreContainer;
   }
 
+  public static String getSuffixedNameForAutoGeneratedConfigSet(String configName) {
+    return configName + AUTOCREATED_CONFIGSET_SUFFIX;
+  }
+
+  public static boolean isAutoGeneratedConfigSet(String configName) {
+    return configName != null && configName.endsWith(AUTOCREATED_CONFIGSET_SUFFIX);
+  }
+
 
   @Override
   public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
@@ -267,10 +272,10 @@ public class ConfigSetsHandler extends RequestHandlerBase implements PermissionN
     return Category.ADMIN;
   }
 
-  enum ConfigSetOperation {
+  public enum ConfigSetOperation {
     CREATE_OP(CREATE) {
       @Override
-      Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
+      public Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
         String baseConfigSetName = req.getParams().get(BASE_CONFIGSET, DEFAULT_CONFIGSET_NAME);
         Map<String, Object> props = CollectionsHandler.copy(req.getParams().required(), null, NAME);
         props.put(BASE_CONFIGSET, baseConfigSetName);
@@ -279,14 +284,14 @@ public class ConfigSetsHandler extends RequestHandlerBase implements PermissionN
     },
     DELETE_OP(DELETE) {
       @Override
-      Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
+      public Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
         return CollectionsHandler.copy(req.getParams().required(), null, NAME);
       }
     },
     @SuppressWarnings({"unchecked"})
     LIST_OP(LIST) {
       @Override
-      Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
+      public Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
         NamedList<Object> results = new NamedList<>();
         SolrZkClient zk = h.coreContainer.getZkController().getZkStateReader().getZkClient();
         ZkConfigManager zkConfigManager = new ZkConfigManager(zk);
@@ -304,7 +309,7 @@ public class ConfigSetsHandler extends RequestHandlerBase implements PermissionN
       this.action = action;
     }
 
-    abstract Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception;
+    public abstract Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception;
 
     public static ConfigSetOperation get(ConfigSetAction action) {
       for (ConfigSetOperation op : values()) {
@@ -315,16 +320,6 @@ public class ConfigSetsHandler extends RequestHandlerBase implements PermissionN
   }
 
   @Override
-  public Collection<Api> getApis() {
-    return configSetsHandlerApi.getApis();
-  }
-
-  @Override
-  public Boolean registerV2() {
-    return Boolean.TRUE;
-  }
-
-  @Override
   public Name getPermissionName(AuthorizationContext ctx) {
     String a = ctx.getParams().get(ConfigSetParams.ACTION);
     if (a != null) {
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandlerApi.java b/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandlerApi.java
deleted file mode 100644
index 30450a8..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandlerApi.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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 org.apache.solr.handler.admin;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.solr.client.solrj.request.CollectionApiMapping;
-import org.apache.solr.client.solrj.request.CollectionApiMapping.ConfigSetMeta;
-import org.apache.solr.handler.admin.ConfigSetsHandler.ConfigSetOperation;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-
-public class ConfigSetsHandlerApi extends BaseHandlerApiSupport {
-
-  final public static String DEFAULT_CONFIGSET_NAME = "_default";
-  final public static String AUTOCREATED_CONFIGSET_SUFFIX = ".AUTOCREATED";
-
-
-  final ConfigSetsHandler configSetHandler;
-  static Collection<ApiCommand> apiCommands = createMapping();
-
-  public static String getSuffixedNameForAutoGeneratedConfigSet(String configName) {
-    return configName + AUTOCREATED_CONFIGSET_SUFFIX;
-  }
-
-  public static boolean isAutoGeneratedConfigSet(String configName) {
-    return configName != null && configName.endsWith(AUTOCREATED_CONFIGSET_SUFFIX);
-  }
-
-  private static Collection<ApiCommand> createMapping() {
-    Map<ConfigSetMeta, ApiCommand> result = new EnumMap<>(ConfigSetMeta.class);
-
-    for (ConfigSetMeta meta : ConfigSetMeta.values())
-      for (ConfigSetOperation op : ConfigSetOperation.values()) {
-        if (op.action == meta.action) {
-          result.put(meta, new ApiCommand() {
-            @Override
-            public CollectionApiMapping.CommandMeta meta() {
-              return meta;
-            }
-
-            @Override
-            public void invoke(SolrQueryRequest req, SolrQueryResponse rsp, BaseHandlerApiSupport apiHandler) throws Exception {
-              ((ConfigSetsHandlerApi) apiHandler).configSetHandler.invokeAction(req, rsp, op.action);
-            }
-          });
-        }
-      }
-
-    for (ConfigSetMeta meta : ConfigSetMeta.values()) {
-      if(result.get(meta) == null){
-        throw new RuntimeException("No implementation for "+ meta.name());
-      }
-    }
-
-    return result.values();
-  }
-
-  public ConfigSetsHandlerApi(ConfigSetsHandler configSetHandler) {
-    this.configSetHandler = configSetHandler;
-  }
-
-
-  @Override
-  protected Collection<ApiCommand> getCommands() {
-    return apiCommands;
-  }
-
-  @Override
-  protected List<CollectionApiMapping.V2EndPoint> getEndPoints() {
-    return Arrays.asList(CollectionApiMapping.ConfigSetEndPoint.values());
-  }
-
-}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionApiMapping.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionApiMapping.java
index 9d35e40..91227e0 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionApiMapping.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionApiMapping.java
@@ -30,7 +30,6 @@ import java.util.stream.Stream;
 
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.common.params.CollectionParams.CollectionAction;
-import org.apache.solr.common.params.ConfigSetParams.ConfigSetAction;
 import org.apache.solr.common.util.CommandOperation;
 import org.apache.solr.common.util.Pair;
 import org.apache.solr.common.util.Utils;
@@ -38,9 +37,6 @@ import org.apache.solr.common.util.Utils;
 import static org.apache.solr.client.solrj.SolrRequest.METHOD.DELETE;
 import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
 import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;
-import static org.apache.solr.client.solrj.request.CollectionApiMapping.ConfigSetEndPoint.CONFIG_COMMANDS;
-import static org.apache.solr.client.solrj.request.CollectionApiMapping.ConfigSetEndPoint.CONFIG_DEL;
-import static org.apache.solr.client.solrj.request.CollectionApiMapping.ConfigSetEndPoint.LIST_CONFIG;
 import static org.apache.solr.client.solrj.request.CollectionApiMapping.EndPoint.CLUSTER_ALIASES;
 import static org.apache.solr.client.solrj.request.CollectionApiMapping.EndPoint.COLLECTIONS;
 import static org.apache.solr.client.solrj.request.CollectionApiMapping.EndPoint.COLLECTIONS_COMMANDS;
@@ -181,23 +177,6 @@ public class CollectionApiMapping {
             NAME, "collection",
             "propertyName", "name",
             "propertyValue", "value")),
-/*    ADD_ROLE(CLUSTER_CMD,
-        POST,
-        ADDROLE,
-        "add-role",null),*/
-/*    REMOVE_ROLE(CLUSTER_CMD,
-        POST,
-        REMOVEROLE,
-        "remove-role",null),*/
-
-  /*  SET_CLUSTER_PROPERTY(CLUSTER_CMD,
-        POST,
-        CLUSTERPROP,
-        "set-property",null),*/
-   /* SET_CLUSTER_PROPERTY_OBJ(CLUSTER_CMD,
-        POST,
-        null,
-        "set-obj-property", null),*/
     BACKUP_COLLECTION(COLLECTIONS_COMMANDS,
         POST,
         BACKUP,
@@ -360,60 +339,6 @@ public class CollectionApiMapping {
     String getSpecName();
   }
 
-  public enum ConfigSetMeta implements CommandMeta {
-    LIST(LIST_CONFIG, GET,null, ConfigSetAction.LIST),
-    CREATE(CONFIG_COMMANDS, POST, "create", ConfigSetAction.CREATE),
-    DEL(CONFIG_DEL,  DELETE, null, ConfigSetAction.DELETE)
-    ;
-    public final ConfigSetEndPoint endPoint;
-    public final SolrRequest.METHOD method;
-    public final String cmdName;
-    public final ConfigSetAction action;
-
-
-    ConfigSetMeta(ConfigSetEndPoint endPoint, SolrRequest.METHOD method, String cmdName, ConfigSetAction action) {
-      this.cmdName = cmdName;
-      this.endPoint = endPoint;
-      this.method = method;
-      this.action = action;
-    }
-
-    @Override
-    public String getName() {
-      return cmdName;
-    }
-
-    @Override
-    public SolrRequest.METHOD getHttpMethod() {
-      return method;
-    }
-
-    @Override
-    public V2EndPoint getEndPoint() {
-      return endPoint;
-    }
-
-
-  }
-  public enum ConfigSetEndPoint implements V2EndPoint {
-    LIST_CONFIG("cluster.configs"),
-    CONFIG_COMMANDS("cluster.configs.Commands"),
-    CONFIG_DEL("cluster.configs.delete");
-
-    public final String spec;
-
-    ConfigSetEndPoint(String spec) {
-      this.spec = spec;
-    }
-
-    @Override
-    public String getSpecName() {
-      return spec;
-    }
-  }
-
-
-
   @SuppressWarnings({"unchecked", "rawtypes"})
   private static Collection<String> getParamNames_(CommandOperation op, CommandMeta command) {
     Object o = op.getCommandData();
diff --git a/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/CreateConfigInfo.java
similarity index 67%
copy from solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
copy to solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/CreateConfigInfo.java
index f56f1b2..5cd10b6 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/CreateConfigInfo.java
@@ -14,18 +14,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.solr.common;
+package org.apache.solr.client.solrj.request.beans;
 
 import java.util.Map;
 
-/**This is to facilitate just in time creation of objects before writing
- * it to the response.
- */
-public interface MapSerializable {
-  /**Use the passed map to minimize object creation.
-   * Do not keep a reference to the passed map and reuse it.
-   * it may be reused by the framework
-   */
-  @SuppressWarnings({"rawtypes"})
-  Map toMap(Map<String, Object> map);
+import org.apache.solr.common.annotation.JsonProperty;
+import org.apache.solr.common.util.ReflectMapWriter;
+
+public class CreateConfigInfo implements ReflectMapWriter {
+  @JsonProperty(required = true)
+  public String name;
+  @JsonProperty
+  public String baseConfigSet;
+  @JsonProperty
+  public Map<String,Object> properties;
+
 }
diff --git a/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java b/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
index f56f1b2..14f06d7 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
+++ b/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
@@ -26,6 +26,5 @@ public interface MapSerializable {
    * Do not keep a reference to the passed map and reuse it.
    * it may be reused by the framework
    */
-  @SuppressWarnings({"rawtypes"})
-  Map toMap(Map<String, Object> map);
+  Map<String,Object> toMap(Map<String, Object> map);
 }
diff --git a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
index 7266410..f98f269 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
@@ -41,7 +41,7 @@ public interface MapWriter extends MapSerializable , NavigableObject {
 
   @Override
   @SuppressWarnings({"unchecked", "rawtypes"})
-  default Map toMap(Map<String, Object> map) {
+  default Map<String, Object> toMap(Map<String, Object> map) {
     try {
       writeMap(new EntryWriter() {
         @Override
diff --git a/solr/solrj/src/resources/apispec/cluster.configs.Commands.json b/solr/solrj/src/resources/apispec/cluster.configs.Commands.json
deleted file mode 100644
index f8b3b3a..0000000
--- a/solr/solrj/src/resources/apispec/cluster.configs.Commands.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "documentation": "https://lucene.apache.org/solr/guide/configsets-api.html#configsets-create",
-  "description": "Create configsets.",
-  "methods": [
-    "POST"
-  ],
-  "url": {
-    "paths": [
-      "/cluster/configs"]
-  },
-  "commands": {
-    "create": {
-      "type" :"object",
-      "description": "Create a configset, based on another configset already in ZooKeeper.",
-      "documentation": "https://lucene.apache.org/solr/guide/configsets-api.html#configsets-create",
-      "properties": {
-        "name" :{
-          "type" :"string",
-          "description" : "The name of the configset to be created."
-        },
-        "baseConfigSet":{
-          "type" : "string",
-          "description" :"The existing configset to copy as the basis for the new one."
-        },
-        "properties" : {
-          "type":"object",
-          "description": "Additional key-value pairs, in the form of 'ConfigSetProp.<key>=<value>', as needed. These properties will override the same properties in the base configset.",
-          "additionalProperties" : true
-        }
-      },
-      "required" : ["name"]
-    }
-  }
-}
diff --git a/solr/solrj/src/resources/apispec/cluster.configs.delete.json b/solr/solrj/src/resources/apispec/cluster.configs.delete.json
deleted file mode 100644
index 20985b8..0000000
--- a/solr/solrj/src/resources/apispec/cluster.configs.delete.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-  "documentation": "https://lucene.apache.org/solr/guide/configsets-api.html#configsets-delete",
-  "description": "Delete configsets. The name of the configset to delete must be provided as a path parameter.",
-  "methods": [
-    "DELETE"
-  ],
-  "url": {
-    "paths": [
-      "/cluster/configs/{name}"
-    ]
-  }
-}
diff --git a/solr/solrj/src/resources/apispec/cluster.configs.json b/solr/solrj/src/resources/apispec/cluster.configs.json
deleted file mode 100644
index 45d91d9..0000000
--- a/solr/solrj/src/resources/apispec/cluster.configs.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-  "documentation": "https://lucene.apache.org/solr/guide/configsets-api.html#configsets-list",
-  "description": "List all configsets in the cluster.",
-  "methods": [
-    "GET"
-  ],
-  "url": {
-    "paths": [
-      "/cluster/configs"
-    ]
-  }
-}


[lucene-solr] 02/02: SOLR-14890: Refactor code to use annotations for cluster API

Posted by no...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

noble pushed a commit to branch jira/solr14890
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 1423dd495d225799801f01c819b9250696997157
Author: noble <no...@apache.org>
AuthorDate: Wed Sep 23 17:29:19 2020 +1000

    SOLR-14890: Refactor code to use annotations for cluster API
---
 solr/solrj/src/java/org/apache/solr/common/MapSerializable.java       | 3 ++-
 solr/solrj/src/java/org/apache/solr/common/MapWriter.java             | 2 +-
 solr/solrj/src/java/org/apache/solr/common/MapWriterMap.java          | 4 ++--
 .../solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java | 1 -
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java b/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
index 14f06d7..f56f1b2 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
+++ b/solr/solrj/src/java/org/apache/solr/common/MapSerializable.java
@@ -26,5 +26,6 @@ public interface MapSerializable {
    * Do not keep a reference to the passed map and reuse it.
    * it may be reused by the framework
    */
-  Map<String,Object> toMap(Map<String, Object> map);
+  @SuppressWarnings({"rawtypes"})
+  Map toMap(Map<String, Object> map);
 }
diff --git a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
index f98f269..7266410 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
@@ -41,7 +41,7 @@ public interface MapWriter extends MapSerializable , NavigableObject {
 
   @Override
   @SuppressWarnings({"unchecked", "rawtypes"})
-  default Map<String, Object> toMap(Map<String, Object> map) {
+  default Map toMap(Map<String, Object> map) {
     try {
       writeMap(new EntryWriter() {
         @Override
diff --git a/solr/solrj/src/java/org/apache/solr/common/MapWriterMap.java b/solr/solrj/src/java/org/apache/solr/common/MapWriterMap.java
index 8b35c96..c5f6164 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapWriterMap.java
+++ b/solr/solrj/src/java/org/apache/solr/common/MapWriterMap.java
@@ -51,8 +51,8 @@ public class MapWriterMap implements MapWriter {
 
 
   @Override
-  @SuppressWarnings({"rawtypes"})
-  public Map toMap(Map<String, Object> map) {
+  @SuppressWarnings("unchecked")
+  public Map<String,Object> toMap(Map<String, Object> map) {
     return delegate;
   }
 }
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java b/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java
index b4807e3..d539088 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java
@@ -39,7 +39,6 @@ public class JsonValidatorTest extends SolrTestCaseJ4  {
     checkSchema("cluster.security.RuleBasedAuthorization");
     checkSchema("core.config.Commands");
     checkSchema("core.SchemaEdit");
-    checkSchema("cluster.configs.Commands");
   }