use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class BaseCdcrDistributedZkTest method deleteCollection.
/**
* Delete a collection through the Collection API.
*/
protected CollectionAdminResponse deleteCollection(String collectionName) throws Exception {
SolrClient client = createCloudClient(null);
CollectionAdminResponse res;
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.DELETE.toString());
params.set("name", collectionName);
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
res = new CollectionAdminResponse();
res.setResponse(client.request(request));
} catch (Exception e) {
log.warn("Error while deleting the collection " + collectionName, e);
return new CollectionAdminResponse();
} finally {
client.close();
}
return res;
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class BaseCdcrDistributedZkTest method createCollection.
private CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos, String collectionName, Map<String, Object> collectionProps, SolrClient client, String confSetName) throws SolrServerException, IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATE.toString());
for (Map.Entry<String, Object> entry : collectionProps.entrySet()) {
if (entry.getValue() != null)
params.set(entry.getKey(), String.valueOf(entry.getValue()));
}
Integer numShards = (Integer) collectionProps.get(NUM_SLICES);
if (numShards == null) {
String shardNames = (String) collectionProps.get(SHARDS_PROP);
numShards = StrUtils.splitSmart(shardNames, ',').size();
}
Integer replicationFactor = (Integer) collectionProps.get(REPLICATION_FACTOR);
if (replicationFactor == null) {
replicationFactor = (Integer) OverseerCollectionMessageHandler.COLL_PROPS.get(REPLICATION_FACTOR);
}
if (confSetName != null) {
params.set("collection.configName", confSetName);
}
List<Integer> list = new ArrayList<>();
list.add(numShards);
list.add(replicationFactor);
if (collectionInfos != null) {
collectionInfos.put(collectionName, list);
}
params.set("name", collectionName);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
CollectionAdminResponse res = new CollectionAdminResponse();
res.setResponse(client.request(request));
return res;
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testClusterProp.
@Test
public void testClusterProp() throws InterruptedException, IOException, SolrServerException {
// sanity check our expected default
final ClusterProperties props = new ClusterProperties(zkClient());
assertEquals("Expecting prop to default to unset, test needs upated", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), null);
CollectionAdminResponse response = CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, "false").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertEquals("Cluster property was not set", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), "false");
// Unset ClusterProp that we set.
CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, null).process(cluster.getSolrClient());
assertEquals("Cluster property was not unset", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), null);
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testCreateCollectionWithPropertyParam.
@Test
public void testCreateCollectionWithPropertyParam() throws Exception {
String collectionName = "solrj_test_core_props";
Path tmpDir = createTempDir("testPropertyParamsForCreate");
Path dataDir = tmpDir.resolve("dataDir-" + TestUtil.randomSimpleString(random(), 1, 5));
Path ulogDir = tmpDir.resolve("ulogDir-" + TestUtil.randomSimpleString(random(), 1, 5));
CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1).withProperty(CoreAdminParams.DATA_DIR, dataDir.toString()).withProperty(CoreAdminParams.ULOG_DIR, ulogDir.toString()).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
assertEquals(1, coresStatus.size());
DocCollection testCollection = getCollectionState(collectionName);
Replica replica1 = testCollection.getReplica("core_node1");
CoreStatus coreStatus = getCoreStatus(replica1);
assertEquals(Paths.get(coreStatus.getDataDirectory()).toString(), dataDir.toString());
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testAddAndDeleteReplica.
@Test
public void testAddAndDeleteReplica() throws Exception {
final String collectionName = "solrj_replicatests";
CollectionAdminRequest.createCollection(collectionName, "conf", 1, 2).process(cluster.getSolrClient());
String newReplicaName = Assign.assignNode(getCollectionState(collectionName));
ArrayList<String> nodeList = new ArrayList<>(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes());
Collections.shuffle(nodeList, random());
final String node = nodeList.get(0);
CollectionAdminResponse response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").setNode(node).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
waitForState("Expected to see replica " + newReplicaName + " on node " + node, collectionName, (n, c) -> {
Replica r = c.getSlice("shard1").getReplica(newReplicaName);
return r != null && r.getNodeName().equals(node);
});
// Test DELETEREPLICA
response = CollectionAdminRequest.deleteReplica(collectionName, "shard1", newReplicaName).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
waitForState("Expected replica " + newReplicaName + " to vanish from cluster state", collectionName, (n, c) -> c.getSlice("shard1").getReplica(newReplicaName) == null);
}
Aggregations