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: testcases for configset api
Date Thu, 22 Sep 2016 19:33:31 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/apiv2 3baf6f8b3 -> b957e2ed1


SOLR-8029: testcases for configset api


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

Branch: refs/heads/apiv2
Commit: b957e2ed1f28038e6b0f07dc0f74319d89cb16c2
Parents: 3baf6f8
Author: Noble Paul <noble@apache.org>
Authored: Fri Sep 23 01:03:21 2016 +0530
Committer: Noble Paul <noble@apache.org>
Committed: Fri Sep 23 01:03:21 2016 +0530

----------------------------------------------------------------------
 .../handler/admin/CollectionHandlerApi.java     |  3 +-
 .../solr/handler/admin/ConfigSetsHandler.java   | 33 ++++++-----
 .../handler/admin/ConfigSetsHandlerApi.java     | 12 ++--
 .../apispec/cluster.config.Commands.json        | 30 ----------
 .../apispec/cluster.config.delete.json          | 11 ----
 .../src/resources/apispec/cluster.config.json   | 11 ----
 .../apispec/cluster.configs.Commands.json       | 30 ++++++++++
 .../apispec/cluster.configs.delete.json         | 11 ++++
 .../src/resources/apispec/cluster.configs.json  | 11 ++++
 .../solr/handler/admin/TestCollectionAPIs.java  | 31 +++++-----
 .../solr/handler/admin/TestConfigsApi.java      | 62 ++++++++++++++++++++
 11 files changed, 156 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/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 e30f58d..28fa9f0 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
@@ -26,7 +26,6 @@ import java.util.Map;
 
 import com.google.common.collect.ImmutableMap;
 import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.cloud.OverseerCollectionMessageHandler;
 import org.apache.solr.handler.admin.CollectionsHandler.CollectionOperation;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.response.SolrQueryResponse;
@@ -42,7 +41,7 @@ import static org.apache.solr.handler.admin.CollectionsHandler.CollectionOperati
 
 
 public class CollectionHandlerApi extends BaseHandlerApiSupport {
-  private final CollectionsHandler handler;
+  final CollectionsHandler handler;
 
   public CollectionHandlerApi(CollectionsHandler handler) {
     this.handler = handler;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java
----------------------------------------------------------------------
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 212009b..28092f2 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
@@ -74,10 +74,6 @@ public class ConfigSetsHandler extends RequestHandlerBase {
     this.coreContainer = coreContainer;
   }
 
-  @Override
-  final public void init(NamedList args) {
-
-  }
 
   @Override
   public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
@@ -99,16 +95,7 @@ public class ConfigSetsHandler extends RequestHandlerBase {
       ConfigSetAction action = ConfigSetAction.get(a);
       if (action == null)
         throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " +
a);
-      ConfigSetOperation operation = ConfigSetOperation.get(action);
-      log.info("Invoked ConfigSet Action :{} with params {} ", action.toLower(), req.getParamString());
-      Map<String, Object> result = operation.call(req, rsp, this);
-      if (result != null) {
-        // We need to differentiate between collection and configsets actions since they
currently
-        // use the same underlying queue.
-        result.put(QUEUE_OPERATION, CONFIGSETS_ACTION_PREFIX + operation.action.toLower());
-        ZkNodeProps props = new ZkNodeProps(result);
-        handleResponse(operation.action.toLower(), props, rsp, DEFAULT_ZK_TIMEOUT);
-      }
+      invokeAction(req, rsp, action);
     } else {
       throw new SolrException(ErrorCode.BAD_REQUEST, "action is a required param");
     }
@@ -116,6 +103,24 @@ public class ConfigSetsHandler extends RequestHandlerBase {
     rsp.setHttpCaching(false);
   }
 
+  void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetAction action)
throws Exception {
+    ConfigSetOperation operation = ConfigSetOperation.get(action);
+    log.info("Invoked ConfigSet Action :{} with params {} ", action.toLower(), req.getParamString());
+    Map<String, Object> result = operation.call(req, rsp, this);
+    sendToZk(rsp, operation, result);
+  }
+
+  protected void sendToZk(SolrQueryResponse rsp, ConfigSetOperation operation, Map<String,
Object> result)
+      throws KeeperException, InterruptedException {
+    if (result != null) {
+      // We need to differentiate between collection and configsets actions since they currently
+      // use the same underlying queue.
+      result.put(QUEUE_OPERATION, CONFIGSETS_ACTION_PREFIX + operation.action.toLower());
+      ZkNodeProps props = new ZkNodeProps(result);
+      handleResponse(operation.action.toLower(), props, rsp, DEFAULT_ZK_TIMEOUT);
+    }
+  }
+
   private void handleResponse(String operation, ZkNodeProps m,
       SolrQueryResponse rsp, long timeout) throws KeeperException, InterruptedException {
     long time = System.nanoTime();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandlerApi.java
----------------------------------------------------------------------
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
index 83e5bd4..6be26ce 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandlerApi.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandlerApi.java
@@ -35,7 +35,7 @@ import static org.apache.solr.handler.admin.ConfigSetsHandler.ConfigSetOperation
 
 public class ConfigSetsHandlerApi extends BaseHandlerApiSupport {
 
-  private final ConfigSetsHandler configSetHandler;
+  final ConfigSetsHandler configSetHandler;
 
   public ConfigSetsHandlerApi(ConfigSetsHandler configSetHandler) {
     this.configSetHandler = configSetHandler;
@@ -90,16 +90,14 @@ public class ConfigSetsHandlerApi extends BaseHandlerApiSupport {
 
     @Override
     public void invoke(SolrQueryRequest req, SolrQueryResponse rsp, BaseHandlerApiSupport
apiHandler) throws Exception {
-          op.call(req, rsp,
-              ((ConfigSetsHandlerApi)apiHandler).configSetHandler);
-
+      ((ConfigSetsHandlerApi) apiHandler).configSetHandler.invokeAction(req, rsp, op.action);
     }
 
   }
   enum EndPoint implements V2EndPoint {
-    LIST_CONFIG("cluster.config"),
-    CONFIG_COMMANDS("cluster.config.Commands"),
-    CONFIG_DEL("cluster.config.delete");
+    LIST_CONFIG("cluster.configs"),
+    CONFIG_COMMANDS("cluster.configs.Commands"),
+    CONFIG_DEL("cluster.configs.delete");
 
     public final String spec;
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/resources/apispec/cluster.config.Commands.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.config.Commands.json b/solr/core/src/resources/apispec/cluster.config.Commands.json
deleted file mode 100644
index 305bf25..0000000
--- a/solr/core/src/resources/apispec/cluster.config.Commands.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
-  "documentation": "https://cwiki.apache.org/confluence/display/solr/ConfigSets+API",
-  "methods": [
-    "POST"
-  ],
-  "url": {
-    "paths": [
-      "/cluster/configs"]
-  },
-  "commands": {
-    "create": {
-      "type" :"object",
-      "properties": {
-        "name" :{
-          "type" :"string",
-          "description" : "ConfigSet to be created"
-        },
-        "baseConfigSet":{
-          "type" : "string",
-          "description" :"ConfigSet to copy as a base"
-        },
-        "properties" : {
-          "type":"object",
-          "additionalProperties" : true
-        }
-      },
-      "required" : ["name", "baseConfigSet"]
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/resources/apispec/cluster.config.delete.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.config.delete.json b/solr/core/src/resources/apispec/cluster.config.delete.json
deleted file mode 100644
index ae8dbc3..0000000
--- a/solr/core/src/resources/apispec/cluster.config.delete.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
-  "documentation": "https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-api1",
-  "methods": [
-    "DELETE"
-  ],
-  "url": {
-    "paths": [
-      "/cluster/configs/{name}"
-    ]
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/resources/apispec/cluster.config.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.config.json b/solr/core/src/resources/apispec/cluster.config.json
deleted file mode 100644
index b3d8c23..0000000
--- a/solr/core/src/resources/apispec/cluster.config.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
-  "documentation": "https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-api1",
-  "methods": [
-    "GET"
-  ],
-  "url": {
-    "paths": [
-      "/cluster/configs"
-    ]
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/resources/apispec/cluster.configs.Commands.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.configs.Commands.json b/solr/core/src/resources/apispec/cluster.configs.Commands.json
new file mode 100644
index 0000000..305bf25
--- /dev/null
+++ b/solr/core/src/resources/apispec/cluster.configs.Commands.json
@@ -0,0 +1,30 @@
+{
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/ConfigSets+API",
+  "methods": [
+    "POST"
+  ],
+  "url": {
+    "paths": [
+      "/cluster/configs"]
+  },
+  "commands": {
+    "create": {
+      "type" :"object",
+      "properties": {
+        "name" :{
+          "type" :"string",
+          "description" : "ConfigSet to be created"
+        },
+        "baseConfigSet":{
+          "type" : "string",
+          "description" :"ConfigSet to copy as a base"
+        },
+        "properties" : {
+          "type":"object",
+          "additionalProperties" : true
+        }
+      },
+      "required" : ["name", "baseConfigSet"]
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/resources/apispec/cluster.configs.delete.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.configs.delete.json b/solr/core/src/resources/apispec/cluster.configs.delete.json
new file mode 100644
index 0000000..ae8dbc3
--- /dev/null
+++ b/solr/core/src/resources/apispec/cluster.configs.delete.json
@@ -0,0 +1,11 @@
+{
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-api1",
+  "methods": [
+    "DELETE"
+  ],
+  "url": {
+    "paths": [
+      "/cluster/configs/{name}"
+    ]
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/solr/core/src/resources/apispec/cluster.configs.json
----------------------------------------------------------------------
diff --git a/solr/core/src/resources/apispec/cluster.configs.json b/solr/core/src/resources/apispec/cluster.configs.json
new file mode 100644
index 0000000..b3d8c23
--- /dev/null
+++ b/solr/core/src/resources/apispec/cluster.configs.json
@@ -0,0 +1,11 @@
+{
+  "documentation": "https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-api1",
+  "methods": [
+    "GET"
+  ],
+  "url": {
+    "paths": [
+      "/cluster/configs"
+    ]
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/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 78f9911..e2ced9c 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
@@ -143,10 +143,10 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
 
   }
 
-  ZkNodeProps compareOutput(final ApiBag apiBag, final String path, final SolrRequest.METHOD
method,
+  static ZkNodeProps compareOutput(final ApiBag apiBag, final String path, final SolrRequest.METHOD
method,
                             final String payload, final CoreContainer cc, String expectedOutputMapJson)
throws Exception {
     Pair<SolrQueryRequest, SolrQueryResponse> ctx = makeCall(apiBag, path, method,
payload, cc);
-    ZkNodeProps output = (ZkNodeProps) ctx.first().getContext().get(ZkNodeProps.class.getName());
+    ZkNodeProps output = (ZkNodeProps) ctx.second().getValues().get(ZkNodeProps.class.getName());
     Map expected = (Map) fromJSONString(expectedOutputMapJson);
     assertMapEqual(expected, output);
     return output;
@@ -155,10 +155,10 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
 
   public static Pair<SolrQueryRequest, SolrQueryResponse> makeCall(final ApiBag apiBag,
String path,
                                                                    final SolrRequest.METHOD
method,
-                                    final String payload, final CoreContainer cc) throws
Exception {
+                                                                   final String payload,
final CoreContainer cc) throws Exception {
     SolrParams queryParams = new MultiMapSolrParams(Collections.EMPTY_MAP);
     if (path.indexOf('?') > 0) {
-      String queryStr = path.substring(path.indexOf('?')+1);
+      String queryStr = path.substring(path.indexOf('?') + 1);
       path = path.substring(0, path.indexOf('?'));
       queryParams = SolrRequestParsers.parseQueryString(queryStr);
     }
@@ -166,11 +166,11 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
     Api api = apiBag.lookup(path, method.toString(), parts);
     if (api == null) throw new RuntimeException("No handler at path :" + path);
     SolrQueryResponse rsp = new SolrQueryResponse();
-    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, queryParams){
+    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, queryParams) {
       @Override
       public List<CommandOperation> getCommands(boolean validateInput) {
         if (payload == null) return Collections.emptyList();
-        return ApiBag.getCommandOperations(new StringReader(payload), api.getCommandSchema(),true);
+        return ApiBag.getCommandOperations(new StringReader(payload), api.getCommandSchema(),
true);
       }
 
       @Override
@@ -186,13 +186,13 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
     try {
       api.call(req, rsp);
     } catch (ApiBag.ExceptionWithErrObject e) {
-      throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()) , e);
+      throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()), e);
 
     }
-    return new Pair<>(req,rsp);
+    return new Pair<>(req, rsp);
   }
 
-  private void assertMapEqual(Map expected, ZkNodeProps actual) {
+  private static void assertMapEqual(Map expected, ZkNodeProps actual) {
     assertEquals(errorMessage(expected, actual), expected.size(), actual.getProperties().size());
     for (Object o : expected.entrySet()) {
       Map.Entry e = (Map.Entry) o;
@@ -200,11 +200,11 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
       if (actualVal instanceof String[]) {
         actualVal = Arrays.asList((String[]) actualVal);
       }
-      assertEquals(errorMessage(expected, actual), String.valueOf(e.getValue()),String.valueOf(actualVal));
+      assertEquals(errorMessage(expected, actual), String.valueOf(e.getValue()), String.valueOf(actualVal));
     }
   }
 
-  private String errorMessage(Map expected, ZkNodeProps actual) {
+  private static String errorMessage(Map expected, ZkNodeProps actual) {
     return "expected: " + Utils.toJSONString(expected) + "\nactual: " + Utils.toJSONString(actual);
 
   }
@@ -212,15 +212,18 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
   static class MockCollectionsHandler extends CollectionsHandler {
     LocalSolrQueryRequest req;
 
-    MockCollectionsHandler() { }
+    MockCollectionsHandler() {
+    }
 
     @Override
-    void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer cores, CollectionParams.CollectionAction
action,
+    void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp,
+                      CoreContainer cores,
+                      CollectionParams.CollectionAction action,
                       CollectionOperation operation) throws Exception {
       Map<String, Object> result = operation.execute(req, rsp, this);
       if (result != null) {
         result.put(QUEUE_OPERATION, operation.action.toLower());
-        req.getContext().put(ZkNodeProps.class.getName(),new ZkNodeProps(result) );
+        rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result));
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b957e2ed/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
new file mode 100644
index 0000000..49412ac
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestConfigsApi.java
@@ -0,0 +1,62 @@
+/*
+ * 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.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;
+
+import static java.util.Collections.EMPTY_MAP;
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.DELETE;
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;
+import static org.apache.solr.cloud.Overseer.QUEUE_OPERATION;
+import static org.apache.solr.handler.admin.TestCollectionAPIs.compareOutput;
+
+public class TestConfigsApi extends SolrTestCaseJ4 {
+
+
+  public void testCommands() throws Exception {
+
+    ConfigSetsHandler handler = new ConfigSetsHandler(null) {
+      @Override
+      protected void sendToZk(SolrQueryResponse rsp,
+                              ConfigSetOperation operation,
+                              Map<String, Object> result)
+          throws KeeperException, InterruptedException {
+        result.put(QUEUE_OPERATION, operation.action.toLower());
+        rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result));
+      }
+    };
+    ApiBag apiBag = new ApiBag();
+    for (Api api : handler.getApis()) apiBag.register(api, EMPTY_MAP);
+    compareOutput(apiBag, "/cluster/configs/sample", DELETE, null, null,
+        "{name :sample, operation:delete}");
+
+    compareOutput(apiBag, "/cluster/configs", POST, "{create:{name : newconf, baseConfigSet:
sample }}", null,
+        "{operation:create, name :newconf,  baseConfigSet: sample }");
+  }
+}


Mime
View raw message