mirror of https://github.com/apache/lucene.git
SOLR-10647: move the spec files to solrj
This commit is contained in:
parent
5a34d419b9
commit
c5c05b46c4
|
@ -20,6 +20,7 @@ package org.apache.solr.api;
|
|||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.solr.common.SpecProvider;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
|
|
|
@ -33,6 +33,8 @@ import java.util.stream.Collectors;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SpecProvider;
|
||||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.apache.solr.common.util.Utils;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
import org.apache.solr.core.PluginBag;
|
||||
|
@ -42,9 +44,8 @@ import org.apache.solr.request.SolrRequestHandler;
|
|||
import org.apache.solr.response.SolrQueryResponse;
|
||||
import org.apache.solr.security.AuthorizationContext;
|
||||
import org.apache.solr.security.PermissionNameProvider;
|
||||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.apache.solr.util.JsonSchemaValidator;
|
||||
import org.apache.solr.util.PathTrie;
|
||||
import org.apache.solr.common.util.PathTrie;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -227,12 +228,6 @@ public class ApiBag {
|
|||
}
|
||||
}
|
||||
|
||||
public static SpecProvider getSpec(final String name) {
|
||||
return () -> {
|
||||
return ValidatingJsonMap.parse(APISPEC_LOCATION + name + ".json", APISPEC_LOCATION);
|
||||
};
|
||||
}
|
||||
|
||||
public static class ReqHandlerToApi extends Api implements PermissionNameProvider {
|
||||
SolrRequestHandler rh;
|
||||
|
||||
|
@ -257,13 +252,10 @@ public class ApiBag {
|
|||
|
||||
public static List<Api> wrapRequestHandlers(final SolrRequestHandler rh, String... specs) {
|
||||
ImmutableList.Builder<Api> b = ImmutableList.builder();
|
||||
for (String spec : specs) b.add(new ReqHandlerToApi(rh, ApiBag.getSpec(spec)));
|
||||
for (String spec : specs) b.add(new ReqHandlerToApi(rh, Utils.getSpec(spec)));
|
||||
return b.build();
|
||||
}
|
||||
|
||||
public static final String APISPEC_LOCATION = "apispec/";
|
||||
public static final String INTROSPECT = "/_introspect";
|
||||
|
||||
|
||||
public static final SpecProvider EMPTY_SPEC = () -> ValidatingJsonMap.EMPTY;
|
||||
public static final String HANDLER_NAME = "handlerName";
|
||||
|
@ -276,7 +268,7 @@ public class ApiBag {
|
|||
public void registerLazy(PluginBag.PluginHolder<SolrRequestHandler> holder, PluginInfo info) {
|
||||
String specName = info.attributes.get("spec");
|
||||
if (specName == null) specName = "emptySpec";
|
||||
register(new LazyLoadedApi(ApiBag.getSpec(specName), holder), Collections.singletonMap(HANDLER_NAME, info.attributes.get(NAME)));
|
||||
register(new LazyLoadedApi(Utils.getSpec(specName), holder), Collections.singletonMap(HANDLER_NAME, info.attributes.get(NAME)));
|
||||
}
|
||||
|
||||
public static SpecProvider constructSpec(PluginInfo info) {
|
||||
|
@ -286,7 +278,7 @@ public class ApiBag {
|
|||
Map map = (Map) specObj;
|
||||
return () -> ValidatingJsonMap.getDeepCopy(map, 4, false);
|
||||
} else {
|
||||
return ApiBag.getSpec((String) specObj);
|
||||
return Utils.getSpec((String) specObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.apache.solr.servlet.HttpSolrCall;
|
|||
import org.apache.solr.servlet.SolrDispatchFilter;
|
||||
import org.apache.solr.servlet.SolrRequestParsers;
|
||||
import org.apache.solr.util.JsonSchemaValidator;
|
||||
import org.apache.solr.util.PathTrie;
|
||||
import org.apache.solr.common.util.PathTrie;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -58,7 +58,7 @@ import static org.apache.solr.common.params.CommonParams.WT;
|
|||
import static org.apache.solr.servlet.SolrDispatchFilter.Action.ADMIN;
|
||||
import static org.apache.solr.servlet.SolrDispatchFilter.Action.PASSTHROUGH;
|
||||
import static org.apache.solr.servlet.SolrDispatchFilter.Action.PROCESS;
|
||||
import static org.apache.solr.util.PathTrie.getPathSegments;
|
||||
import static org.apache.solr.common.util.PathTrie.getPathSegments;
|
||||
|
||||
// class that handle the '/v2' path
|
||||
public class V2HttpCall extends HttpSolrCall {
|
||||
|
@ -102,7 +102,7 @@ public class V2HttpCall extends HttpSolrCall {
|
|||
String collectionName = origCorename = corename = pieces.get(1);
|
||||
DocCollection collection = getDocCollection(collectionName);
|
||||
if (collection == null) {
|
||||
if ( ! path.endsWith(ApiBag.INTROSPECT)) {
|
||||
if ( ! path.endsWith(CommonParams.INTROSPECT)) {
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "no such collection or alias");
|
||||
}
|
||||
} else {
|
||||
|
@ -124,7 +124,7 @@ public class V2HttpCall extends HttpSolrCall {
|
|||
}
|
||||
if (core == null) {
|
||||
log.error(">> path: '" + path + "'");
|
||||
if (path.endsWith(ApiBag.INTROSPECT)) {
|
||||
if (path.endsWith(CommonParams.INTROSPECT)) {
|
||||
initAdminRequest(path);
|
||||
return;
|
||||
} else {
|
||||
|
@ -193,7 +193,7 @@ public class V2HttpCall extends HttpSolrCall {
|
|||
Map<String, String> parts) {
|
||||
fullPath = fullPath == null ? path : fullPath;
|
||||
Api api = requestHandlers.v2lookup(path, method, parts);
|
||||
if (api == null && path.endsWith(ApiBag.INTROSPECT)) {
|
||||
if (api == null && path.endsWith(CommonParams.INTROSPECT)) {
|
||||
// the particular http method does not have any ,
|
||||
// just try if any other method has this path
|
||||
api = requestHandlers.v2lookup(path, null, parts);
|
||||
|
@ -234,7 +234,7 @@ public class V2HttpCall extends HttpSolrCall {
|
|||
|
||||
private static CompositeApi getSubPathApi(PluginBag<SolrRequestHandler> requestHandlers, String path, String fullPath, CompositeApi compositeApi) {
|
||||
|
||||
String newPath = path.endsWith(ApiBag.INTROSPECT) ? path.substring(0, path.length() - ApiBag.INTROSPECT.length()) : path;
|
||||
String newPath = path.endsWith(CommonParams.INTROSPECT) ? path.substring(0, path.length() - CommonParams.INTROSPECT.length()) : path;
|
||||
Map<String, Set<String>> subpaths = new LinkedHashMap<>();
|
||||
|
||||
getSubPaths(newPath, requestHandlers.getApiBag(), subpaths);
|
||||
|
@ -244,12 +244,12 @@ public class V2HttpCall extends HttpSolrCall {
|
|||
@Override
|
||||
public void call(SolrQueryRequest req1, SolrQueryResponse rsp) {
|
||||
String prefix = null;
|
||||
prefix = fullPath.endsWith(ApiBag.INTROSPECT) ?
|
||||
fullPath.substring(0, fullPath.length() - ApiBag.INTROSPECT.length()) :
|
||||
prefix = fullPath.endsWith(CommonParams.INTROSPECT) ?
|
||||
fullPath.substring(0, fullPath.length() - CommonParams.INTROSPECT.length()) :
|
||||
fullPath;
|
||||
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;
|
||||
if (e.getKey().endsWith(CommonParams.INTROSPECT)) continue;
|
||||
result.put(prefix + e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.api.Api;
|
||||
import org.apache.solr.api.ApiBag;
|
||||
import org.apache.solr.common.util.Utils;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class UpdateRequestHandlerApi extends UpdateRequestHandler {
|
|||
}
|
||||
|
||||
private Api getApiImpl() {
|
||||
return new Api(ApiBag.getSpec("core.Update")) {
|
||||
return new Api(Utils.getSpec("core.Update")) {
|
||||
@Override
|
||||
public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||
String path = req.getPath();
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Objects;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.solr.api.Api;
|
||||
import org.apache.solr.api.ApiBag;
|
||||
import org.apache.solr.api.ApiSupport;
|
||||
import org.apache.solr.client.solrj.SolrRequest;
|
||||
import org.apache.solr.client.solrj.request.CollectionApiMapping.CommandMeta;
|
||||
|
@ -73,7 +72,7 @@ public abstract class BaseHandlerApiSupport implements ApiSupport {
|
|||
|
||||
private Api getApi(final V2EndPoint op) {
|
||||
final BaseHandlerApiSupport apiHandler = this;
|
||||
return new Api(ApiBag.getSpec(op.getSpecName())) {
|
||||
return new Api(Utils.getSpec(op.getSpecName())) {
|
||||
@Override
|
||||
public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||
SolrParams params = req.getParams();
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.apache.solr.response.SolrQueryResponse;
|
|||
import org.apache.solr.api.Api;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.apache.solr.api.ApiBag.getSpec;
|
||||
import static org.apache.solr.common.util.Utils.getSpec;
|
||||
import static org.apache.solr.common.params.CommonParams.PATH;
|
||||
|
||||
public class InfoHandler extends RequestHandlerBase {
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.solr.security.PermissionNameProvider;
|
|||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.apache.solr.api.Api;
|
||||
import org.apache.solr.api.ApiBag.ReqHandlerToApi;
|
||||
import org.apache.solr.api.SpecProvider;
|
||||
import org.apache.solr.common.SpecProvider;
|
||||
import org.apache.solr.util.JsonSchemaValidator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -264,10 +264,10 @@ public abstract class SecurityConfHandler extends RequestHandlerBase implements
|
|||
synchronized (this) {
|
||||
if (apis == null) {
|
||||
Collection<Api> apis = new ArrayList<>();
|
||||
final SpecProvider authcCommands = ApiBag.getSpec("cluster.security.authentication.Commands");
|
||||
final SpecProvider authzCommands = ApiBag.getSpec("cluster.security.authorization.Commands");
|
||||
apis.add(new ReqHandlerToApi(this, ApiBag.getSpec("cluster.security.authentication")));
|
||||
apis.add(new ReqHandlerToApi(this, ApiBag.getSpec("cluster.security.authorization")));
|
||||
final SpecProvider authcCommands = Utils.getSpec("cluster.security.authentication.Commands");
|
||||
final SpecProvider authzCommands = Utils.getSpec("cluster.security.authorization.Commands");
|
||||
apis.add(new ReqHandlerToApi(this, Utils.getSpec("cluster.security.authentication")));
|
||||
apis.add(new ReqHandlerToApi(this, Utils.getSpec("cluster.security.authorization")));
|
||||
SpecProvider authcSpecProvider = () -> {
|
||||
AuthenticationPlugin authcPlugin = cores.getAuthenticationPlugin();
|
||||
return authcPlugin != null && authcPlugin instanceof SpecProvider ?
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.http.message.BasicHeader;
|
|||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.apache.solr.api.SpecProvider;
|
||||
import org.apache.solr.common.SpecProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.solr.api.ApiBag;
|
||||
import org.apache.solr.api.SpecProvider;
|
||||
import org.apache.solr.common.SpecProvider;
|
||||
import org.apache.solr.common.util.Utils;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -238,7 +238,7 @@ public class RuleBasedAuthorizationPlugin implements AuthorizationPlugin, Config
|
|||
|
||||
@Override
|
||||
public ValidatingJsonMap getSpec() {
|
||||
return ApiBag.getSpec("cluster.security.RuleBasedAuthorization").getSpec();
|
||||
return Utils.getSpec("cluster.security.RuleBasedAuthorization").getSpec();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ import java.util.Set;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.apache.solr.common.util.Utils;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
|
||||
import org.apache.solr.api.ApiBag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class Sha256AuthenticationProvider implements ConfigEditablePlugin, Basi
|
|||
|
||||
@Override
|
||||
public ValidatingJsonMap getSpec() {
|
||||
return ApiBag.getSpec("cluster.security.BasicAuth.Commands").getSpec();
|
||||
return Utils.getSpec("cluster.security.BasicAuth.Commands").getSpec();
|
||||
}
|
||||
|
||||
static final Set<String> supported_ops = ImmutableSet.of("set-user", "delete-user");
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.apache.solr.response.SolrQueryResponse;
|
|||
import org.apache.solr.api.Api;
|
||||
import org.apache.solr.api.V2HttpCall;
|
||||
import org.apache.solr.common.util.CommandOperation;
|
||||
import org.apache.solr.util.PathTrie;
|
||||
import org.apache.solr.common.util.PathTrie;
|
||||
|
||||
import static org.apache.solr.api.ApiBag.EMPTY_SPEC;
|
||||
import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.api.ApiBag;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
import org.apache.solr.common.util.StrUtils;
|
||||
import org.apache.solr.common.util.Utils;
|
||||
|
@ -48,7 +47,7 @@ public class JsonValidatorTest extends SolrTestCaseJ4 {
|
|||
|
||||
|
||||
public void testSchemaValidation() {
|
||||
ValidatingJsonMap spec = ApiBag.getSpec("collections.Commands").getSpec();
|
||||
ValidatingJsonMap spec = Utils.getSpec("collections.Commands").getSpec();
|
||||
Map createSchema = spec.getMap("commands", NOT_NULL).getMap("create-alias", NOT_NULL);
|
||||
JsonSchemaValidator validator = new JsonSchemaValidator(createSchema);
|
||||
List<String> errs = validator.validateJson(Utils.fromJSONString("{name : x, collections: [ c1 , c2]}"));
|
||||
|
@ -181,7 +180,7 @@ public class JsonValidatorTest extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
private void checkSchema(String name) {
|
||||
ValidatingJsonMap spec = ApiBag.getSpec(name).getSpec();
|
||||
ValidatingJsonMap spec = Utils.getSpec(name).getSpec();
|
||||
Map commands = (Map) spec.get("commands");
|
||||
for (Object o : commands.entrySet()) {
|
||||
Map.Entry cmd = (Map.Entry) o;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.solr.api;
|
||||
package org.apache.solr.common;
|
||||
import org.apache.solr.common.util.ValidatingJsonMap;
|
||||
|
||||
/**A generic interface for any class that is capable of providing its specification as a json schema
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.solr.common.params;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
@ -184,7 +185,7 @@ public interface CommonParams {
|
|||
String AUTOSCALING_PATH = "/admin/autoscaling";
|
||||
String AUTOSCALING_DIAGNOSTICS_PATH = "/admin/autoscaling/diagnostics";
|
||||
|
||||
Set<String> ADMIN_PATHS = new HashSet<>(Arrays.asList(
|
||||
Set<String> ADMIN_PATHS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
|
||||
CORES_HANDLER_PATH,
|
||||
COLLECTIONS_HANDLER_PATH,
|
||||
CONFIGSETS_HANDLER_PATH,
|
||||
|
@ -192,7 +193,9 @@ public interface CommonParams {
|
|||
AUTHZ_PATH,
|
||||
METRICS_PATH,
|
||||
AUTOSCALING_PATH,
|
||||
AUTOSCALING_DIAGNOSTICS_PATH));
|
||||
AUTOSCALING_DIAGNOSTICS_PATH)));
|
||||
String APISPEC_LOCATION = "apispec/";
|
||||
String INTROSPECT = "/_introspect";
|
||||
|
||||
/** valid values for: <code>echoParams</code> */
|
||||
enum EchoParamStyle {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.solr.util;
|
||||
package org.apache.solr.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
|
@ -42,8 +42,10 @@ import org.apache.http.util.EntityUtils;
|
|||
import org.apache.solr.common.IteratorWriter;
|
||||
import org.apache.solr.common.MapWriter;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SpecProvider;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.common.cloud.ZkOperation;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.noggit.CharArr;
|
||||
import org.noggit.JSONParser;
|
||||
|
@ -302,4 +304,10 @@ public class Utils {
|
|||
|
||||
public static final Pattern ARRAY_ELEMENT_INDEX = Pattern
|
||||
.compile("(\\S*?)\\[(\\d+)\\]");
|
||||
|
||||
public static SpecProvider getSpec(final String name) {
|
||||
return () -> {
|
||||
return ValidatingJsonMap.parse(CommonParams.APISPEC_LOCATION + name + ".json", CommonParams.APISPEC_LOCATION);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.solr.api;
|
||||
package org.apache.solr.common.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -23,7 +23,7 @@ import java.util.Set;
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.util.PathTrie;
|
||||
import org.apache.solr.common.util.PathTrie;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
Loading…
Reference in New Issue