use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testAddAndDeleteReplicaProp.
@Test
public void testAddAndDeleteReplicaProp() throws InterruptedException, IOException, SolrServerException {
final String collection = "replicaProperties";
CollectionAdminRequest.createCollection(collection, "conf", 2, 2).process(cluster.getSolrClient());
final Replica replica = getCollectionState(collection).getLeader("shard1");
CollectionAdminResponse response = CollectionAdminRequest.addReplicaProperty(collection, "shard1", replica.getName(), "preferredleader", "true").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
waitForState("Expecting property 'preferredleader' to appear on replica " + replica.getName(), collection, (n, c) -> "true".equals(c.getReplica(replica.getName()).getStr("property.preferredleader")));
response = CollectionAdminRequest.deleteReplicaProperty(collection, "shard1", replica.getName(), "property.preferredleader").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
waitForState("Expecting property 'preferredleader' to be removed from replica " + replica.getName(), collection, (n, c) -> c.getReplica(replica.getName()).getStr("property.preferredleader") == null);
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPIDistributedZkTest method testCreateShouldFailOnExistingCore.
@Test
public void testCreateShouldFailOnExistingCore() throws Exception {
// first we make a core with the core name the collections api
// will try and use - this will cause our mock fail
Create createCmd = new Create();
createCmd.setCoreName(Assign.buildCoreName("halfcollection", "shard1", Replica.Type.NRT, 1));
createCmd.setCollection("halfcollectionblocker");
String dataDir = createTempDir().toFile().getAbsolutePath();
createCmd.setDataDir(dataDir);
createCmd.setNumShards(1);
createCmd.setCollectionConfigName("conf");
try (SolrClient client = cluster.getJettySolrRunner(0).newClient()) {
client.request(createCmd);
}
createCmd = new Create();
createCmd.setCoreName(Assign.buildCoreName("halfcollection", "shard1", Replica.Type.NRT, 1));
createCmd.setCollection("halfcollectionblocker2");
dataDir = createTempDir().toFile().getAbsolutePath();
createCmd.setDataDir(dataDir);
createCmd.setNumShards(1);
createCmd.setCollectionConfigName("conf");
try (SolrClient client = cluster.getJettySolrRunner(1).newClient()) {
client.request(createCmd);
}
String nn1 = cluster.getJettySolrRunner(0).getNodeName();
String nn2 = cluster.getJettySolrRunner(1).getNodeName();
CollectionAdminResponse resp = CollectionAdminRequest.createCollection("halfcollection", "conf", 2, 1).setCreateNodeSet(nn1 + "," + nn2).process(cluster.getSolrClient());
SimpleOrderedMap success = (SimpleOrderedMap) resp.getResponse().get("success");
SimpleOrderedMap failure = (SimpleOrderedMap) resp.getResponse().get("failure");
assertNotNull(resp.toString(), success);
assertNotNull(resp.toString(), failure);
String val1 = success.getVal(0).toString();
String val2 = failure.getVal(0).toString();
assertTrue(val1.contains("SolrException") || val2.contains("SolrException"));
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testSplitShard.
@Test
public void testSplitShard() throws Exception {
final String collectionName = "solrj_test_splitshard";
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1).process(cluster.getSolrClient());
CollectionAdminResponse response = CollectionAdminRequest.splitShard(collectionName).setShardName("shard1").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
assertEquals(0, (int) coresStatus.get(Assign.buildCoreName(collectionName, "shard1_0", Replica.Type.NRT, 1)).get("status"));
assertEquals(0, (int) coresStatus.get(Assign.buildCoreName(collectionName, "shard1_1", Replica.Type.NRT, 1)).get("status"));
waitForState("Expected all shards to be active and parent shard to be removed", collectionName, (n, c) -> {
if (c.getSlice("shard1").getState() == Slice.State.ACTIVE)
return false;
for (Replica r : c.getReplicas()) {
if (r.isActive(n) == false)
return false;
}
return true;
});
// Test splitting using split.key
response = CollectionAdminRequest.splitShard(collectionName).setSplitKey("b!").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
waitForState("Expected 5 slices to be active", collectionName, (n, c) -> c.getActiveSlices().size() == 5);
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testList.
@Test
public void testList() throws IOException, SolrServerException {
CollectionAdminResponse response = new CollectionAdminRequest.List().process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertNotNull("collection list should not be null", response.getResponse().get("collections"));
}
use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testCloudInfoInCoreStatus.
@Test
public void testCloudInfoInCoreStatus() throws IOException, SolrServerException {
String collectionName = "corestatus_test";
CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setStateFormat(1).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
String nodeName = ((NamedList) response.getResponse().get("success")).getName(0);
String corename = (String) ((NamedList) ((NamedList) response.getResponse().get("success")).getVal(0)).get("core");
try (HttpSolrClient coreclient = getHttpSolrClient(cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeName))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreclient);
Map m = status.getResponse().asMap(5);
assertEquals(collectionName, Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "collection")));
assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "shard")));
assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "replica")));
}
}
Aggregations