mirror of https://github.com/apache/lucene.git
SOLR-7995: Add a LIST command to ConfigSets API
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1706920 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6098ca73a3
commit
e04a4e9abc
|
@ -163,6 +163,8 @@ New Features
|
|||
|
||||
* SOLR-8053: Basic auth support in SolrJ (noble)
|
||||
|
||||
* SOLR-7995: Add a LIST command to ConfigSets API (Gregory Chanan)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -18,14 +18,18 @@ package org.apache.solr.handler.admin;
|
|||
*/
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrResponse;
|
||||
import org.apache.solr.cloud.Overseer;
|
||||
import org.apache.solr.cloud.OverseerSolrResponse;
|
||||
import org.apache.solr.cloud.OverseerTaskQueue.QueueEvent;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.common.cloud.ZkConfigManager;
|
||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||
import org.apache.solr.common.params.ConfigSetParams;
|
||||
import org.apache.solr.common.params.ConfigSetParams.ConfigSetAction;
|
||||
|
@ -170,6 +174,19 @@ public class ConfigSetsHandler extends RequestHandlerBase {
|
|||
Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
|
||||
return req.getParams().required().getAll(null, NAME);
|
||||
}
|
||||
},
|
||||
LIST_OP(LIST) {
|
||||
@Override
|
||||
Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, ConfigSetsHandler h) throws Exception {
|
||||
NamedList<Object> results = new NamedList<>();
|
||||
SolrZkClient zk = h.coreContainer.getZkController().getZkStateReader().getZkClient();
|
||||
ZkConfigManager zkConfigManager = new ZkConfigManager(zk);
|
||||
List<String> configSetsList = zkConfigManager.listConfigs();
|
||||
results.add("configSets", configSetsList);
|
||||
SolrResponse response = new OverseerSolrResponse(results);
|
||||
rsp.getValues().addAll(response.getResponse());
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
ConfigSetAction action;
|
||||
|
|
|
@ -22,9 +22,12 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
|
@ -33,6 +36,7 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
|||
import org.apache.solr.client.solrj.request.ConfigSetAdminRequest;
|
||||
import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create;
|
||||
import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Delete;
|
||||
import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.List;
|
||||
import org.apache.solr.client.solrj.response.ConfigSetAdminResponse;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.common.cloud.ZkConfigManager;
|
||||
|
@ -296,6 +300,39 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 {
|
|||
solrClient.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList() throws Exception {
|
||||
final SolrClient solrClient =
|
||||
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
|
||||
|
||||
SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(),
|
||||
AbstractZkTestCase.TIMEOUT, 45000, null);
|
||||
try {
|
||||
// test empty
|
||||
List list = new List();
|
||||
ConfigSetAdminResponse.List response = list.process(solrClient);
|
||||
Collection<String> actualConfigSets = response.getConfigSets();
|
||||
assertEquals(0, actualConfigSets.size());
|
||||
|
||||
// test multiple
|
||||
final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile();
|
||||
Set<String> configSets = new HashSet<String>();
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
String configSet = "configSet" + i;
|
||||
solrCluster.uploadConfigDir(configDir, configSet);
|
||||
configSets.add(configSet);
|
||||
}
|
||||
response = list.process(solrClient);
|
||||
actualConfigSets = response.getConfigSets();
|
||||
assertEquals(configSets.size(), actualConfigSets.size());
|
||||
assertTrue(configSets.containsAll(actualConfigSets));
|
||||
} finally {
|
||||
zkClient.close();
|
||||
}
|
||||
|
||||
solrClient.close();
|
||||
}
|
||||
|
||||
private StringBuilder getConfigSetProps(Map<String, String> map) {
|
||||
return new StringBuilder(new String(Utils.toJSON(map), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
|
|
@ -38,10 +38,11 @@ import static org.apache.solr.common.params.CommonParams.NAME;
|
|||
*
|
||||
* @since solr 5.4
|
||||
*/
|
||||
public abstract class ConfigSetAdminRequest <Q extends ConfigSetAdminRequest<Q>> extends SolrRequest<ConfigSetAdminResponse> {
|
||||
public abstract class ConfigSetAdminRequest
|
||||
<Q extends ConfigSetAdminRequest<Q,R>, R extends ConfigSetAdminResponse>
|
||||
extends SolrRequest<R> {
|
||||
|
||||
protected ConfigSetAction action = null;
|
||||
protected String configSetName = null;
|
||||
|
||||
protected ConfigSetAdminRequest setAction(ConfigSetAction action) {
|
||||
this.action = action;
|
||||
|
@ -63,12 +64,8 @@ public abstract class ConfigSetAdminRequest <Q extends ConfigSetAdminRequest<Q>>
|
|||
if (action == null) {
|
||||
throw new RuntimeException( "no action specified!" );
|
||||
}
|
||||
if (configSetName == null) {
|
||||
throw new RuntimeException( "no ConfigSet specified!" );
|
||||
}
|
||||
ModifiableSolrParams params = new ModifiableSolrParams();
|
||||
params.set(ConfigSetParams.ACTION, action.toString());
|
||||
params.set(NAME, configSetName);
|
||||
return params;
|
||||
}
|
||||
|
||||
|
@ -78,11 +75,14 @@ public abstract class ConfigSetAdminRequest <Q extends ConfigSetAdminRequest<Q>>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ConfigSetAdminResponse createResponse(SolrClient client) {
|
||||
return new ConfigSetAdminResponse();
|
||||
}
|
||||
protected abstract R createResponse(SolrClient client);
|
||||
|
||||
public final Q setConfigSetName(String configSetName) {
|
||||
protected abstract static class ConfigSetSpecificAdminRequest
|
||||
<T extends ConfigSetAdminRequest<T,ConfigSetAdminResponse>>
|
||||
extends ConfigSetAdminRequest<T,ConfigSetAdminResponse> {
|
||||
protected String configSetName = null;
|
||||
|
||||
public final T setConfigSetName(String configSetName) {
|
||||
this.configSetName = configSetName;
|
||||
return getThis();
|
||||
}
|
||||
|
@ -91,8 +91,24 @@ public abstract class ConfigSetAdminRequest <Q extends ConfigSetAdminRequest<Q>>
|
|||
return configSetName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrParams getParams() {
|
||||
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
|
||||
if (configSetName == null) {
|
||||
throw new RuntimeException( "no ConfigSet specified!" );
|
||||
}
|
||||
params.set(NAME, configSetName);
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigSetAdminResponse createResponse(SolrClient client) {
|
||||
return new ConfigSetAdminResponse();
|
||||
}
|
||||
}
|
||||
|
||||
// CREATE request
|
||||
public static class Create extends ConfigSetAdminRequest<Create> {
|
||||
public static class Create extends ConfigSetSpecificAdminRequest<Create> {
|
||||
protected static String PROPERTY_PREFIX = "configSetProp";
|
||||
protected String baseConfigSetName;
|
||||
protected Properties properties;
|
||||
|
@ -142,7 +158,7 @@ public abstract class ConfigSetAdminRequest <Q extends ConfigSetAdminRequest<Q>>
|
|||
}
|
||||
|
||||
// DELETE request
|
||||
public static class Delete extends ConfigSetAdminRequest<Delete> {
|
||||
public static class Delete extends ConfigSetSpecificAdminRequest<Delete> {
|
||||
public Delete() {
|
||||
action = ConfigSetAction.DELETE;
|
||||
}
|
||||
|
@ -152,4 +168,21 @@ public abstract class ConfigSetAdminRequest <Q extends ConfigSetAdminRequest<Q>>
|
|||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// LIST request
|
||||
public static class List extends ConfigSetAdminRequest<List, ConfigSetAdminResponse.List> {
|
||||
public List() {
|
||||
action = ConfigSetAction.LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigSetAdminResponse.List createResponse(SolrClient client) {
|
||||
return new ConfigSetAdminResponse.List();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,4 +30,9 @@ public class ConfigSetAdminResponse extends SolrResponseBase
|
|||
return (NamedList<String>) getResponse().get( "exceptions" );
|
||||
}
|
||||
|
||||
public static class List extends ConfigSetAdminResponse {
|
||||
public java.util.List<String> getConfigSets() {
|
||||
return (java.util.List<String>) getResponse().get("configSets");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ public interface ConfigSetParams
|
|||
|
||||
public enum ConfigSetAction {
|
||||
CREATE,
|
||||
DELETE;
|
||||
DELETE,
|
||||
LIST;
|
||||
|
||||
public static ConfigSetAction get(String p) {
|
||||
if (p != null) {
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
package org.apache.solr.client.solrj.request;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.apache.solr.client.solrj.response.ConfigSetAdminResponse;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -29,7 +31,6 @@ public class TestConfigSetAdminRequest extends SolrTestCaseJ4 {
|
|||
@Test
|
||||
public void testNoAction() {
|
||||
ConfigSetAdminRequest request = new MyConfigSetAdminRequest();
|
||||
request.setConfigSetName("name");
|
||||
verifyException(request, "action");
|
||||
}
|
||||
|
||||
|
@ -59,12 +60,17 @@ public class TestConfigSetAdminRequest extends SolrTestCaseJ4 {
|
|||
}
|
||||
}
|
||||
|
||||
private static class MyConfigSetAdminRequest extends ConfigSetAdminRequest<MyConfigSetAdminRequest> {
|
||||
private static class MyConfigSetAdminRequest extends ConfigSetAdminRequest<MyConfigSetAdminRequest, ConfigSetAdminResponse> {
|
||||
public MyConfigSetAdminRequest() {}
|
||||
|
||||
@Override
|
||||
public MyConfigSetAdminRequest getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSetAdminResponse createResponse(SolrClient client) {
|
||||
return new ConfigSetAdminResponse();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue