You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2016/12/21 20:08:20 UTC

[2/2] lucene-solr:apiv2: SOLR-8029: get introspect working for endpoints that don't include named cores or collections

SOLR-8029: get introspect working for endpoints that don't include named cores or collections


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

Branch: refs/heads/apiv2
Commit: 03eca9c111e68b74e4d9a160bcf5fb3cbc0d3ddf
Parents: 6798877
Author: Steve Rowe <sa...@apache.org>
Authored: Wed Dec 21 15:08:06 2016 -0500
Committer: Steve Rowe <sa...@apache.org>
Committed: Wed Dec 21 15:08:06 2016 -0500

----------------------------------------------------------------------
 .../java/org/apache/solr/api/V2HttpCall.java    | 55 ++++++++++++--------
 1 file changed, 34 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/03eca9c1/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 5d8bc15..52f44f6 100644
--- a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
+++ b/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
@@ -91,10 +91,7 @@ public class V2HttpCall extends HttpSolrCall {
         if (api != null) {
           isCompositeApi = api instanceof CompositeApi;
           if (!isCompositeApi) {
-            solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);
-            solrReq.getContext().put(CoreContainer.class.getName(), cores);
-            requestType = AuthorizationContext.RequestType.ADMIN;
-            action = ADMIN;
+            initAdminRequest(path);
             return;
           }
         }
@@ -103,28 +100,36 @@ public class V2HttpCall extends HttpSolrCall {
       if ("c".equals(prefix) || "collections".equals(prefix)) {
         String collectionName = origCorename = corename = pieces.get(1);
         DocCollection collection = getDocCollection(collectionName);
-        if (collection == null)
-          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "no such collection or alias");
-
-        boolean isPreferLeader = false;
-        if (path.endsWith("/update") || path.contains("/update/")) {
-          isPreferLeader = true;
-        }
-        core = getCoreByCollection(collection.getName(), isPreferLeader);
-        if (core == null) {
-          //this collection exists , but this node does not have a replica for that collection
-          //todo find a better way to compute remote
-          extractRemotePath(corename, origCorename, 0);
-          return;
+        if (collection == null) {
+           if ( ! path.endsWith(ApiBag.INTROSPECT)) {
+            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "no such collection or alias");
+          }
+        } else {
+          boolean isPreferLeader = false;
+          if (path.endsWith("/update") || path.contains("/update/")) {
+            isPreferLeader = true;
+          }
+          core = getCoreByCollection(collection.getName(), isPreferLeader);
+          if (core == null) {
+            //this collection exists , but this node does not have a replica for that collection
+            //todo find a better way to compute remote
+            extractRemotePath(corename, origCorename, 0);
+            return;
+          }
         }
-
       } else if ("cores".equals(prefix)) {
         origCorename = corename = pieces.get(1);
         core = cores.getCore(corename);
       }
-      if (core == null)
-        throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "no core retrieved for " + corename);
-
+      if (core == null) {
+        log.error(">> path: '" + path + "'");
+        if (path.endsWith(ApiBag.INTROSPECT)) {
+          initAdminRequest(path);
+          return;
+        } else {
+          throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "no core retrieved for " + corename);
+        }
+      }
 
       this.path = path = path.substring(prefix.length() + pieces.get(1).length() + 2);
       Api apiInfo = getApiInfo(core.getRequestHandlers(), path, req.getMethod(), fullPath, parts);
@@ -151,6 +156,13 @@ public class V2HttpCall extends HttpSolrCall {
     }
   }
 
+  private void initAdminRequest(String path) throws Exception {
+    solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);
+    solrReq.getContext().put(CoreContainer.class.getName(), cores);
+    requestType = AuthorizationContext.RequestType.ADMIN;
+    action = ADMIN;
+  }
+
   protected void parseRequest() throws Exception {
     config = core.getSolrConfig();
     // get or create/cache the parser for the core
@@ -185,6 +197,7 @@ public class V2HttpCall extends HttpSolrCall {
       // just try if any other method has this path
       api = requestHandlers.v2lookup(path, null, parts);
     }
+    log.error(">> api class: " + (api == null ? "null" : api.getClass().getSimpleName())); // nocommit
 
     if (api == null) {
       return getSubPathApi(requestHandlers, path, fullPath, new CompositeApi(null));