Search in sources :

Example 36 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class VespaFeedHandlerRemove method handle.

@Override
public HttpResponse handle(HttpRequest request) {
    if (request.getProperty("status") != null) {
        return new MetricResponse(context.getMetrics().getMetricSet());
    }
    MessagePropertyProcessor.PropertySetter properties = getPropertyProcessor().buildPropertySetter(request);
    String route = properties.getRoute().toString();
    FeedResponse response = new FeedResponse(new RouteMetricSet(route, null));
    SingleSender sender = new SingleSender(response, getSharedSender(route));
    sender.addMessageProcessor(properties);
    response.setAbortOnFeedError(properties.getAbortOnFeedError());
    if (request.hasProperty("id")) {
        sender.remove(new DocumentId(request.getProperty("id")));
    } else if (request.hasProperty("id[0]")) {
        int index = 0;
        while (request.hasProperty("id[" + index + "]")) {
            sender.remove(new DocumentId(request.getProperty("id[" + index + "]")));
            ++index;
        }
    }
    if (request.getData() != null) {
        try {
            String line;
            BufferedReader reader = new BufferedReader(new InputStreamReader(getRequestInputStream(request), "UTF-8"));
            while ((line = reader.readLine()) != null) {
                sender.remove(new DocumentId(line));
            }
        } catch (Exception e) {
            response.addError(e.getClass() + ": " + e.getCause());
        }
    }
    sender.done();
    long millis = getTimeoutMillis(request);
    boolean completed = sender.waitForPending(millis);
    if (!completed)
        response.addError(Error.TIMEOUT, "Timed out after " + millis + " ms waiting for responses");
    return response;
}
Also used : InputStreamReader(java.io.InputStreamReader) DocumentId(com.yahoo.document.DocumentId) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) SingleSender(com.yahoo.feedapi.SingleSender) BufferedReader(java.io.BufferedReader) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor)

Example 37 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class GetSearcher method sendDocumentGetMessages.

private void sendDocumentGetMessages(List<String> documentIds, String fieldSet, SingleSender sender) {
    for (String docIdStr : documentIds) {
        DocumentId docId = new DocumentId(docIdStr);
        GetDocumentMessage getMsg = new GetDocumentMessage(docId, fieldSet);
        sender.send(getMsg);
        if (log.isLoggable(LogLevel.DEBUG)) {
            log.log(LogLevel.DEBUG, "Sent GetDocumentMessage for " + docId.toString());
        }
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)

Example 38 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class DocumentRetrieverTest method testShowDocSize.

@Test
public void testShowDocSize() throws DocumentRetrieverException {
    ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setShowDocSize(true).build();
    Document document = new Document(DataType.DOCUMENT, new DocumentId(DOC_ID_1));
    when(mockedSession.syncSend(any())).thenReturn(new GetDocumentReply(document));
    DocumentRetriever documentRetriever = createDocumentRetriever(params);
    documentRetriever.retrieveDocuments();
    assertTrue(outContent.toString().contains(String.format("Document size: %d bytes", document.getSerializedSize())));
}
Also used : DocumentId(com.yahoo.document.DocumentId) Document(com.yahoo.document.Document) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 39 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class DocumentRetrieverTest method testTrace.

@Test
public void testTrace() throws DocumentRetrieverException {
    final int traceLevel = 9;
    ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setTraceLevel(traceLevel).build();
    GetDocumentReply reply = new GetDocumentReply(new Document(DataType.DOCUMENT, new DocumentId(DOC_ID_1)));
    reply.getTrace().getRoot().addChild("childnode");
    when(mockedSession.syncSend(any())).thenReturn(reply);
    DocumentRetriever documentRetriever = createDocumentRetriever(params);
    documentRetriever.retrieveDocuments();
    verify(mockedSession, times(1)).setTraceLevel(traceLevel);
    assertTrue(outContent.toString().contains("<trace>"));
}
Also used : DocumentId(com.yahoo.document.DocumentId) Document(com.yahoo.document.Document) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 40 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class BucketStatsRetrieverTest method testRoute.

@Test
public void testRoute() throws BucketStatsException {
    String route = "default";
    BucketId bucketId = bucketIdFactory.getBucketId(new DocumentId("id:ns:type::another"));
    GetBucketListReply reply = new GetBucketListReply();
    reply.getBuckets().add(new GetBucketListReply.BucketInfo(bucketId, "I like turtles!"));
    when(mockedSession.syncSend(any())).thenReturn(reply);
    BucketStatsRetriever retriever = new BucketStatsRetriever(mockedFactory, route, t -> {
    });
    retriever.retrieveBucketList(new BucketId(0), bucketSpace);
    verify(mockedSession).syncSend(argThat(new ArgumentMatcher<Message>() {

        @Override
        public boolean matches(Object o) {
            return ((Message) o).getRoute().equals(Route.parse(route));
        }
    }));
}
Also used : GetBucketListReply(com.yahoo.documentapi.messagebus.protocol.GetBucketListReply) ArgumentMatcher(org.mockito.ArgumentMatcher) DocumentId(com.yahoo.document.DocumentId) BucketId(com.yahoo.document.BucketId) Test(org.junit.Test)

Aggregations

DocumentId (com.yahoo.document.DocumentId)61 Test (org.junit.Test)28 DocumentType (com.yahoo.document.DocumentType)20 Document (com.yahoo.document.Document)16 DocumentPut (com.yahoo.document.DocumentPut)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)9 BucketId (com.yahoo.document.BucketId)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 BucketIdFactory (com.yahoo.document.BucketIdFactory)4 FieldUpdate (com.yahoo.document.update.FieldUpdate)4 DocumentOperation (com.yahoo.document.DocumentOperation)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Hit (com.yahoo.search.result.Hit)3 HashMap (java.util.HashMap)3 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 Field (com.yahoo.document.Field)2 GlobalId (com.yahoo.document.GlobalId)2 StructDataType (com.yahoo.document.StructDataType)2 Struct (com.yahoo.document.datatypes.Struct)2