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);
}
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);
}
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);
}
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);
}
}
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();
}
Aggregations