mirror of https://github.com/apache/lucene.git
SOLR-14894: Use annotations to implement V2 collection APIs
This commit is contained in:
parent
1c9c1509fa
commit
565c5b1ac4
|
@ -88,6 +88,7 @@ import org.apache.solr.core.backup.repository.BackupRepository;
|
|||
import org.apache.solr.core.backup.repository.BackupRepositoryFactory;
|
||||
import org.apache.solr.filestore.PackageStoreAPI;
|
||||
import org.apache.solr.handler.ClusterAPI;
|
||||
import org.apache.solr.handler.CollectionsAPI;
|
||||
import org.apache.solr.handler.RequestHandlerBase;
|
||||
import org.apache.solr.handler.SnapShooter;
|
||||
import org.apache.solr.handler.admin.CollectionsHandler;
|
||||
|
@ -720,6 +721,7 @@ public class CoreContainer {
|
|||
createHandler(ZK_PATH, ZookeeperInfoHandler.class.getName(), ZookeeperInfoHandler.class);
|
||||
createHandler(ZK_STATUS_PATH, ZookeeperStatusHandler.class.getName(), ZookeeperStatusHandler.class);
|
||||
collectionsHandler = createHandler(COLLECTIONS_HANDLER_PATH, cfg.getCollectionsHandlerClass(), CollectionsHandler.class);
|
||||
containerHandlers.getApiBag().registerObject(new CollectionsAPI(collectionsHandler));
|
||||
configSetsHandler = createHandler(CONFIGSETS_HANDLER_PATH, cfg.getConfigSetsHandlerClass(), ConfigSetsHandler.class);
|
||||
ClusterAPI clusterAPI = new ClusterAPI(collectionsHandler, configSetsHandler);
|
||||
containerHandlers.getApiBag().registerObject(clusterAPI);
|
||||
|
|
|
@ -56,6 +56,9 @@ import static org.apache.solr.security.PermissionNameProvider.Name.COLL_READ_PER
|
|||
import static org.apache.solr.security.PermissionNameProvider.Name.CONFIG_EDIT_PERM;
|
||||
import static org.apache.solr.security.PermissionNameProvider.Name.CONFIG_READ_PERM;
|
||||
|
||||
/** All V2 APIs that have a prefix of /api/cluster/
|
||||
*
|
||||
*/
|
||||
public class ClusterAPI {
|
||||
private final CollectionsHandler collectionsHandler;
|
||||
private final ConfigSetsHandler configSetsHandler;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package org.apache.solr.handler;
|
||||
|
||||
import org.apache.solr.api.EndPoint;
|
||||
import org.apache.solr.common.cloud.ZkStateReader;
|
||||
import org.apache.solr.common.params.CollectionParams.CollectionAction;
|
||||
import org.apache.solr.handler.admin.CollectionsHandler;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
|
||||
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.common.params.CommonParams.NAME;
|
||||
import static org.apache.solr.security.PermissionNameProvider.Name.COLL_EDIT_PERM;
|
||||
import static org.apache.solr.security.PermissionNameProvider.Name.COLL_READ_PERM;
|
||||
|
||||
/**
|
||||
* All V2 APIs for collection management
|
||||
*
|
||||
*/
|
||||
public class CollectionsAPI {
|
||||
|
||||
private final CollectionsHandler collectionsHandler;
|
||||
|
||||
public CollectionsAPI(CollectionsHandler collectionsHandler) {
|
||||
this.collectionsHandler = collectionsHandler;
|
||||
}
|
||||
|
||||
@EndPoint(
|
||||
path = {"/c", "/collections"},
|
||||
method = GET,
|
||||
permission = COLL_READ_PERM)
|
||||
public void getCollections(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
|
||||
CollectionsHandler.CollectionOperation.LIST_OP.execute(req, rsp, collectionsHandler);
|
||||
}
|
||||
|
||||
@EndPoint(path = {"/c/{collection}", "/collections/{collection}"},
|
||||
method = DELETE,
|
||||
permission = COLL_EDIT_PERM)
|
||||
public void deleteCollection(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
|
||||
req = ClusterAPI.wrapParams(req, "action",
|
||||
CollectionAction.DELETE.toString(),
|
||||
NAME, req.getPathTemplateValues().get(ZkStateReader.COLLECTION_PROP));
|
||||
collectionsHandler.handleRequestBody(req, rsp);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,17 +17,41 @@
|
|||
|
||||
package org.apache.solr.handler.admin;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.api.*;
|
||||
import org.apache.solr.api.Api;
|
||||
import org.apache.solr.api.ApiBag;
|
||||
import org.apache.solr.api.Command;
|
||||
import org.apache.solr.api.EndPoint;
|
||||
import org.apache.solr.api.PayloadObj;
|
||||
import org.apache.solr.api.V2HttpCall;
|
||||
import org.apache.solr.api.V2HttpCall.CompositeApi;
|
||||
import org.apache.solr.client.solrj.SolrRequest;
|
||||
import org.apache.solr.common.annotation.JsonProperty;
|
||||
import org.apache.solr.common.params.MapSolrParams;
|
||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||
import org.apache.solr.common.params.SolrParams;
|
||||
import org.apache.solr.common.util.*;
|
||||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.apache.solr.common.util.ContentStream;
|
||||
import org.apache.solr.common.util.ContentStreamBase;
|
||||
import org.apache.solr.common.util.JsonSchemaValidator;
|
||||
import org.apache.solr.common.util.PathTrie;
|
||||
import org.apache.solr.common.util.ReflectMapWriter;
|
||||
import org.apache.solr.common.util.StrUtils;
|
||||
import org.apache.solr.common.util.Utils;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.PluginBag;
|
||||
import org.apache.solr.handler.CollectionsAPI;
|
||||
import org.apache.solr.handler.PingRequestHandler;
|
||||
import org.apache.solr.handler.SchemaHandler;
|
||||
import org.apache.solr.handler.SolrConfigHandler;
|
||||
|
@ -38,16 +62,13 @@ import org.apache.solr.request.SolrRequestHandler;
|
|||
import org.apache.solr.response.SolrQueryResponse;
|
||||
import org.apache.solr.security.PermissionNameProvider;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.apache.solr.api.ApiBag.EMPTY_SPEC;
|
||||
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.common.params.CommonParams.*;
|
||||
import static org.apache.solr.common.params.CommonParams.COLLECTIONS_HANDLER_PATH;
|
||||
import static org.apache.solr.common.params.CommonParams.CONFIGSETS_HANDLER_PATH;
|
||||
import static org.apache.solr.common.params.CommonParams.CORES_HANDLER_PATH;
|
||||
import static org.apache.solr.common.util.ValidatingJsonMap.NOT_NULL;
|
||||
|
||||
public class TestApiFramework extends SolrTestCaseJ4 {
|
||||
|
@ -57,7 +78,9 @@ public class TestApiFramework extends SolrTestCaseJ4 {
|
|||
Map<String, Object> out = new HashMap<>();
|
||||
CoreContainer mockCC = TestCoreAdminApis.getCoreContainerMock(calls, out);
|
||||
PluginBag<SolrRequestHandler> containerHandlers = new PluginBag<>(SolrRequestHandler.class, null, false);
|
||||
containerHandlers.put(COLLECTIONS_HANDLER_PATH, new TestCollectionAPIs.MockCollectionsHandler());
|
||||
TestCollectionAPIs.MockCollectionsHandler collectionsHandler = new TestCollectionAPIs.MockCollectionsHandler();
|
||||
containerHandlers.put(COLLECTIONS_HANDLER_PATH, collectionsHandler);
|
||||
containerHandlers.getApiBag().registerObject(new CollectionsAPI(collectionsHandler));
|
||||
containerHandlers.put(CORES_HANDLER_PATH, new CoreAdminHandler(mockCC));
|
||||
containerHandlers.put(CONFIGSETS_HANDLER_PATH, new ConfigSetsHandler(mockCC));
|
||||
out.put("getRequestHandlers", containerHandlers);
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.solr.common.util.Pair;
|
|||
import org.apache.solr.common.util.Utils;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.handler.ClusterAPI;
|
||||
import org.apache.solr.handler.CollectionsAPI;
|
||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
|
@ -83,6 +84,7 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
|
|||
ApiBag apiBag;
|
||||
try (MockCollectionsHandler collectionsHandler = new MockCollectionsHandler()) {
|
||||
apiBag = new ApiBag(false);
|
||||
apiBag.registerObject(new CollectionsAPI(collectionsHandler));
|
||||
Collection<Api> apis = collectionsHandler.getApis();
|
||||
for (Api api : apis) apiBag.register(api, Collections.emptyMap());
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ 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.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;
|
||||
import static org.apache.solr.client.solrj.request.CollectionApiMapping.EndPoint.COLLECTION_STATE;
|
||||
import static org.apache.solr.client.solrj.request.CollectionApiMapping.EndPoint.PER_COLLECTION;
|
||||
|
@ -56,7 +55,6 @@ import static org.apache.solr.common.params.CommonParams.NAME;
|
|||
public class CollectionApiMapping {
|
||||
|
||||
public enum Meta implements CommandMeta {
|
||||
GET_COLLECTIONS(COLLECTIONS, GET, LIST),
|
||||
GET_A_COLLECTION(COLLECTION_STATE, GET, CLUSTERSTATUS),
|
||||
LIST_ALIASES(CLUSTER_ALIASES, GET, LISTALIASES),
|
||||
CREATE_COLLECTION(COLLECTIONS_COMMANDS,
|
||||
|
@ -70,12 +68,6 @@ public class CollectionApiMapping {
|
|||
),
|
||||
Utils.makeMap("property.", "properties.")),
|
||||
|
||||
DELETE_COLL(EndPoint.PER_COLLECTION_DELETE,
|
||||
DELETE,
|
||||
CollectionAction.DELETE,
|
||||
CollectionAction.DELETE.toLower(),
|
||||
Utils.makeMap(NAME, "collection")),
|
||||
|
||||
RELOAD_COLL(PER_COLLECTION,
|
||||
POST,
|
||||
RELOAD,
|
||||
|
@ -313,10 +305,8 @@ public class CollectionApiMapping {
|
|||
public enum EndPoint implements V2EndPoint {
|
||||
CLUSTER_ALIASES("cluster.aliases"),
|
||||
COLLECTIONS_COMMANDS("collections.Commands"),
|
||||
COLLECTIONS("collections"),
|
||||
COLLECTION_STATE("collections.collection"),
|
||||
PER_COLLECTION("collections.collection.Commands"),
|
||||
PER_COLLECTION_DELETE("collections.collection.delete"),
|
||||
PER_COLLECTION_SHARDS_COMMANDS("collections.collection.shards.Commands"),
|
||||
PER_COLLECTION_PER_SHARD_COMMANDS("collections.collection.shards.shard.Commands"),
|
||||
PER_COLLECTION_PER_SHARD_DELETE("collections.collection.shards.shard.delete"),
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"documentation": "https://lucene.apache.org/solr/guide/cluster-node-management.html",
|
||||
"description": "Provides general information about the available nodes of the cluster.",
|
||||
"methods": [
|
||||
"GET"
|
||||
],
|
||||
"url": {
|
||||
"paths": [
|
||||
"/cluster/nodes"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"documentation": "https://lucene.apache.org/solr/guide/collection-management.html#delete",
|
||||
"description": "Deletes a collection.",
|
||||
"methods": [
|
||||
"DELETE"
|
||||
],
|
||||
"url": {
|
||||
"paths": [
|
||||
"/collections/{collection}",
|
||||
"/c/{collection}"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"documentation": "https://lucene.apache.org/solr/guide/collection-management.html#list",
|
||||
"description": "List all available collections and their properties.",
|
||||
"methods": [
|
||||
"GET"
|
||||
],
|
||||
"url": {
|
||||
"paths": [
|
||||
"/collections",
|
||||
"/c"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue