use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class FastSearcher method ping.
public static Pong ping(Ping ping, Backend backend, String name) {
FS4Channel channel = backend.openPingChannel();
// com.yahoo.prelude.cluster.TrafficNodeMonitor.failed(ErrorMessage)
try {
PingPacket pingPacket = new PingPacket();
try {
boolean couldSend = channel.sendPacket(pingPacket);
if (!couldSend) {
return new Pong(ErrorMessage.createBackendCommunicationError("Could not ping " + name));
}
} catch (InvalidChannelException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel " + name));
} catch (IllegalStateException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Illegal state in FS4: " + e.getMessage()));
} catch (IOException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("IO error while sending ping: " + e.getMessage()));
}
// We should only get a single packet
BasicPacket[] packets;
try {
packets = channel.receivePackets(ping.getTimeout(), 1);
} catch (ChannelTimeoutException e) {
return new Pong(ErrorMessage.createNoAnswerWhenPingingNode("timeout while waiting for fdispatch for " + name));
} catch (InvalidChannelException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel for " + name));
}
if (packets.length == 0) {
return new Pong(ErrorMessage.createBackendCommunicationError(name + " got no packets back"));
}
try {
ensureInstanceOf(PongPacket.class, packets[0], name);
} catch (TimeoutException e) {
return new Pong(ErrorMessage.createTimeout(e.getMessage()));
} catch (IOException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Unexpected packet class returned after ping: " + e.getMessage()));
}
return new Pong((PongPacket) packets[0]);
} finally {
if (channel != null) {
channel.close();
}
}
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class ClusterSearcher method ping.
/**
* Pinging a node, called from ClusterMonitor
*/
@Override
public final void ping(T p, Executor executor) {
log(LogLevel.FINE, "Sending ping to: ", p);
Pinger pinger = new Pinger(p);
FutureTask<Pong> future = new FutureTask<>(pinger);
executor.execute(future);
Pong pong;
Throwable logThrowable = null;
try {
pong = future.get(monitor.getConfiguration().getFailLimit(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
pong = new Pong(ErrorMessage.createUnspecifiedError("Ping was interrupted: " + p));
logThrowable = e;
} catch (ExecutionException e) {
pong = new Pong(ErrorMessage.createUnspecifiedError("Execution was interrupted: " + p));
logThrowable = e;
} catch (LinkageError e) {
// Typically Osgi woes
pong = new Pong(ErrorMessage.createErrorInPluginSearcher("Class loading problem", e));
logThrowable = e;
} catch (TimeoutException e) {
pong = new Pong(ErrorMessage.createNoAnswerWhenPingingNode("Ping thread timed out."));
}
future.cancel(true);
if (pong.badResponse()) {
monitor.failed(p, pong.getError(0));
log(LogLevel.FINE, "Failed ping - ", pong);
} else {
monitor.responded(p);
log(LogLevel.FINE, "Answered ping - ", p);
}
if (logThrowable != null) {
StackTraceElement[] trace = logThrowable.getStackTrace();
String traceAsString = null;
if (trace != null) {
StringBuilder b = new StringBuilder(": ");
for (StackTraceElement k : trace) {
if (k == null) {
b.append("null\n");
} else {
b.append(k.toString()).append('\n');
}
}
traceAsString = b.toString();
}
getLogger().warning("Caught " + logThrowable.getClass().getName() + " exception in " + getId().getName() + " ping" + (trace == null ? ", no stack trace available." : traceAsString));
}
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class FastSearcherTestCase method testPing.
@Test
public void testPing() throws IOException, InterruptedException {
Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
BackendTestCase.MockServer server = new BackendTestCase.MockServer();
FS4ResourcePool listeners = new FS4ResourcePool(new Fs4Config(new Fs4Config.Builder()));
Backend backend = listeners.getBackend(server.host.getHostString(), server.host.getPort());
FastSearcher fastSearcher = new FastSearcher(backend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(0, 0.0d), documentdbInfoConfig);
server.dispatch.packetData = BackendTestCase.PONG;
server.dispatch.setNoChannel();
Chain<Searcher> chain = new Chain<>(fastSearcher);
Execution e = new Execution(chain, Execution.Context.createContextStub());
Pong pong = e.ping(new Ping());
assertTrue(pong.getPongPacket().isPresent());
assertEquals(127, pong.getPongPacket().get().getDocstamp());
backend.shutdown();
server.dispatch.socket.close();
server.dispatch.connection.close();
server.worker.join();
pong.setPingInfo("blbl");
assertEquals("Result of pinging using blbl", pong.toString());
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class VdsStreamingSearcherTestCase method testTrivialitiesToIncreaseCoverage.
@Test
public void testTrivialitiesToIncreaseCoverage() {
VdsStreamingSearcher searcher = new VdsStreamingSearcher();
assertNull(searcher.getSearchClusterConfigId());
String searchClusterConfigId = "searchClusterConfigId";
searcher.setSearchClusterConfigId(searchClusterConfigId);
assertEquals(searchClusterConfigId, searcher.getSearchClusterConfigId());
assertNull(searcher.getStorageClusterRouteSpec());
String storageClusterRouteSpec = "storageClusterRouteSpec";
searcher.setStorageClusterRouteSpec(storageClusterRouteSpec);
assertEquals(storageClusterRouteSpec, searcher.getStorageClusterRouteSpec());
Pong pong = searcher.ping(new Ping(), new Execution(new Execution.Context(null, null, null, null, null)));
assertEquals(0, pong.getErrorSize());
}
use of com.yahoo.prelude.Pong in project vespa by vespa-engine.
the class ClusterSearcher method ping.
/**
* Pinging a node, called from ClusterMonitor.
*/
void ping(VespaBackEndSearcher node) throws InterruptedException {
log.fine("Sending ping to: " + node);
Pinger pinger = new Pinger(node);
getExecutor().execute(pinger);
// handles timeout
Pong pong = pinger.getPong();
if (pong == null) {
monitor.failed(node, ErrorMessage.createNoAnswerWhenPingingNode("Ping thread timed out."));
} else if (pong.badResponse()) {
monitor.failed(node, pong.getError(0));
} else {
monitor.responded(node, backendCanServeDocuments(pong));
}
}
Aggregations