Search in sources :

Example 6 with SolrPingResponse

use of org.apache.solr.client.solrj.response.SolrPingResponse in project ddf by codice.

the class SolrClientAdapter method checkIfReachable.

/**
 * Checks if the Solr server is reachable by issuing a ping and awaiting the response.
 *
 * @param how how we got to checking if the server was reachable
 * @throws UnavailableSolrException if the server is not reachable for whatever reasons
 */
@VisibleForTesting
@SuppressWarnings("squid:S1181")
void checkIfReachable(String how) {
    LOGGER.debug("Solr({}): checking availability of the client {}", core, how);
    try {
        lastPing.set(System.currentTimeMillis());
        final SolrPingResponse response = pingClient.ping();
        if (response == null) {
            LOGGER.debug(SolrClientAdapter.FAILED_TO_PING, core, "null response");
            throw new UnavailableSolrException("ping failed with no response");
        }
        final Object status = response.getResponse().get("status");
        if (SolrClientAdapter.OK_STATUS.equals(status)) {
            return;
        }
        LOGGER.debug(SolrClientAdapter.FAILED_TO_PING_WITH_STATUS, core, status);
        throw new UnavailableSolrException("ping failed with " + status + " status");
    } catch (UnavailableSolrException | VirtualMachineError e) {
        throw e;
    } catch (Throwable t) {
        LOGGER.debug(SolrClientAdapter.FAILED_TO_PING, core, t, t);
        throw new UnavailableSolrException("ping failed", t);
    }
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) UnavailableSolrException(org.codice.solr.client.solrj.UnavailableSolrException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with SolrPingResponse

use of org.apache.solr.client.solrj.response.SolrPingResponse in project ddf by codice.

the class RemoteSolrCatalogProviderTest method givenSolrClient.

/**
 * @return
 * @throws IOException
 * @throws SolrServerException
 */
private SolrClient givenSolrClient(boolean ok) throws SolrServerException, IOException {
    SolrClient client = mock(SolrClient.class);
    SolrPingResponse pingResponse = mock(SolrPingResponse.class);
    NamedList<Object> namedList = new NamedList<>();
    if (ok) {
        namedList.add("status", "OK");
    } else {
        namedList.add("status", "NOT_OK");
    }
    when(pingResponse.getResponse()).thenReturn(namedList);
    when(client.ping()).thenReturn(pingResponse);
    return client;
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) SolrClient(org.codice.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList)

Example 8 with SolrPingResponse

use of org.apache.solr.client.solrj.response.SolrPingResponse in project lucene-solr by apache.

the class SolrPingTest method testDisabledSolrPing.

@Test(expected = SolrException.class)
public void testDisabledSolrPing() throws Exception {
    SolrPing ping = new SolrPing();
    SolrPingResponse rsp = null;
    ping.setActionDisable();
    try {
        ping.process(getSolrClient());
    } catch (Exception e) {
        throw new Exception("disable action failed!");
    }
    ping.setActionPing();
    rsp = ping.process(getSolrClient());
    // the above line should fail with a 503 SolrException.
    Assert.assertNotNull(rsp);
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 9 with SolrPingResponse

use of org.apache.solr.client.solrj.response.SolrPingResponse in project jackrabbit-oak by apache.

the class RemoteSolrServerProvider method initializeWithCloudSolrServer.

private SolrClient initializeWithCloudSolrServer() throws IOException {
    // try SolrCloud client
    CloudSolrClient cloudSolrServer = new CloudSolrClient(remoteSolrServerConfiguration.getSolrZkHost());
    cloudSolrServer.setZkConnectTimeout(remoteSolrServerConfiguration.getConnectionTimeout());
    cloudSolrServer.setZkClientTimeout(remoteSolrServerConfiguration.getSocketTimeout());
    cloudSolrServer.setIdField(OakSolrConfigurationDefaults.PATH_FIELD_NAME);
    if (connectToZK(cloudSolrServer)) {
        log.debug("CloudSolrServer connected");
        // workaround for first request when the needed collection may not exist
        cloudSolrServer.setDefaultCollection("collection1");
        // create specified collection if it doesn't exists
        try {
            createCollectionIfNeeded(cloudSolrServer);
        } catch (Throwable t) {
            if (log.isWarnEnabled()) {
                log.warn("could not create the collection on {}", remoteSolrServerConfiguration.getSolrZkHost(), t);
            }
        }
        cloudSolrServer.setDefaultCollection(remoteSolrServerConfiguration.getSolrCollection());
        log.debug("waiting for CloudSolrServer to come alive");
        // SolrCloud may need some time to sync on collection creation (to spread it over the shards / replicas)
        int i = 0;
        while (i < 3) {
            try {
                SolrPingResponse ping = cloudSolrServer.ping();
                if (ping != null && 0 == ping.getStatus()) {
                    return cloudSolrServer;
                } else {
                    cloudSolrServer.close();
                    throw new IOException("the found SolrCloud server is not alive");
                }
            } catch (Exception e) {
                // wait a bit
                try {
                    if (log.isDebugEnabled()) {
                        log.debug("server is not alive yet, wait a bit", e);
                    }
                    Thread.sleep(3000);
                } catch (InterruptedException e1) {
                // do nothing
                }
            }
            i++;
        }
        cloudSolrServer.close();
        throw new IOException("the found SolrCloud server is not alive");
    } else {
        cloudSolrServer.close();
        throw new IOException("could not connect to Zookeeper hosted at " + remoteSolrServerConfiguration.getSolrZkHost());
    }
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) IOException(java.io.IOException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 10 with SolrPingResponse

use of org.apache.solr.client.solrj.response.SolrPingResponse in project jackrabbit-oak by apache.

the class RemoteSolrServerProvider method initializeWithExistingHttpServer.

private SolrClient initializeWithExistingHttpServer() throws IOException, SolrServerException {
    // try basic Solr HTTP client
    HttpSolrClient httpSolrServer = new HttpSolrClient(remoteSolrServerConfiguration.getSolrHttpUrls()[0]);
    httpSolrServer.setConnectionTimeout(remoteSolrServerConfiguration.getConnectionTimeout());
    httpSolrServer.setSoTimeout(remoteSolrServerConfiguration.getSocketTimeout());
    SolrPingResponse ping = httpSolrServer.ping();
    if (ping != null && 0 == ping.getStatus()) {
        return httpSolrServer;
    } else {
        httpSolrServer.close();
        throw new IOException("the found HTTP Solr server is not alive");
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) IOException(java.io.IOException)

Aggregations

SolrPingResponse (org.apache.solr.client.solrj.response.SolrPingResponse)11 Test (org.junit.Test)4 IOException (java.io.IOException)2 SolrClient (org.apache.solr.client.solrj.SolrClient)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 NamedList (org.apache.solr.common.util.NamedList)2 UnavailableSolrException (org.codice.solr.client.solrj.UnavailableSolrException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 URI (java.net.URI)1 EmbeddedSolrServerConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)1 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)1 SolrPing (org.apache.solr.client.solrj.request.SolrPing)1 MiniSolrCloudCluster (org.apache.solr.cloud.MiniSolrCloudCluster)1 SolrException (org.apache.solr.common.SolrException)1 SolrClient (org.codice.solr.client.solrj.SolrClient)1