lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject lucene-solr:apiv2: SOLR-8029: _introspect for per core handlers must return the full path
Date Mon, 09 Jan 2017 10:26:16 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/apiv2 d9caa8082 -> 049cb10a2


SOLR-8029: _introspect for per core handlers must return the full path


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/049cb10a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/049cb10a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/049cb10a

Branch: refs/heads/apiv2
Commit: 049cb10a21a4fdfa180c1931fdf901c1067f13ab
Parents: d9caa80
Author: Noble Paul <noble@apache.org>
Authored: Mon Jan 9 20:56:05 2017 +1030
Committer: Noble Paul <noble@apache.org>
Committed: Mon Jan 9 20:56:05 2017 +1030

----------------------------------------------------------------------
 .../src/java/org/apache/solr/api/ApiBag.java    | 26 +++++++++++++++++---
 .../java/org/apache/solr/api/V2HttpCall.java    |  2 +-
 .../java/org/apache/solr/core/PluginBag.java    |  2 +-
 .../org/apache/solr/handler/BlobHandler.java    |  2 +-
 .../apache/solr/request/SolrQueryRequest.java   |  5 ++++
 .../apache/solr/servlet/SolrRequestParsers.java |  5 ++++
 .../src/resources/apispec/core.system.blob.json | 20 +++++++++++++++
 .../apispec/core.system.blob.upload.json        | 12 +++++++++
 .../core/src/resources/apispec/system.blob.json | 20 ---------------
 .../resources/apispec/system.blob.upload.json   | 12 ---------
 .../solr/handler/admin/TestCollectionAPIs.java  |  2 +-
 .../solr/handler/admin/TestConfigsApi.java      |  5 +---
 .../solr/handler/admin/TestCoreAdminApis.java   |  2 +-
 13 files changed, 71 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/java/org/apache/solr/api/ApiBag.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/api/ApiBag.java b/solr/core/src/java/org/apache/solr/api/ApiBag.java
index 143792e..2cadcf3 100644
--- a/solr/core/src/java/org/apache/solr/api/ApiBag.java
+++ b/solr/core/src/java/org/apache/solr/api/ApiBag.java
@@ -28,6 +28,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -54,10 +56,15 @@ import static org.apache.solr.common.util.ValidatingJsonMap.NOT_NULL;
 import static org.apache.solr.common.util.StrUtils.formatString;
 
 public class ApiBag {
+  private final boolean isCoreSpecific;
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   private final Map<String, PathTrie<Api>> apis = new ConcurrentHashMap<>();
 
+  public ApiBag(boolean isCoreSpecific) {
+    this.isCoreSpecific = isCoreSpecific;
+  }
+
   public synchronized void register(Api api, Map<String, String> nameSubstitutes) {
     try {
       validateAndRegister(api, nameSubstitutes);
@@ -74,7 +81,7 @@ public class ApiBag {
 
   private void validateAndRegister(Api api, Map<String, String> nameSubstitutes) {
     ValidatingJsonMap spec = api.getSpec();
-    Api introspect = new IntrospectApi(api);
+    Api introspect = new IntrospectApi(api, isCoreSpecific);
     List<String> methods = spec.getList("methods", ENUM_OF, SUPPORTED_METHODS);
     for (String method : methods) {
       PathTrie<Api> registry = apis.get(method);
@@ -109,10 +116,12 @@ public class ApiBag {
 
   public static class IntrospectApi extends  Api {
     Api baseApi;
+    final boolean isCoreSpecific;
 
-    protected IntrospectApi( Api base) {
+    protected IntrospectApi(Api base, boolean isCoreSpecific) {
       super(EMPTY_SPEC);
       this.baseApi = base;
+      this.isCoreSpecific = isCoreSpecific;
     }
 
     public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
@@ -120,7 +129,7 @@ public class ApiBag {
       String cmd = req.getParams().get("command");
       ValidatingJsonMap result = null;
       if (cmd == null) {
-        result = baseApi.getSpec();
+        result = isCoreSpecific ? ValidatingJsonMap.getDeepCopy(baseApi.getSpec(), 5, true)
: baseApi.getSpec();
       } else {
         ValidatingJsonMap specCopy = ValidatingJsonMap.getDeepCopy(baseApi.getSpec(), 5,
true);
         ValidatingJsonMap commands = specCopy.getMap("commands", null);
@@ -130,6 +139,17 @@ public class ApiBag {
         }
         result = specCopy;
       }
+      if (isCoreSpecific) {
+        List<String> pieces = req.getHttpSolrCall() == null ? null : ((V2HttpCall)
req.getHttpSolrCall()).pieces;
+        if (pieces != null) {
+          String prefix = "/" + pieces.get(0) + "/" + pieces.get(1);
+          List<String> paths = result.getMap("url", NOT_NULL).getList("paths", NOT_NULL);
+          result.getMap("url", NOT_NULL).put("paths",
+              paths.stream()
+                  .map(s -> prefix + s)
+                  .collect(Collectors.toList()));
+        }
+      }
       List l = (List) rsp.getValues().get("spec");
       if (l == null) rsp.getValues().add("spec", l = new ArrayList());
       l.add(result);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java b/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
index 52f44f6..4cffb3f 100644
--- a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
+++ b/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
@@ -63,7 +63,7 @@ import static org.apache.solr.util.PathTrie.getPathSegments;
 public class V2HttpCall extends HttpSolrCall {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   private Api api;
-  private List<String> pieces;
+  List<String> pieces;
   private String prefix;
   HashMap<String, String> parts = new HashMap<>();
   static final Set<String> knownPrefixes = ImmutableSet.of("cluster", "node", "collections",
"cores", "c");

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/java/org/apache/solr/core/PluginBag.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/PluginBag.java b/solr/core/src/java/org/apache/solr/core/PluginBag.java
index 4a380fb..ad8bdec 100644
--- a/solr/core/src/java/org/apache/solr/core/PluginBag.java
+++ b/solr/core/src/java/org/apache/solr/core/PluginBag.java
@@ -74,7 +74,7 @@ public class PluginBag<T> implements AutoCloseable {
    * Pass needThreadSafety=true if plugins can be added and removed concurrently with lookups.
    */
   public PluginBag(Class<T> klass, SolrCore core, boolean needThreadSafety) {
-    this.apiBag = klass == SolrRequestHandler.class ? new ApiBag() : null;
+    this.apiBag = klass == SolrRequestHandler.class ? new ApiBag(core != null) : null;
     this.core = core;
     this.klass = klass;
     // TODO: since reads will dominate writes, we could also think about creating a new instance
of a map each time it changes.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java
index 69d0608..f5b49ea 100644
--- a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java
@@ -287,6 +287,6 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitial
 
   @Override
   public Collection<Api> getApis() {
-    return ApiBag.wrapRequestHandlers(this, "system.blob", "system.blob.upload");
+    return ApiBag.wrapRequestHandlers(this, "core.system.blob", "core.system.blob.upload");
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java b/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
index d975be8..a494ec4 100644
--- a/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
+++ b/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
@@ -21,6 +21,7 @@ import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.ContentStream;
 import org.apache.solr.core.SolrCore;
+import org.apache.solr.servlet.HttpSolrCall;
 import org.apache.solr.util.CommandOperation;
 import org.apache.solr.util.RTimerTree;
 
@@ -117,6 +118,10 @@ public interface SolrQueryRequest extends AutoCloseable {
   default String getHttpMethod() {
     return (String) getContext().get("httpMethod");
   }
+
+  default HttpSolrCall getHttpSolrCall() {
+    return null;
+  }
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
index bf2d814..94a8e7d 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
@@ -245,6 +245,11 @@ public class SolrRequestParsers
         }
         return Collections.EMPTY_MAP;
       }
+
+      @Override
+      public HttpSolrCall getHttpSolrCall() {
+        return httpSolrCall;
+      }
     };
     if( streams != null && streams.size() > 0 ) {
       q.setContentStreams( streams );

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/resources/apispec/core.system.blob.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/core.system.blob.json b/solr/core/src/resources/apispec/core.system.blob.json
new file mode 100644
index 0000000..47f0bba
--- /dev/null
+++ b/solr/core/src/resources/apispec/core.system.blob.json
@@ -0,0 +1,20 @@
+{
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/Blob+Store+API",
+  "description": "Lists blobs in the blob store (.system collection). The list can be limited
by name or name and version.",
+  "methods": [
+    "GET"
+  ],
+  "url": {
+    "paths": [
+      "/blob",
+      "/blob/{name}",
+      "/blob/{name}/{version}"
+    ],
+    "params": {
+      "wt": {
+        "type":"string",
+        "description": "Use the value 'filestream' to get the file content. Use other response
writers (such as xml, or json) to fetch only the metadata."
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/resources/apispec/core.system.blob.upload.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/core.system.blob.upload.json b/solr/core/src/resources/apispec/core.system.blob.upload.json
new file mode 100644
index 0000000..1b6c6d5
--- /dev/null
+++ b/solr/core/src/resources/apispec/core.system.blob.upload.json
@@ -0,0 +1,12 @@
+{
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/Blob+Store+API",
+  "description": "Uploads a blob to the blob store (.system collection).",
+  "methods": [
+    "POST"
+  ],
+  "url": {
+    "paths": [
+      "/blob/{name}"
+    ]
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/resources/apispec/system.blob.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/system.blob.json b/solr/core/src/resources/apispec/system.blob.json
deleted file mode 100644
index e021b4e..0000000
--- a/solr/core/src/resources/apispec/system.blob.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-  "documentation": "https://cwiki.apache.org/confluence/display/solr/Blob+Store+API",
-  "description": "Lists blobs in the blob store (.system collection). The list can be limited
by name or name and version.",
-  "methods": [
-    "GET"
-  ],
-  "url": {
-    "paths": [
-      "/blob",
-      "/blob/{name}",
-      "/blob/{name}/{version}"
-    ]
-  },
-  "params": {
-    "wt": {
-      "type":"string",
-      "description": "Use the value 'filestream' to get the file content. Use other response
writers (such as xml, or json) to fetch only the metadata."
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/resources/apispec/system.blob.upload.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/system.blob.upload.json b/solr/core/src/resources/apispec/system.blob.upload.json
deleted file mode 100644
index 1b6c6d5..0000000
--- a/solr/core/src/resources/apispec/system.blob.upload.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-  "documentation": "https://cwiki.apache.org/confluence/display/solr/Blob+Store+API",
-  "description": "Uploads a blob to the blob store (.system collection).",
-  "methods": [
-    "POST"
-  ],
-  "url": {
-    "paths": [
-      "/blob/{name}"
-    ]
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java b/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
index e2ced9c..5e6b34d 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
@@ -56,7 +56,7 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
 
   public void testCommands() throws Exception {
     MockCollectionsHandler collectionsHandler = new MockCollectionsHandler();
-    ApiBag apiBag = new ApiBag();
+    ApiBag apiBag = new ApiBag(false);
     Collection<Api> apis = collectionsHandler.getApis();
     for (Api api : apis) apiBag.register(api, Collections.EMPTY_MAP);
     //test a simple create collection call

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/test/org/apache/solr/handler/admin/TestConfigsApi.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestConfigsApi.java b/solr/core/src/test/org/apache/solr/handler/admin/TestConfigsApi.java
index 49412ac..d2c96a6 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/TestConfigsApi.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestConfigsApi.java
@@ -18,14 +18,11 @@
 package org.apache.solr.handler.admin;
 
 
-import java.util.Collection;
-import java.util.Collections;
 import java.util.Map;
 
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.api.Api;
 import org.apache.solr.api.ApiBag;
-import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.common.cloud.ZkNodeProps;
 import org.apache.solr.response.SolrQueryResponse;
 import org.apache.zookeeper.KeeperException;
@@ -51,7 +48,7 @@ public class TestConfigsApi extends SolrTestCaseJ4 {
         rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result));
       }
     };
-    ApiBag apiBag = new ApiBag();
+    ApiBag apiBag = new ApiBag(false);
     for (Api api : handler.getApis()) apiBag.register(api, EMPTY_MAP);
     compareOutput(apiBag, "/cluster/configs/sample", DELETE, null, null,
         "{name :sample, operation:delete}");

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/049cb10a/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java b/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java
index 08db1b3..f263f5e 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java
@@ -43,7 +43,7 @@ public class TestCoreAdminApis extends SolrTestCaseJ4 {
     CoreContainer mockCC = getCoreContainerMock(calls, new HashMap<>());
 
     CoreAdminHandler  coreAdminHandler = new CoreAdminHandler(mockCC);
-    ApiBag apiBag = new ApiBag();
+    ApiBag apiBag = new ApiBag(false);
     for (Api api : coreAdminHandler.getApis()) {
       apiBag.register(api, Collections.EMPTY_MAP);
     }


Mime
View raw message