Search in sources :

Example 6 with Api

use of org.apache.solr.api.Api in project lucene-solr by apache.

the class TestConfigsApi method testCommands.

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(false);
    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, immutable: false }");
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ApiBag(org.apache.solr.api.ApiBag) Api(org.apache.solr.api.Api) Map(java.util.Map)

Example 7 with Api

use of org.apache.solr.api.Api in project lucene-solr by apache.

the class TestCoreAdminApis method testCalls.

public void testCalls() throws Exception {
    Map<String, Object[]> calls = new HashMap<>();
    CoreContainer mockCC = getCoreContainerMock(calls, new HashMap<>());
    CoreAdminHandler coreAdminHandler = new CoreAdminHandler(mockCC);
    ApiBag apiBag = new ApiBag(false);
    for (Api api : coreAdminHandler.getApis()) {
        apiBag.register(api, Collections.EMPTY_MAP);
    }
    TestCollectionAPIs.makeCall(apiBag, "/cores", SolrRequest.METHOD.POST, "{create:{name: hello, instanceDir : someDir, schema: 'schema.xml'}}", mockCC);
    Object[] params = calls.get("create");
    assertEquals("hello", params[0]);
    assertEquals(fromJSONString("{schema : schema.xml}"), params[2]);
    TestCollectionAPIs.makeCall(apiBag, "/cores/core1", SolrRequest.METHOD.POST, "{swap:{with: core2}}", mockCC);
    params = calls.get("swap");
    assertEquals("core1", params[0]);
    assertEquals("core2", params[1]);
    TestCollectionAPIs.makeCall(apiBag, "/cores/core1", SolrRequest.METHOD.POST, "{rename:{to: core2}}", mockCC);
    params = calls.get("swap");
    assertEquals("core1", params[0]);
    assertEquals("core2", params[1]);
    TestCollectionAPIs.makeCall(apiBag, "/cores/core1", SolrRequest.METHOD.POST, "{unload:{deleteIndex : true}}", mockCC);
    params = calls.get("unload");
    assertEquals("core1", params[0]);
    assertEquals(Boolean.TRUE, params[1]);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) HashMap(java.util.HashMap) ApiBag(org.apache.solr.api.ApiBag) Utils.fromJSONString(org.apache.solr.common.util.Utils.fromJSONString) Api(org.apache.solr.api.Api)

Example 8 with Api

use of org.apache.solr.api.Api in project lucene-solr by apache.

the class SecurityConfHandler method getApis.

@Override
public Collection<Api> getApis() {
    if (apis == null) {
        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")));
                SpecProvider authcSpecProvider = () -> {
                    AuthenticationPlugin authcPlugin = cores.getAuthenticationPlugin();
                    return authcPlugin != null && authcPlugin instanceof SpecProvider ? ((SpecProvider) authcPlugin).getSpec() : authcCommands.getSpec();
                };
                apis.add(new ReqHandlerToApi(this, authcSpecProvider) {

                    @Override
                    public synchronized Map<String, JsonSchemaValidator> getCommandSchema() {
                        // the cached commandSchema
                        if (SecurityConfHandler.this.authcPlugin != cores.getAuthenticationPlugin())
                            commandSchema = null;
                        SecurityConfHandler.this.authcPlugin = cores.getAuthenticationPlugin();
                        return super.getCommandSchema();
                    }
                });
                SpecProvider authzSpecProvider = () -> {
                    AuthorizationPlugin authzPlugin = cores.getAuthorizationPlugin();
                    return authzPlugin != null && authzPlugin instanceof SpecProvider ? ((SpecProvider) authzPlugin).getSpec() : authzCommands.getSpec();
                };
                apis.add(new ApiBag.ReqHandlerToApi(this, authzSpecProvider) {

                    @Override
                    public synchronized Map<String, JsonSchemaValidator> getCommandSchema() {
                        // the cached commandSchema
                        if (SecurityConfHandler.this.authzPlugin != cores.getAuthorizationPlugin())
                            commandSchema = null;
                        SecurityConfHandler.this.authzPlugin = cores.getAuthorizationPlugin();
                        return super.getCommandSchema();
                    }
                });
                this.apis = ImmutableList.copyOf(apis);
            }
        }
    }
    return this.apis;
}
Also used : ReqHandlerToApi(org.apache.solr.api.ApiBag.ReqHandlerToApi) ArrayList(java.util.ArrayList) AuthenticationPlugin(org.apache.solr.security.AuthenticationPlugin) AuthorizationPlugin(org.apache.solr.security.AuthorizationPlugin) ApiBag(org.apache.solr.api.ApiBag) SpecProvider(org.apache.solr.api.SpecProvider) ReqHandlerToApi(org.apache.solr.api.ApiBag.ReqHandlerToApi) Api(org.apache.solr.api.Api) ReqHandlerToApi(org.apache.solr.api.ApiBag.ReqHandlerToApi) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 9 with Api

use of org.apache.solr.api.Api in project lucene-solr by apache.

the class TestApiFramework method testTrailingTemplatePaths.

public void testTrailingTemplatePaths() {
    PathTrie<Api> registry = new PathTrie<>();
    Api api = new Api(EMPTY_SPEC) {

        @Override
        public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
        }
    };
    Api intropsect = new ApiBag.IntrospectApi(api, false);
    ApiBag.registerIntrospect(Collections.emptyMap(), registry, "/c/.system/blob/{name}", intropsect);
    ApiBag.registerIntrospect(Collections.emptyMap(), registry, "/c/.system/{x}/{name}", intropsect);
    assertEquals(intropsect, registry.lookup("/c/.system/blob/random_string/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/blob/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/v1/_introspect", new HashMap<>()));
    assertEquals(intropsect, registry.lookup("/c/.system/v1/v2/_introspect", new HashMap<>()));
}
Also used : PathTrie(org.apache.solr.util.PathTrie) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) HashMap(java.util.HashMap) CompositeApi(org.apache.solr.api.V2HttpCall.CompositeApi) Api(org.apache.solr.api.Api)

Example 10 with Api

use of org.apache.solr.api.Api in project lucene-solr by apache.

the class TestCollectionAPIs method makeCall.

public static Pair<SolrQueryRequest, SolrQueryResponse> makeCall(final ApiBag apiBag, String path, final SolrRequest.METHOD method, final String payload, final CoreContainer cc) throws Exception {
    SolrParams queryParams = new MultiMapSolrParams(Collections.emptyMap());
    if (path.indexOf('?') > 0) {
        String queryStr = path.substring(path.indexOf('?') + 1);
        path = path.substring(0, path.indexOf('?'));
        queryParams = SolrRequestParsers.parseQueryString(queryStr);
    }
    final HashMap<String, String> parts = new HashMap<>();
    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) {

        @Override
        public List<CommandOperation> getCommands(boolean validateInput) {
            if (payload == null)
                return Collections.emptyList();
            return ApiBag.getCommandOperations(new StringReader(payload), api.getCommandSchema(), true);
        }

        @Override
        public Map<String, String> getPathTemplateValues() {
            return parts;
        }

        @Override
        public String getHttpMethod() {
            return method.toString();
        }
    };
    try {
        api.call(req, rsp);
    } catch (ApiBag.ExceptionWithErrObject e) {
        throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()), e);
    }
    return new Pair<>(req, rsp);
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) HashMap(java.util.HashMap) CommandOperation(org.apache.solr.common.util.CommandOperation) ApiBag(org.apache.solr.api.ApiBag) Utils.fromJSONString(org.apache.solr.common.util.Utils.fromJSONString) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) StringReader(java.io.StringReader) SolrParams(org.apache.solr.common.params.SolrParams) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) Api(org.apache.solr.api.Api) Pair(org.apache.solr.common.util.Pair)

Aggregations

Api (org.apache.solr.api.Api)11 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)7 HashMap (java.util.HashMap)5 ApiBag (org.apache.solr.api.ApiBag)5 CompositeApi (org.apache.solr.api.V2HttpCall.CompositeApi)3 CommandOperation (org.apache.solr.common.util.CommandOperation)3 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)3 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)3 Map (java.util.Map)2 SolrException (org.apache.solr.common.SolrException)2 SolrParams (org.apache.solr.common.params.SolrParams)2 Utils.fromJSONString (org.apache.solr.common.util.Utils.fromJSONString)2 CoreContainer (org.apache.solr.core.CoreContainer)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ReqHandlerToApi (org.apache.solr.api.ApiBag.ReqHandlerToApi)1 ApiSupport (org.apache.solr.api.ApiSupport)1 SpecProvider (org.apache.solr.api.SpecProvider)1 SolrRequest (org.apache.solr.client.solrj.SolrRequest)1