use of org.apache.solr.api.ApiBag in project lucene-solr by apache.
the class TestCollectionAPIs method testCommands.
public void testCommands() throws Exception {
MockCollectionsHandler collectionsHandler = new MockCollectionsHandler();
ApiBag apiBag = new ApiBag(false);
Collection<Api> apis = collectionsHandler.getApis();
for (Api api : apis) apiBag.register(api, Collections.emptyMap());
//test a simple create collection call
compareOutput(apiBag, "/collections", POST, "{create:{name:'newcoll', config:'schemaless', numShards:2, replicationFactor:2 }}", null, "{name:newcoll, fromApi:'true', replicationFactor:'2', collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create}");
compareOutput(apiBag, "/collections", POST, "{create:{name:'newcoll', config:'schemaless', numShards:2, nrtReplicas:2 }}", null, "{name:newcoll, fromApi:'true', nrtReplicas:'2', collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create}");
compareOutput(apiBag, "/collections", POST, "{create:{name:'newcoll', config:'schemaless', numShards:2, nrtReplicas:2, tlogReplicas:2, pullReplicas:2 }}", null, "{name:newcoll, fromApi:'true', nrtReplicas:'2', tlogReplicas:'2', pullReplicas:'2', collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create}");
//test a create collection with custom properties
compareOutput(apiBag, "/collections", POST, "{create:{name:'newcoll', config:'schemaless', numShards:2, replicationFactor:2, properties:{prop1:'prop1val', prop2: prop2val} }}", null, "{name:newcoll, fromApi:'true', replicationFactor:'2', collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create, property.prop1:prop1val, property.prop2:prop2val}");
compareOutput(apiBag, "/collections", POST, "{create-alias:{name: aliasName , collections:[c1,c2] }}", null, "{operation : createalias, name: aliasName, collections:[c1,c2] }");
compareOutput(apiBag, "/collections", POST, "{delete-alias:{ name: aliasName}}", null, "{operation : deletealias, name: aliasName}");
compareOutput(apiBag, "/collections/collName", POST, "{reload:{}}", null, "{name:collName, operation :reload}");
compareOutput(apiBag, "/collections/collName", DELETE, null, null, "{name:collName, operation :delete}");
compareOutput(apiBag, "/collections/collName/shards/shard1", DELETE, null, null, "{collection:collName, shard: shard1 , operation :deleteshard }");
compareOutput(apiBag, "/collections/collName/shards/shard1/replica1?deleteDataDir=true&onlyIfDown=true", DELETE, null, null, "{collection:collName, shard: shard1, replica :replica1 , deleteDataDir:'true', onlyIfDown: 'true', operation :deletereplica }");
compareOutput(apiBag, "/collections/collName/shards", POST, "{split:{shard:shard1, ranges: '0-1f4,1f5-3e8,3e9-5dc', coreProperties : {prop1:prop1Val, prop2:prop2Val} }}", null, "{collection: collName , shard : shard1, ranges :'0-1f4,1f5-3e8,3e9-5dc', operation : splitshard, property.prop1:prop1Val, property.prop2: prop2Val}");
compareOutput(apiBag, "/collections/collName/shards", POST, "{add-replica:{shard: shard1, node: 'localhost_8978' , coreProperties : {prop1:prop1Val, prop2:prop2Val} }}", null, "{collection: collName , shard : shard1, node :'localhost_8978', operation : addreplica, property.prop1:prop1Val, property.prop2: prop2Val}");
compareOutput(apiBag, "/collections/collName/shards", POST, "{split:{ splitKey:id12345, coreProperties : {prop1:prop1Val, prop2:prop2Val} }}", null, "{collection: collName , split.key : id12345 , operation : splitshard, property.prop1:prop1Val, property.prop2: prop2Val}");
compareOutput(apiBag, "/collections/collName/shards", POST, "{add-replica:{shard: shard1, node: 'localhost_8978' , type:'TLOG' }}", null, "{collection: collName , shard : shard1, node :'localhost_8978', operation : addreplica, type: TLOG}");
compareOutput(apiBag, "/collections/collName/shards", POST, "{add-replica:{shard: shard1, node: 'localhost_8978' , type:'PULL' }}", null, "{collection: collName , shard : shard1, node :'localhost_8978', operation : addreplica, type: PULL}");
assertErrorContains(apiBag, "/collections/collName/shards", POST, "{add-replica:{shard: shard1, node: 'localhost_8978' , type:'foo' }}", null, "Value of enum must be one of");
compareOutput(apiBag, "/collections/collName", POST, "{add-replica-property : {name:propA , value: VALA, shard: shard1, replica:replica1}}", null, "{collection: collName, shard: shard1, replica : replica1 , property : propA , operation : addreplicaprop, property.value : 'VALA'}");
compareOutput(apiBag, "/collections/collName", POST, "{delete-replica-property : {property: propA , shard: shard1, replica:replica1} }", null, "{collection: collName, shard: shard1, replica : replica1 , property : propA , operation : deletereplicaprop}");
compareOutput(apiBag, "/collections/collName", POST, "{modify : {rule : ['replica:*, cores:<5'], autoAddReplicas : false} }", null, "{collection: collName, operation : modifycollection , autoAddReplicas : 'false', rule : [{replica: '*', cores : '<5' }]}");
compareOutput(apiBag, "/cluster", POST, "{add-role : {role : overseer, node : 'localhost_8978'} }", null, "{operation : addrole ,role : overseer, node : 'localhost_8978'}");
compareOutput(apiBag, "/cluster", POST, "{remove-role : {role : overseer, node : 'localhost_8978'} }", null, "{operation : removerole ,role : overseer, node : 'localhost_8978'}");
compareOutput(apiBag, "/collections/coll1", POST, "{balance-shard-unique : {property: preferredLeader} }", null, "{operation : balanceshardunique ,collection : coll1, property : preferredLeader}");
compareOutput(apiBag, "/collections/coll1", POST, "{migrate-docs : {forwardTimeout: 1800, target: coll2, splitKey: 'a123!'} }", null, "{operation : migrate ,collection : coll1, target.collection:coll2, forward.timeout:1800, split.key:'a123!'}");
}
use of org.apache.solr.api.ApiBag 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.ApiBag 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.ApiBag 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