Search in sources :

Example 6 with Pong

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;
}
Also used : InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pong(com.yahoo.prelude.Pong) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 7 with 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);
}
Also used : FutureTask(java.util.concurrent.FutureTask) Pong(com.yahoo.prelude.Pong)

Example 8 with Pong

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);
    }
}
Also used : PingableSearcher(com.yahoo.search.cluster.PingableSearcher) Searcher(com.yahoo.search.Searcher) Pong(com.yahoo.prelude.Pong)

Example 9 with Pong

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;
}
Also used : Pong(com.yahoo.prelude.Pong)

Example 10 with 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();
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Ping(com.yahoo.prelude.Ping) Pong(com.yahoo.prelude.Pong)

Aggregations

Pong (com.yahoo.prelude.Pong)10 Ping (com.yahoo.prelude.Ping)3 Execution (com.yahoo.search.searchchain.Execution)3 Searcher (com.yahoo.search.Searcher)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Chain (com.yahoo.component.chain.Chain)1 Fs4Config (com.yahoo.container.search.Fs4Config)1 BasicPacket (com.yahoo.fs4.BasicPacket)1 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)1 PingPacket (com.yahoo.fs4.PingPacket)1 FS4Channel (com.yahoo.fs4.mplex.FS4Channel)1 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)1 MockBackend (com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend)1 Query (com.yahoo.search.Query)1 PingableSearcher (com.yahoo.search.cluster.PingableSearcher)1 InterruptedIOException (java.io.InterruptedIOException)1 FutureTask (java.util.concurrent.FutureTask)1 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)1