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 }");
}
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]);
}
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;
}
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<>()));
}
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);
}
Aggregations