Search in sources :

Example 1 with DocumentRemove

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

the class OperationHandlerImpl method delete.

@Override
public void delete(RestUri restUri, String condition, Optional<String> route) throws RestApiException {
    SyncSession syncSession = syncSessions.alloc();
    Response response;
    try {
        Instant startTime = Instant.now();
        DocumentId id = new DocumentId(restUri.generateFullId());
        DocumentRemove documentRemove = new DocumentRemove(id);
        setRoute(syncSession, route);
        if (condition != null && !condition.isEmpty()) {
            documentRemove.setCondition(new TestAndSetCondition(condition));
        }
        syncSession.remove(documentRemove);
        metricsHelper.reportSuccessful(DocumentOperationType.REMOVE, startTime);
        return;
    } catch (DocumentAccessException documentException) {
        if (documentException.hasConditionNotMetError()) {
            response = Response.createErrorResponse(412, "Condition not met: " + documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_CONDITION_NOT_MET);
        } else {
            response = Response.createErrorResponse(400, documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_EXCPETION);
        }
    } catch (Exception e) {
        response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED);
    } finally {
        syncSessions.free(syncSession);
    }
    metricsHelper.reportFailure(DocumentOperationType.REMOVE, DocumentOperationStatus.fromHttpStatusCode(response.getStatus()));
    throw new RestApiException(response);
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) Instant(java.time.Instant) DocumentId(com.yahoo.document.DocumentId) SyncSession(com.yahoo.documentapi.SyncSession) MessageBusSyncSession(com.yahoo.documentapi.messagebus.MessageBusSyncSession) TestAndSetCondition(com.yahoo.document.TestAndSetCondition) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 2 with DocumentRemove

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

the class DocumentOperationMessageV3 method newRemoveMessage.

static DocumentOperationMessageV3 newRemoveMessage(VespaXMLFeedReader.Operation op, String operationId) {
    DocumentRemove remove = new DocumentRemove(op.getRemove());
    remove.setCondition(op.getCondition());
    Message msg = new RemoveDocumentMessage(remove);
    String id = (operationId == null) ? remove.getId().toString() : operationId;
    return new DocumentOperationMessageV3(id, msg);
}
Also used : RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) DocumentRemove(com.yahoo.document.DocumentRemove) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)

Example 3 with DocumentRemove

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

the class Feeder method newRemoveMessage.

private Tuple2<String, Message> newRemoveMessage(Operation op, String operationId) {
    DocumentRemove remove = new DocumentRemove(op.getRemove());
    remove.setCondition(op.getCondition());
    Message msg = new RemoveDocumentMessage(remove);
    String id = (operationId == null) ? remove.getId().toString() : operationId;
    return new Tuple2<>(id, msg);
}
Also used : RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) DocumentRemove(com.yahoo.document.DocumentRemove) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Tuple2(com.yahoo.collections.Tuple2) Utf8String(com.yahoo.text.Utf8String)

Example 4 with DocumentRemove

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

the class JsonFeedReader method read.

@Override
public void read(Operation operation) throws Exception {
    DocumentOperation documentOperation = reader.next();
    if (documentOperation == null) {
        stream.close();
        operation.setInvalid();
        return;
    }
    if (documentOperation instanceof DocumentUpdate) {
        operation.setDocumentUpdate((DocumentUpdate) documentOperation);
    } else if (documentOperation instanceof DocumentRemove) {
        operation.setRemove(documentOperation.getId());
    } else if (documentOperation instanceof DocumentPut) {
        operation.setDocument(((DocumentPut) documentOperation).getDocument());
    } else {
        throw new IllegalStateException("Got unknown class from JSON reader: " + documentOperation.getClass().getName());
    }
    operation.setCondition(documentOperation.getCondition());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut)

Example 5 with DocumentRemove

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

the class JsonReaderTestCase method testCompleteFeedWithCreateAndCondition.

@Test
public final void testCompleteFeedWithCreateAndCondition() {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}" + ", " + "{" + "\"condition\":\"bla\"," + "\"update\": \"id:unittest:testarray::whee\"," + " \"create\":true," + " \"fields\": { " + "\"actualarray\": {" + " \"add\": [" + " \"person\"," + " \"another person\"]}}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentOperation d = r.next();
    Document doc = ((DocumentPut) d).getDocument();
    smokeTestDoc(doc);
    d = r.next();
    DocumentUpdate update = (DocumentUpdate) d;
    checkSimpleArrayAdd(update);
    assertThat(update.getCreateIfNonExistent(), is(true));
    assertThat(update.getCondition().getSelection(), is("bla"));
    d = r.next();
    DocumentRemove remove = (DocumentRemove) d;
    assertEquals("smoke", remove.getId().getDocType());
    assertNull(r.next());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

DocumentRemove (com.yahoo.document.DocumentRemove)13 DocumentPut (com.yahoo.document.DocumentPut)8 DocumentUpdate (com.yahoo.document.DocumentUpdate)6 Test (org.junit.Test)6 Document (com.yahoo.document.Document)5 DocumentOperation (com.yahoo.document.DocumentOperation)5 DocumentId (com.yahoo.document.DocumentId)4 DocumentType (com.yahoo.document.DocumentType)3 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)2 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)2 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)2 Message (com.yahoo.messagebus.Message)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Tuple2 (com.yahoo.collections.Tuple2)1 Processing (com.yahoo.docproc.Processing)1 TestAndSetCondition (com.yahoo.document.TestAndSetCondition)1 JsonReaderException (com.yahoo.document.json.JsonReaderException)1 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)1 SyncSession (com.yahoo.documentapi.SyncSession)1