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: missing mappings for /v2/cluster path
Date Mon, 25 Apr 2016 09:11:40 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/apiv2 4a1f9c86d -> 52aa4478d


SOLR-8029: missing mappings for /v2/cluster 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/52aa4478
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/52aa4478
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/52aa4478

Branch: refs/heads/apiv2
Commit: 52aa4478de9d1ef352c28b4beccf5c442170d46b
Parents: 4a1f9c8
Author: Noble Paul <noble@apache.org>
Authored: Mon Apr 25 14:41:25 2016 +0530
Committer: Noble Paul <noble@apache.org>
Committed: Mon Apr 25 14:41:25 2016 +0530

----------------------------------------------------------------------
 .../src/java/org/apache/solr/api/ApiBag.java    | 49 +++++++++++---------
 .../java/org/apache/solr/api/V2HttpCall.java    | 31 ++++++++-----
 .../handler/admin/BaseHandlerApiSupport.java    |  8 ++++
 .../handler/admin/CollectionHandlerApi.java     |  4 ++
 .../apispec/cluster.commandstatus.json          | 11 +++++
 solr/core/src/resources/apispec/cluster.json    |  5 +-
 6 files changed, 71 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/52aa4478/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 886c1d5..649606b 100644
--- a/solr/core/src/java/org/apache/solr/api/ApiBag.java
+++ b/solr/core/src/java/org/apache/solr/api/ApiBag.java
@@ -94,7 +94,7 @@ public class ApiBag {
 
   private void validateAndRegister(Api api, Map<String, String> nameSubstitutes) {
     Map2 spec = api.getSpec();
-    Api introspect = getIntrospect(api);
+    Api introspect = new IntrospectApi(api);
     List<String> methods = spec.getList("methods", ENUM_OF, SUPPORTED_METHODS);
     for (String method : methods) {
       PathTrie<Api> registry = apis.get(method);
@@ -128,30 +128,35 @@ public class ApiBag {
     }
   }
 
-  private Api getIntrospect(final Api baseApi) {
-    return new Api(EMPTY_SPEC) {
-      @Override
-      public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
-
-        String cmd = req.getParams().get("command");
-        Map2 result = null;
-        if (cmd == null) {
-          result = baseApi.getSpec();
-        } else {
-          Map2 specCopy = Map2.getDeepCopy(baseApi.getSpec(), 5, true);
-          Map2 commands = specCopy.getMap("commands", null);
-          if (commands != null) {
-            Map2 m = commands.getMap(cmd, null);
-            specCopy.put("commands", Collections.singletonMap(cmd, m));
-          }
-          result = specCopy;
+  public static class IntrospectApi extends  Api {
+    Api baseApi;
+
+    protected IntrospectApi( Api base) {
+      super(EMPTY_SPEC);
+      this.baseApi = base;
+    }
+
+    public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
+
+      String cmd = req.getParams().get("command");
+      Map2 result = null;
+      if (cmd == null) {
+        result = baseApi.getSpec();
+      } else {
+        Map2 specCopy = Map2.getDeepCopy(baseApi.getSpec(), 5, true);
+        Map2 commands = specCopy.getMap("commands", null);
+        if (commands != null) {
+          Map2 m = commands.getMap(cmd, null);
+          specCopy.put("commands", Collections.singletonMap(cmd, m));
         }
-        List l = (List) rsp.getValues().get("spec");
-        if (l == null) rsp.getValues().add("spec", l = new ArrayList());
-        l.add(result);
+        result = specCopy;
       }
-    };
+      List l = (List) rsp.getValues().get("spec");
+      if (l == null) rsp.getValues().add("spec", l = new ArrayList());
+      l.add(result);
+    }
   }
+
   public static Map<String, JsonSchemaValidator> getParsedSchema(Map2 commands) {
     Map<String,JsonSchemaValidator> validators =  new HashMap<>();
     for (Object o : commands.entrySet()) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/52aa4478/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 f513b69..515f572 100644
--- a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
+++ b/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
@@ -179,22 +179,29 @@ public class V2HttpCall extends HttpSolrCall {
       if (containerHandlerLookup && commonPaths4ContainerLevelAndCoreLevel.contains(prefix))
return null;
 
 
-      Map<String, Set<String>> subpaths = new LinkedHashMap<>();
-
-      getSubPaths(path, requestHandlers.getApiBag(), subpaths);
-      if (!containerHandlerLookup) getSubPaths(fullPath, cores.getRequestHandlers().getApiBag(),
subpaths);
+      Map<String, Set<String>> subpaths = getSubPaths(requestHandlers, path,
cores, fullPath, containerHandlerLookup);
 
       if (subpaths.isEmpty()) {
         throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No valid handler for
path :" + path);
       } else {
-        return getSubPathImpl(subpaths, fullPath);
+        return getSubPathImpl(subpaths, fullPath, true);
       }
     }
-    if (api.getSpec() == Map2.EMPTY)
-      api = mergeIntrospect(requestHandlers, path, method, parts);
+    if (api instanceof ApiBag.IntrospectApi) {
+      api = mergeIntrospect(requestHandlers, path, parts,
+          getSubPathImpl(getSubPaths(requestHandlers, path,cores,fullPath, containerHandlerLookup),
path, true ));
+    }
     return api;
   }
 
+  private static Map<String, Set<String>> getSubPaths(PluginBag<SolrRequestHandler>
requestHandlers, String path, CoreContainer cores, String fullPath, boolean containerHandlerLookup)
{
+    Map<String, Set<String>> subpaths = new LinkedHashMap<>();
+
+    getSubPaths(path, requestHandlers.getApiBag(), subpaths);
+    if (!containerHandlerLookup) getSubPaths(fullPath, cores.getRequestHandlers().getApiBag(),
subpaths);
+    return subpaths;
+  }
+
   private static void getSubPaths(String path, ApiBag bag, Map<String, Set<String>>
pathsVsMethod) {
     for (SolrRequest.METHOD m : SolrRequest.METHOD.values()) {
       PathTrie<Api> registry = bag.getRegistry(m.toString());
@@ -211,7 +218,8 @@ public class V2HttpCall extends HttpSolrCall {
   }
 
   private static Api mergeIntrospect(PluginBag<SolrRequestHandler> requestHandlers,
-                                     String path, String method, Map<String, String>
parts) {
+                                     String path,Map<String, String> parts,
+                                     Api subPath) {
     Api api;
     final Map<String, Api> apis = new LinkedHashMap<>();
     for (String m : SolrRequest.SUPPORTED_METHODS) {
@@ -224,23 +232,24 @@ public class V2HttpCall extends HttpSolrCall {
         String method = req.getParams().get("method");
         Set<Api> added = new HashSet<>();
         for (Map.Entry<String, Api> e : apis.entrySet()) {
-          if (method == null || e.getKey().equals(req.getHttpMethod())) {
+          if (method == null || e.getKey().equals(method)) {
             if (!added.contains(e.getValue())) {
               e.getValue().call(req, rsp);
               added.add(e.getValue());
             }
           }
         }
+        subPath.call(req, rsp);
       }
     };
     return api;
   }
 
-  private static Api getSubPathImpl(final Map<String, Set<String>> subpaths,
String path) {
+  private static Api getSubPathImpl(final Map<String, Set<String>> subpaths,
String path,  boolean addMsg) {
     return new Api(() -> Map2.EMPTY) {
       @Override
       public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
-        rsp.add("msg", "Invalid path, try the following");
+        if(addMsg) rsp.add("msg", "Invalid path, try the following");
         LinkedHashMap<String, Set<String>> result = new LinkedHashMap<>(subpaths.size());
         for (Map.Entry<String, Set<String>> e : subpaths.entrySet()) {
           if (e.getKey().endsWith(ApiBag.INTROSPECT)) continue;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/52aa4478/solr/core/src/java/org/apache/solr/handler/admin/BaseHandlerApiSupport.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/BaseHandlerApiSupport.java b/solr/core/src/java/org/apache/solr/handler/admin/BaseHandlerApiSupport.java
index aabcc10..aaf229b 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/BaseHandlerApiSupport.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/BaseHandlerApiSupport.java
@@ -100,6 +100,14 @@ public abstract class BaseHandlerApiSupport implements ApiSupport {
               rsp.add("error", "No support for : " + method + " at :" + req.getPath());
               return;
             }
+            if (commands.size() > 1) {
+              for (ApiCommand command : commands) {
+                if (command.getName().equals(req.getPath())) {
+                  commands = Collections.singletonList(command);
+                  break;
+                }
+              }
+            }
             wrapParams(req, new CommandOperation("", Collections.EMPTY_MAP), commands.get(0),
true);
             invokeUrl(commands.get(0), req, rsp);
           }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/52aa4478/solr/core/src/java/org/apache/solr/handler/admin/CollectionHandlerApi.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionHandlerApi.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionHandlerApi.java
index 0790366..a3c7168 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionHandlerApi.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionHandlerApi.java
@@ -69,6 +69,9 @@ public class CollectionHandlerApi extends BaseHandlerApiSupport {
 
   enum Cmd implements ApiCommand<CollectionHandlerApi> {
     GET_COLLECTIONS(EndPoint.COLLECTIONS, GET, LIST_OP),
+    GET_CLUSTER(EndPoint.CLUSTER, GET, LIST_OP, "/cluster", null),
+    GET_CLUSTER_OVERSEER(EndPoint.CLUSTER, GET, OVERSEERSTATUS_OP, "/cluster/overseer", null),
+    GET_CLUSTER_CMD(EndPoint.CLUSTER_CMD, GET, REQUESTSTATUS_OP),
     GET_A_COLLECTION(EndPoint.COLLECTION_STATE, GET, CLUSTERSTATUS_OP),
     CREATE_COLLECTION(EndPoint.COLLECTIONS_COMMANDS,
         POST,
@@ -255,6 +258,7 @@ public class CollectionHandlerApi extends BaseHandlerApiSupport {
 
   enum EndPoint implements V2EndPoint {
     CLUSTER("cluster"),
+    CLUSTER_CMD("cluster.commandstatus"),
     COLLECTIONS_COMMANDS("collections.Commands"),
     COLLECTIONS("collections"),
     COLLECTION_STATE("collection"),

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/52aa4478/solr/core/src/resources/apispec/cluster.commandstatus.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.commandstatus.json b/solr/core/src/resources/apispec/cluster.commandstatus.json
new file mode 100644
index 0000000..f608299
--- /dev/null
+++ b/solr/core/src/resources/apispec/cluster.commandstatus.json
@@ -0,0 +1,11 @@
+{
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/Config+API",
+  "methods": [
+    "GET"
+  ],
+  "url": {
+    "paths": [
+      "/cluster/command-status/{id}"
+    ]
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/52aa4478/solr/core/src/resources/apispec/cluster.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.json b/solr/core/src/resources/apispec/cluster.json
index afff2b3..434e9d5 100644
--- a/solr/core/src/resources/apispec/cluster.json
+++ b/solr/core/src/resources/apispec/cluster.json
@@ -7,10 +7,7 @@
     "paths": [
       "/cluster",
       "/cluster/overseer",
-      "/cluster/nodes",
-      "/cluster/command-status",
-      "/cluster/command-status/{id}",
-      "/cluster/command-status/{id}"
+      "/cluster/nodes"
     ]
   }
 }


Mime
View raw message