diff options
author | Haakon Dybdahl <dybdahl@yahoo-inc.com> | 2017-02-27 10:02:55 +0100 |
---|---|---|
committer | Haakon Dybdahl <dybdahl@yahoo-inc.com> | 2017-02-27 10:02:55 +0100 |
commit | ceaa98f507b652b571300ca8771051bb35f1790f (patch) | |
tree | 5c9900c0cb7e9652c4f957deb9bf23a7b33f5981 /vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi | |
parent | 01a7850d2ec5c980238cd54f5ca4b7d9dae1a316 (diff) |
Add route option, to be tested in system test.
Diffstat (limited to 'vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi')
3 files changed, 27 insertions, 9 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java index fb1b317399c..1a9c8c46693 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java @@ -25,11 +25,11 @@ public interface OperationHandler { VisitResult visit(RestUri restUri, String documentSelection, Optional<String> cluster, Optional<String> continuation) throws RestApiException; - void put(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException; + void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException; - void update(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException; + void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException; - void delete(RestUri restUri, String condition) throws RestApiException; + void delete(RestUri restUri, String condition, Optional<String> route) throws RestApiException; Optional<String> get(RestUri restUri) throws RestApiException; diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java index 5ad7524ca2f..93b6dfcab71 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java @@ -14,6 +14,7 @@ import com.yahoo.documentapi.SyncSession; import com.yahoo.documentapi.VisitorControlHandler; import com.yahoo.documentapi.VisitorParameters; import com.yahoo.documentapi.VisitorSession; +import com.yahoo.documentapi.messagebus.MessageBusSyncSession; import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; import com.yahoo.messagebus.StaticThrottlePolicy; import com.yahoo.storage.searcher.ContinuationHit; @@ -140,12 +141,24 @@ public class OperationHandlerImpl implements OperationHandler { throw new RestApiException(Response.createErrorResponse(500, localDataVisitorHandler.getErrors(), restUri)); } + private void setRoute(SyncSession session, Optional<String> route) throws RestApiException { + if (route.isPresent()) { + if (! (session instanceof MessageBusSyncSession)) { + // Not sure if this ever could happen but better be safe. + throw new RestApiException(Response.createErrorResponse( + 400, "Can not set route since the API is not using message bus.")); + } + ((MessageBusSyncSession) session).setRoute(route.get()); + } + } + @Override - public void put(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + public void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); try { DocumentPut put = new DocumentPut(data.getDocument()); put.setCondition(data.getCondition()); + setRoute(syncSession, route); syncSession.put(put); } catch (DocumentAccessException documentException) { throw new RestApiException(createErrorResponse(documentException, restUri)); @@ -157,8 +170,9 @@ public class OperationHandlerImpl implements OperationHandler { } @Override - public void update(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + public void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); + setRoute(syncSession, route); try { syncSession.update(data.getDocumentUpdate()); } catch (DocumentAccessException documentException) { @@ -171,8 +185,9 @@ public class OperationHandlerImpl implements OperationHandler { } @Override - public void delete(RestUri restUri, String condition) throws RestApiException { + public void delete(RestUri restUri, String condition, Optional<String> route) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); + setRoute(syncSession, route); try { DocumentId id = new DocumentId(restUri.generateFullId()); DocumentRemove documentRemove = new DocumentRemove(id); diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index 80769909b9f..1cffe9d8ff6 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -43,6 +43,7 @@ public class RestApi extends LoggingRequestHandler { private static final String CREATE_PARAMETER_NAME = "create"; private static final String CONDITION_PARAMETER_NAME = "condition"; + private static final String ROUTE_PARAMETER_NAME = "route"; private static final String DOCUMENTS = "documents"; private static final String FIELDS = "fields"; private static final String DOC_ID_NAME = "id"; @@ -138,19 +139,21 @@ public class RestApi extends LoggingRequestHandler { "false: " + request.getProperty(CREATE_PARAMETER_NAME)); } String condition = request.getProperty(CONDITION_PARAMETER_NAME); + Optional<String> route = Optional.ofNullable(request.getProperty(ROUTE_PARAMETER_NAME)); + Optional<ObjectNode> resultJson = Optional.empty(); try { switch (request.getMethod()) { case GET: // Vespa Visit/Get return restUri.getDocId().isEmpty() ? handleVisit(restUri, request) : handleGet(restUri); case POST: // Vespa Put - operationHandler.put(restUri, createPutOperation(request, restUri.generateFullId(), condition)); + operationHandler.put(restUri, createPutOperation(request, restUri.generateFullId(), condition), route); break; case PUT: // Vespa Update - operationHandler.update(restUri, createUpdateOperation(request, restUri.generateFullId(), condition, create)); + operationHandler.update(restUri, createUpdateOperation(request, restUri.generateFullId(), condition, create), route); break; case DELETE: // Vespa Delete - operationHandler.delete(restUri, condition); + operationHandler.delete(restUri, condition, route); break; default: return new Response(405, Optional.empty(), Optional.of(restUri)); |