Search in sources :

Example 1 with EmptyReply

use of com.yahoo.messagebus.EmptyReply in project vespa by vespa-engine.

the class RPCNetwork method replyError.

/**
 * Deliver an error reply to the recipients of a {@link SendContext} in a way that avoids entanglement.
 *
 * @param ctx     The send context that contains the recipient data.
 * @param errCode The error code to return.
 * @param errMsg  The error string to return.
 */
private void replyError(SendContext ctx, int errCode, String errMsg) {
    for (RoutingNode recipient : ctx.recipients) {
        Reply reply = new EmptyReply();
        reply.getTrace().setLevel(ctx.traceLevel);
        reply.addError(new Error(errCode, errMsg));
        owner.deliverReply(reply, recipient);
    }
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode) EmptyReply(com.yahoo.messagebus.EmptyReply) Reply(com.yahoo.messagebus.Reply) Error(com.yahoo.messagebus.Error) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 2 with EmptyReply

use of com.yahoo.messagebus.EmptyReply in project vespa by vespa-engine.

the class RPCSend method doRequestDone.

private void doRequestDone(Request req) {
    SendContext ctx = (SendContext) req.getContext();
    String serviceName = ((RPCServiceAddress) ctx.recipient.getServiceAddress()).getServiceName();
    Reply reply = null;
    Error error = null;
    if (!req.checkReturnTypes(getReturnSpec())) {
        // Map all known JRT errors to the appropriate message bus error.
        reply = new EmptyReply();
        switch(req.errorCode()) {
            case com.yahoo.jrt.ErrorCode.TIMEOUT:
                error = new Error(ErrorCode.TIMEOUT, "A timeout occured while waiting for '" + serviceName + "' (" + ctx.timeout + " seconds expired); " + req.errorMessage());
                break;
            case com.yahoo.jrt.ErrorCode.CONNECTION:
                error = new Error(ErrorCode.CONNECTION_ERROR, "A connection error occured for '" + serviceName + "'; " + req.errorMessage());
                break;
            default:
                error = new Error(ErrorCode.NETWORK_ERROR, "A network error occured for '" + serviceName + "'; " + req.errorMessage());
        }
    } else {
        reply = createReply(req.returnValues(), serviceName, ctx.trace);
    }
    if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) {
        ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Reply (type " + reply.getType() + ") received at " + clientIdent + ".");
    }
    reply.getTrace().swap(ctx.trace);
    if (error != null) {
        reply.addError(error);
    }
    net.getOwner().deliverReply(reply, ctx.recipient);
}
Also used : Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 3 with EmptyReply

use of com.yahoo.messagebus.EmptyReply in project vespa by vespa-engine.

the class RPCSend method replyError.

/**
 * Send an error reply for a given request.
 *
 * @param request    The JRT request to reply to.
 * @param version    The version to serialize for.
 * @param traceLevel The trace level to set in the reply.
 * @param err        The error to reply with.
 */
private void replyError(Request request, Version version, int traceLevel, Error err) {
    Reply reply = new EmptyReply();
    reply.setContext(new ReplyContext(request, version));
    reply.getTrace().setLevel(traceLevel);
    reply.addError(err);
    handleReply(reply);
}
Also used : Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 4 with EmptyReply

use of com.yahoo.messagebus.EmptyReply in project vespa by vespa-engine.

the class RPCSendV1 method createReply.

@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
    Version version = new Version(ret.get(0).asUtf8Array());
    double retryDelay = ret.get(1).asDouble();
    int[] errorCodes = ret.get(2).asInt32Array();
    String[] errorMessages = ret.get(3).asStringArray();
    String[] errorServices = ret.get(4).asStringArray();
    Utf8Array protocolName = ret.get(5).asUtf8Array();
    byte[] payload = ret.get(6).asData();
    String replyTrace = ret.get(7).asString();
    // Make sure that the owner understands the protocol.
    Reply reply = null;
    Error error = null;
    if (payload.length > 0) {
        Object retval = decode(protocolName, version, payload);
        if (retval instanceof Reply) {
            reply = (Reply) retval;
        } else {
            error = (Error) retval;
        }
    }
    if (reply == null) {
        reply = new EmptyReply();
    }
    if (error != null) {
        reply.addError(error);
    }
    reply.setRetryDelay(retryDelay);
    for (int i = 0; i < errorCodes.length && i < errorMessages.length; i++) {
        reply.addError(new Error(errorCodes[i], errorMessages[i], errorServices[i].length() > 0 ? errorServices[i] : serviceName));
    }
    if (trace.getLevel() > 0) {
        trace.getRoot().addChild(TraceNode.decode(replyTrace));
    }
    return reply;
}
Also used : Version(com.yahoo.component.Version) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 5 with EmptyReply

use of com.yahoo.messagebus.EmptyReply in project vespa by vespa-engine.

the class SimpleFeederTest method requireThatAsyncFailuresThrowInMainThread.

@Test
public void requireThatAsyncFailuresThrowInMainThread() throws Throwable {
    TestDriver driver = new TestDriver(new FeederParams(), "<vespafeed><document documenttype='simple' documentid='doc:scheme:0'/></vespafeed>", new MessageHandler() {

        @Override
        public void handleMessage(Message msg) {
            Reply reply = new EmptyReply();
            reply.swapState(msg);
            reply.addError(new Error(ErrorCode.APP_FATAL_ERROR + 6, "foo"));
            reply.addError(new Error(ErrorCode.APP_FATAL_ERROR + 9, "bar"));
            reply.popHandler().handleReply(reply);
        }
    });
    try {
        driver.run();
        fail();
    } catch (IOException e) {
        assertMatches("com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage@.+\n" + "\\[UNKNOWN\\(250006\\) @ .+\\]: foo\n" + "\\[UNKNOWN\\(250009\\) @ .+\\]: bar\n", e.getMessage());
    }
    assertTrue(driver.close());
}
Also used : MessageHandler(com.yahoo.messagebus.MessageHandler) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) IOException(java.io.IOException) EmptyReply(com.yahoo.messagebus.EmptyReply) Test(org.junit.Test)

Aggregations

EmptyReply (com.yahoo.messagebus.EmptyReply)21 Reply (com.yahoo.messagebus.Reply)15 Error (com.yahoo.messagebus.Error)8 Test (org.junit.Test)3 RouteMetricSet (com.yahoo.clientmetrics.RouteMetricSet)2 Version (com.yahoo.component.Version)2 Response (com.yahoo.jdisc.Response)2 TestDriver (com.yahoo.jdisc.test.TestDriver)2 Message (com.yahoo.messagebus.Message)2 Hop (com.yahoo.messagebus.routing.Hop)2 Route (com.yahoo.messagebus.routing.Route)2 RoutingNode (com.yahoo.messagebus.routing.RoutingNode)2 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)2 Utf8Array (com.yahoo.text.Utf8Array)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 CompressionType (com.yahoo.compress.CompressionType)1 DocumentIgnoredReply (com.yahoo.documentapi.messagebus.protocol.DocumentIgnoredReply)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)1