use of org.apache.solr.client.solrj.response.CoreAdminResponse in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method reloadCollection.
protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception {
ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica);
String coreName = coreProps.getCoreName();
boolean reloadedOk = false;
try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) {
CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client);
long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime();
Thread.sleep(1000);
// send reload command for the collection
log.info("Sending RELOAD command for " + testCollectionName);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.RELOAD.toString());
params.set("name", testCollectionName);
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
client.request(request);
// reload can take a short while
Thread.sleep(2000);
// verify reload is done, waiting up to 30 seconds for slow test environments
long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS);
while (System.nanoTime() < timeout) {
statusResp = CoreAdminRequest.getStatus(coreName, client);
long startTimeAfterReload = statusResp.getStartTime(coreName).getTime();
if (startTimeAfterReload > leaderCoreStartTime) {
reloadedOk = true;
break;
}
// else ... still waiting to see the reloaded core report a later start time
Thread.sleep(1000);
}
}
return reloadedOk;
}
use of org.apache.solr.client.solrj.response.CoreAdminResponse in project lucene-solr by apache.
the class CollectionsAPIDistributedZkTest method addReplicaTest.
@Test
public void addReplicaTest() throws Exception {
String collectionName = "addReplicaColl";
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setMaxShardsPerNode(4).process(cluster.getSolrClient());
ArrayList<String> nodeList = new ArrayList<>(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes());
Collections.shuffle(nodeList, random());
String newReplicaName = Assign.assignNode(getCollectionState(collectionName));
CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").setNode(nodeList.get(0)).process(cluster.getSolrClient());
Replica newReplica = getCollectionState(collectionName).getReplica(newReplicaName);
assertEquals("Replica should be created on the right node", cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP));
newReplicaName = Assign.assignNode(getCollectionState(collectionName));
Path instancePath = createTempDir();
CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").withProperty(CoreAdminParams.INSTANCE_DIR, instancePath.toString()).process(cluster.getSolrClient());
newReplica = getCollectionState(collectionName).getReplica(newReplicaName);
assertNotNull(newReplica);
try (HttpSolrClient coreclient = getHttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient);
NamedList<Object> coreStatus = status.getCoreStatus(newReplica.getStr("core"));
String instanceDirStr = (String) coreStatus.get("instanceDir");
assertEquals(instanceDirStr, instancePath.toString());
}
//Test to make sure we can't create another replica with an existing core_name of that collection
String coreName = newReplica.getStr(CORE_NAME_PROP);
SolrException e = expectThrows(SolrException.class, () -> {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", "addreplica");
params.set("collection", collectionName);
params.set("shard", "shard1");
params.set("name", coreName);
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
cluster.getSolrClient().request(request);
});
assertTrue(e.getMessage().contains("Another replica with the same core name already exists for this collection"));
// Check that specifying property.name works. DO NOT remove this when the "name" property is deprecated
// for ADDREPLICA, this is "property.name". See SOLR-7132
newReplicaName = Assign.assignNode(getCollectionState(collectionName));
CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").withProperty(CoreAdminParams.NAME, "propertyDotName").process(cluster.getSolrClient());
newReplica = getCollectionState(collectionName).getReplica(newReplicaName);
assertEquals("'core' should be 'propertyDotName' ", "propertyDotName", newReplica.getStr("core"));
}
use of org.apache.solr.client.solrj.response.CoreAdminResponse 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