Search in sources :

Example 1 with DocumentAccessException

use of com.yahoo.documentapi.DocumentAccessException in project vespa by vespa-engine.

the class OperationHandlerImpl method put.

@Override
public void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException {
    SyncSession syncSession = syncSessions.alloc();
    Response response;
    try {
        Instant startTime = Instant.now();
        DocumentPut put = new DocumentPut(data.getDocument());
        put.setCondition(data.getCondition());
        setRoute(syncSession, route);
        syncSession.put(put);
        metricsHelper.reportSuccessful(DocumentOperationType.PUT, startTime);
        return;
    } catch (DocumentAccessException documentException) {
        response = createErrorResponse(documentException, restUri);
    } catch (Exception e) {
        response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.INTERNAL_EXCEPTION);
    } finally {
        syncSessions.free(syncSession);
    }
    metricsHelper.reportFailure(DocumentOperationType.PUT, DocumentOperationStatus.fromHttpStatusCode(response.getStatus()));
    throw new RestApiException(response);
}
Also used : Instant(java.time.Instant) DocumentPut(com.yahoo.document.DocumentPut) SyncSession(com.yahoo.documentapi.SyncSession) MessageBusSyncSession(com.yahoo.documentapi.messagebus.MessageBusSyncSession) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 2 with DocumentAccessException

use of com.yahoo.documentapi.DocumentAccessException in project vespa by vespa-engine.

the class OperationHandlerImpl method update.

@Override
public void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException {
    SyncSession syncSession = syncSessions.alloc();
    Response response;
    try {
        Instant startTime = Instant.now();
        setRoute(syncSession, route);
        syncSession.update(data.getDocumentUpdate());
        metricsHelper.reportSuccessful(DocumentOperationType.UPDATE, startTime);
        return;
    } catch (DocumentAccessException documentException) {
        response = createErrorResponse(documentException, restUri);
    } catch (Exception e) {
        response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.INTERNAL_EXCEPTION);
    } finally {
        syncSessions.free(syncSession);
    }
    metricsHelper.reportFailure(DocumentOperationType.UPDATE, DocumentOperationStatus.fromHttpStatusCode(response.getStatus()));
    throw new RestApiException(response);
}
Also used : Instant(java.time.Instant) SyncSession(com.yahoo.documentapi.SyncSession) MessageBusSyncSession(com.yahoo.documentapi.messagebus.MessageBusSyncSession) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 3 with DocumentAccessException

use of com.yahoo.documentapi.DocumentAccessException 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 4 with DocumentAccessException

use of com.yahoo.documentapi.DocumentAccessException in project vespa by vespa-engine.

the class MessageBusSyncSession method syncSend.

private Reply syncSend(Message msg, Duration timeout) {
    if (timeout != null) {
        msg.setTimeRemaining(timeout.toMillis());
    }
    try {
        RequestMonitor monitor = new RequestMonitor();
        msg.setContext(monitor);
        // store monitor
        msg.pushHandler(this);
        Result result = null;
        while (result == null || result.type() == Result.ResultType.TRANSIENT_ERROR) {
            result = session.send(msg);
            if (result != null && result.isSuccess()) {
                break;
            }
            Thread.sleep(100);
        }
        if (!result.isSuccess()) {
            throw new DocumentAccessException(result.getError().toString());
        }
        return monitor.waitForReply();
    } catch (InterruptedException e) {
        throw new DocumentAccessException(e);
    }
}
Also used : Result(com.yahoo.documentapi.Result) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 5 with DocumentAccessException

use of com.yahoo.documentapi.DocumentAccessException in project vespa by vespa-engine.

the class MessageBusSyncSession method update.

@Override
public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) {
    UpdateDocumentMessage msg = new UpdateDocumentMessage(update);
    msg.setPriority(pri);
    Reply reply = syncSend(msg);
    if (reply.hasErrors()) {
        throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply), reply.getErrorCodes());
    }
    if (reply.getType() != DocumentProtocol.REPLY_UPDATEDOCUMENT) {
        throw new DocumentAccessException("Received unknown response: " + reply);
    }
    return ((UpdateDocumentReply) reply).wasFound();
}
Also used : UpdateDocumentReply(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply) Reply(com.yahoo.messagebus.Reply) RemoveDocumentReply(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply) UpdateDocumentReply(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Aggregations

DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)6 SyncSession (com.yahoo.documentapi.SyncSession)3 MessageBusSyncSession (com.yahoo.documentapi.messagebus.MessageBusSyncSession)3 Instant (java.time.Instant)3 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)2 RemoveDocumentReply (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply)2 UpdateDocumentReply (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply)2 Reply (com.yahoo.messagebus.Reply)2 Document (com.yahoo.document.Document)1 DocumentId (com.yahoo.document.DocumentId)1 DocumentPut (com.yahoo.document.DocumentPut)1 DocumentRemove (com.yahoo.document.DocumentRemove)1 TestAndSetCondition (com.yahoo.document.TestAndSetCondition)1 Result (com.yahoo.documentapi.Result)1 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)1 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)1