use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class HTTPSearcher method ping.
/**
* Pinging in HTTPBackend is done by creating a PING uri from http://host:port/path.
* If this returns a status that is below 300, the ping is considered good.
*
* If another uri is needed for pinging, reimplement getPingURI.
*
* Override either this method to change how ping
*/
@Override
public Pong ping(Ping ping, Connection connection) {
URI uri = null;
Pong pong = new Pong();
HttpResponse response = null;
if (httpParameters.getPingOption() == PingOption.DISABLE)
return pong;
try {
uri = getPingURI(connection);
if (uri == null)
pong.addError(ErrorMessage.createIllegalQuery("Ping uri is null"));
if (uri.getHost() == null) {
pong.addError(ErrorMessage.createIllegalQuery("Ping uri has no host"));
uri = null;
}
} catch (MalformedURLException | URISyntaxException e) {
pong.addError(ErrorMessage.createIllegalQuery("Malformed ping uri '" + uri + "': " + Exceptions.toMessageString(e)));
} catch (RuntimeException e) {
log.log(Level.WARNING, "Unexpected exception while attempting to ping " + connection + " using uri '" + uri + "'", e);
pong.addError(ErrorMessage.createIllegalQuery("Unexpected problem with ping uri '" + uri + "': " + Exceptions.toMessageString(e)));
}
if (uri == null)
return pong;
pong.setPingInfo("using uri '" + uri + "'");
try {
response = getPingResponse(uri, ping);
checkPing(response, pong);
} catch (IOException e) {
// We do not have a valid ping
pong.addError(ErrorMessage.createBackendCommunicationError("Exception thrown when pinging with url '" + uri + "': " + Exceptions.toMessageString(e)));
} catch (TimeoutException e) {
pong.addError(ErrorMessage.createTimeout("Timeout for ping " + uri + " in " + this + ": " + e.getMessage()));
} catch (RuntimeException e) {
log.log(Level.WARNING, "Unexpected exception while attempting to ping " + connection + " using uri '" + uri + "'", e);
pong.addError(ErrorMessage.createIllegalQuery("Unexpected problem with ping uri '" + uri + "': " + Exceptions.toMessageString(e)));
} finally {
if (response != null) {
cleanupHttpEntity(response.getEntity());
}
}
return pong;
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class SearchCluster method ping.
/**
* Used by the cluster monitor to manage node status
*/
@Override
public void ping(Node node, Executor executor) {
Pinger pinger = new Pinger(node);
FutureTask<Pong> futurePong = new FutureTask<>(pinger);
executor.execute(futurePong);
Pong pong = getPong(futurePong, node);
futurePong.cancel(true);
if (pong.badResponse())
clusterMonitor.failed(node, pong.getError(0));
else
clusterMonitor.responded(node);
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class Execution method ping.
/**
* Calls ping on the next search in this chain. If there is no next, a Pong is created and returned.
*/
public Pong ping(Ping ping) {
// return this reference, not directly. It's needed for adding time data
Pong annotationReference = null;
timer.samplePing(nextIndex(), context.getDetailedDiagnostics());
// TODO: Allow but skip processors which are not searchers
Searcher next = (Searcher) next();
if (next == null) {
annotationReference = new Pong();
return annotationReference;
}
try {
nextProcessor();
annotationReference = invokePing(ping, next);
return annotationReference;
} finally {
previousProcessor();
timer.samplePingReturn(nextIndex(), context.getDetailedDiagnostics(), annotationReference);
}
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class TimingSearcher method ping.
@Override
public Pong ping(Ping ping, Execution execution) {
long start = preMeasure(measurePing);
Pong pong = execution.ping(ping);
postMeasure(measurePing, start);
return pong;
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class PingTestCase method checkSearchAndPing.
private void checkSearchAndPing(boolean firstSearch, boolean pongCheck, boolean secondSearch, int port) {
String resultThing;
String comment;
TestHTTPClientSearcher searcher = new TestHTTPClientSearcher("test", "localhost", port);
try {
Query query = new Query("/?query=test");
query.setWindow(0, 10);
// high timeout to allow for overloaded test machine
query.setTimeout(TIMEOUT_MS);
Ping ping = new Ping(TIMEOUT_MS);
long start = System.currentTimeMillis();
Execution exe = new Execution(searcher, Execution.Context.createContextStub());
exe.search(query);
resultThing = firstSearch ? "ok" : null;
comment = firstSearch ? "First search should have succeeded." : "First search should fail.";
assertEquals(comment, resultThing, query.properties().get("gotResponse"));
Pong pong = searcher.ping(ping, searcher.getConnection());
if (pongCheck) {
assertEquals("Ping should not have failed.", 0, pong.getErrorSize());
} else {
assertEquals("Ping should have failed.", 1, pong.getErrorSize());
}
exe = new Execution(searcher, Execution.Context.createContextStub());
exe.search(query);
resultThing = secondSearch ? "ok" : null;
comment = secondSearch ? "Second search should have succeeded." : "Second search should fail.";
assertEquals(resultThing, query.properties().get("gotResponse"));
long duration = System.currentTimeMillis() - start;
// target for duration based on the timeout values + some slack
assertTrue("This test probably hanged.", duration < TIMEOUT_MS + 4000);
searcher.shutdownConnectionManagers();
} finally {
searcher.deconstruct();
}
}
Aggregations