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);
}
}
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;
}
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);
}
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());
}
}
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");
}
}
Aggregations