You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mk...@apache.org on 2019/10/06 20:40:18 UTC

[lucene-solr] branch master updated: SOLR-13719: introducing SolrClient.ping(collection)

This is an automated email from the ASF dual-hosted git repository.

mkhl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 1cf7368  SOLR-13719: introducing SolrClient.ping(collection)
1cf7368 is described below

commit 1cf7368ed8f507750b604682cf967452291fccf8
Author: Mikhail Khludnev <mk...@apache.org>
AuthorDate: Sun Oct 6 23:35:17 2019 +0300

    SOLR-13719: introducing SolrClient.ping(collection)
---
 solr/CHANGES.txt                                         |  2 ++
 solr/solr-ref-guide/src/ping.adoc                        | 11 ++++++++++-
 .../java/org/apache/solr/client/solrj/SolrClient.java    | 16 ++++++++++++++++
 .../solr/client/solrj/impl/CloudSolrClientTest.java      | 13 +++++++++++++
 4 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5f4fcf2..33df7f1 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -187,6 +187,8 @@ Improvements
 * SOLR-13795: Managed schema operations should do a core reload in Solr standalone mode.
   (Thomas Wöckinger via David Smiley)
 
+* SOLR-13719: Introducing SolrClient.ping(collection) in SolrJ (Geza Nagy via Mikhail Khludnev) 
+
 Bug Fixes
 ----------------------
 
diff --git a/solr/solr-ref-guide/src/ping.adoc b/solr/solr-ref-guide/src/ping.adoc
index c1de95c..ed4e7ce 100644
--- a/solr/solr-ref-guide/src/ping.adoc
+++ b/solr/solr-ref-guide/src/ping.adoc
@@ -69,7 +69,7 @@ This command will ping all replicas of the given collection name for a response:
 
 Both API calls have the same output. A status=OK indicates that the nodes are responding.
 
-*SolrJ Example*
+*SolrJ Example with SolrPing*
 
 [source,java]
 ----
@@ -78,3 +78,12 @@ ping.getParams().add("distrib", "true"); //To make it a distributed request agai
 rsp = ping.process(solrClient, collectionName);
 int status = rsp.getStatus();
 ----
+
+*SolrJ Example with SolrClient*
+
+[source,java]
+----
+SolrClient client = new HttpSolrClient.Builder(solrUrl).build();
+SolrPingResponse pingResponse = client.ping(collectionName);
+int status = pingResponse.getStatus();
+----
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrClient.java
index 885edc9..0bbdc1a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrClient.java
@@ -959,6 +959,21 @@ public abstract class SolrClient implements Serializable, Closeable {
   }
 
   /**
+   * Issues a ping request to check if the collection's replicas are alive
+   *
+   * @param collection collection to ping
+   *
+   * @return a {@link org.apache.solr.client.solrj.response.SolrPingResponse} containing the response
+   *         from the server
+   *
+   * @throws IOException If there is a low-level I/O error.
+   * @throws SolrServerException if there is an error on the server
+   */
+  public SolrPingResponse ping(String collection) throws SolrServerException, IOException {
+    return new SolrPing().process(this, collection);
+  }
+
+  /**
    * Issues a ping request to check if the server is alive
    *
    * @return a {@link org.apache.solr.client.solrj.response.SolrPingResponse} containing the response
@@ -971,6 +986,7 @@ public abstract class SolrClient implements Serializable, Closeable {
     return new SolrPing().process(this, null);
   }
 
+
   /**
    * Performs a query to the Solr server
    *
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index 1c9ba04..a505799 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -49,6 +49,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.client.solrj.response.RequestStatusState;
 import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.client.solrj.response.SolrPingResponse;
 import org.apache.solr.cloud.AbstractDistribZkTestBase;
 import org.apache.solr.cloud.SolrCloudTestCase;
 import org.apache.solr.common.SolrDocument;
@@ -951,4 +952,16 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
     log.info("Shards giving the response: " + Arrays.toString(shardAddresses.toArray()));
   }
 
+  @Test
+  public void testPing() throws Exception {
+    final String testCollection = "ping_test";
+    CollectionAdminRequest.createCollection(testCollection, "conf", 2, 1).process(cluster.getSolrClient());
+    cluster.waitForActiveCollection(testCollection, 2, 2);
+    final SolrClient clientUnderTest = getRandomClient();
+
+    final SolrPingResponse response = clientUnderTest.ping(testCollection);
+
+    assertEquals("This should be OK", 0, response.getStatus());
+  }
+
 }