Search in sources :

Example 26 with Error

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

the class FeedResponse method handleReply.

public boolean handleReply(Reply reply) {
    metrics.addReply(reply);
    if (reply.getTrace().getLevel() > 0) {
        String str = reply.getTrace().toString();
        traces.append(str);
        System.out.println(str);
    }
    if (containsFatalErrors(reply.getErrors())) {
        for (int i = 0; i < reply.getNumErrors(); ++i) {
            Error err = reply.getError(i);
            StringBuilder out = new StringBuilder(prettyPrint(reply.getMessage()));
            out.append("[").append(DocumentProtocol.getErrorName(err.getCode())).append("] ");
            if (err.getService() != null) {
                out.append("(").append(err.getService()).append(") ");
            }
            out.append(err.getMessage());
            String str = out.toString();
            log.finest(str);
            addError(convertErrorCode(err.getCode()), str);
        }
        if (abortOnError) {
            isAborted = true;
            return false;
        }
    }
    return true;
}
Also used : Error(com.yahoo.messagebus.Error) Utf8String(com.yahoo.text.Utf8String)

Example 27 with Error

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

the class DummyReceiver method handleMessage.

public void handleMessage(Message message) {
    messageCount++;
    if (silentNum == 0) {
        System.out.println("Received message " + message + ". Received " + messageCount + " messages so far. In queue size " + queue.size());
        if (verbose) {
            if (message instanceof PutDocumentMessage) {
                System.out.println("  Document:\n" + ((PutDocumentMessage) message).getDocumentPut().getDocument().toXML("  "));
            } else if (message instanceof RemoveDocumentMessage) {
                System.out.println("  Document id: " + ((RemoveDocumentMessage) message).getDocumentId());
            } else if (message instanceof UpdateDocumentMessage) {
                System.out.println("  Update:\n  " + ((UpdateDocumentMessage) message).getDocumentUpdate().toString());
            }
        }
    } else {
        if ((messageCount % silentNum) == 0) {
            System.out.println("Received " + messageCount + " messages so far. In queue size " + queue.size());
        }
    }
    EmptyReply reply = new EmptyReply();
    message.swapState(reply);
    if (!instant) {
        try {
            executor.execute(new Task(reply));
        } catch (RejectedExecutionException e) {
            reply.addError(new Error(ErrorCode.SESSION_BUSY, "Session " + name + "/default is busy"));
            session.reply(reply);
        }
    } else {
        session.reply(reply);
    }
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Error(com.yahoo.messagebus.Error) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 28 with Error

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

the class BucketStatsRetrieverTest method testShouldFailOnReplyError.

@Test(expected = BucketStatsException.class)
public void testShouldFailOnReplyError() throws BucketStatsException {
    GetBucketListReply reply = new GetBucketListReply();
    reply.addError(new Error(0, "errormsg"));
    when(mockedSession.syncSend(any())).thenReturn(reply);
    createRetriever().retrieveBucketList(new BucketId(1), bucketSpace);
}
Also used : GetBucketListReply(com.yahoo.documentapi.messagebus.protocol.GetBucketListReply) Error(com.yahoo.messagebus.Error) BucketId(com.yahoo.document.BucketId) Test(org.junit.Test)

Example 29 with Error

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

the class PolicyTestCase method testSubsetService.

@Test
public void testSubsetService() {
    PolicyTestFrame frame = new PolicyTestFrame("docproc/cluster.default", manager);
    frame.setMessage(new PutDocumentMessage(new DocumentPut(new DocumentPut(new Document(manager.getDocumentType("testdoc"), new DocumentId("doc:scheme:"))))));
    // Test requerying for adding nodes.
    frame.setHop(new HopSpec("test", "docproc/cluster.default/[SubsetService:2]/chain.default"));
    Set<String> lst = new HashSet<>();
    for (int i = 1; i <= 10; ++i) {
        frame.getNetwork().registerSession(i + "/chain.default");
        assertTrue(frame.waitSlobrok("docproc/cluster.default/*/chain.default", i));
        RoutingNode leaf = frame.select(1).get(0);
        lst.add(leaf.getRoute().toString());
        leaf.handleReply(new EmptyReply());
        assertNotNull(frame.getReceptor().getReply(TIMEOUT));
    }
    // must have requeried
    assertTrue(lst.size() > 1);
    // Test load balancing.
    String prev = null;
    for (int i = 1; i <= 10; ++i) {
        RoutingNode leaf = frame.select(1).get(0);
        String next = leaf.getRoute().toString();
        if (prev == null) {
            assertNotNull(next);
        } else {
            assertFalse(prev.equals(next));
        }
        prev = next;
        leaf.handleReply(new EmptyReply());
        assertNotNull(frame.getReceptor().getReply(TIMEOUT));
    }
    // Test requerying for dropping nodes.
    lst.clear();
    for (int i = 1; i <= 10; ++i) {
        RoutingNode leaf = frame.select(1).get(0);
        String route = leaf.getRoute().toString();
        lst.add(route);
        frame.getNetwork().unregisterSession(route.substring(frame.getIdentity().length() + 1));
        assertTrue(frame.waitSlobrok("docproc/cluster.default/*/chain.default", 10 - i));
        Reply reply = new EmptyReply();
        reply.addError(new Error(ErrorCode.NO_ADDRESS_FOR_SERVICE, route));
        leaf.handleReply(reply);
        assertNotNull(frame.getReceptor().getReply(TIMEOUT));
    }
    assertEquals(10, lst.size());
    // Test merge behavior.
    frame.setHop(new HopSpec("test", "[SubsetService]"));
    frame.assertMergeOneReply("*");
    frame.destroy();
}
Also used : Error(com.yahoo.messagebus.Error) Test(org.junit.Test)

Example 30 with Error

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

the class MbusClient method sendMessage.

private boolean sendMessage(final MbusRequest request) {
    Error error;
    final Long millis = request.timeRemaining(TimeUnit.MILLISECONDS);
    if (millis != null && millis <= 0) {
        error = new Error(ErrorCode.TIMEOUT, request.getTimeout(TimeUnit.MILLISECONDS) + " millis");
    } else if (request.isCancelled()) {
        error = new Error(ErrorCode.APP_FATAL_ERROR, "request cancelled");
    } else {
        try {
            error = session.sendMessage(request.getMessage()).getError();
        } catch (final Exception e) {
            error = new Error(ErrorCode.FATAL_ERROR, e.toString());
        }
    }
    if (error == null) {
        return true;
    }
    if (error.isFatal()) {
        final Reply reply = new EmptyReply();
        reply.swapState(request.getMessage());
        reply.addError(error);
        reply.popHandler().handleReply(reply);
        return true;
    }
    return false;
}
Also used : Error(com.yahoo.messagebus.Error) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) EmptyReply(com.yahoo.messagebus.EmptyReply)

Aggregations

Error (com.yahoo.messagebus.Error)51 Test (org.junit.Test)22 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)10 EmptyReply (com.yahoo.messagebus.EmptyReply)9 Reply (com.yahoo.messagebus.Reply)9 Receptor (com.yahoo.messagebus.test.Receptor)9 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 ParseException (com.yahoo.document.select.parser.ParseException)4 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)4 BucketId (com.yahoo.document.BucketId)3 Message (com.yahoo.messagebus.Message)3 Version (com.yahoo.component.Version)2 DataValue (com.yahoo.jrt.DataValue)2 Protocol (com.yahoo.messagebus.Protocol)2 Hop (com.yahoo.messagebus.routing.Hop)2 Slime (com.yahoo.slime.Slime)2 Utf8Array (com.yahoo.text.Utf8Array)2 Utf8String (com.yahoo.text.Utf8String)2 IOException (java.io.IOException)2