From df143f9c6522282800c88715b645039e96ef12eb Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Fri, 6 May 2016 10:38:32 +0200 Subject: [PATCH] Bug 5528 - API for RESTful - transaction part of CRUD Change-Id: I2e8fad15f1ee2f9fbef1dfabdd36258c59c9d86e Signed-off-by: Jakub Toth --- .../netconf/sal/rest/api/RestconfService.java | 59 ++++++- .../services/api/RestconfDataService.java | 147 ++++++++++++++++++ .../api/RestconfInvokeOperationsService.java | 54 +++++++ .../RestconfStreamsSubscriptionService.java | 36 +++++ 4 files changed, 290 insertions(+), 6 deletions(-) create mode 100644 restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfDataService.java create mode 100644 restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfInvokeOperationsService.java create mode 100644 restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfStreamsSubscriptionService.java diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java index 5bb80f7d2e..1c99af58ba 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java @@ -29,6 +29,8 @@ import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext; import org.opendaylight.restconf.rest.api.services.RestconfModulesService; import org.opendaylight.restconf.rest.api.services.RestconfOperationsService; import org.opendaylight.restconf.rest.api.services.RestconfStreamsService; +import org.opendaylight.restconf.restful.services.api.RestconfDataService; +import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService; /** * The URI hierarchy for the RESTCONF resources consists of an entry point container, 4 top-level resources, and 1 @@ -62,7 +64,7 @@ public interface RestconfService { public Object getRoot(); /** - * @deprecated do not use this method. It is replaced by + * @deprecated do not use this method. It will be replaced by * {@link RestconfModulesService#getModules(UriInfo)} */ @Deprecated @@ -73,7 +75,7 @@ public interface RestconfService { public NormalizedNodeContext getModules(@Context UriInfo uriInfo); /** - * @deprecated do not use this method. It is replaced by + * @deprecated do not use this method. It will be replaced by * {@link RestconfModulesService#getModules(String, UriInfo)} */ @Deprecated @@ -84,7 +86,7 @@ public interface RestconfService { public NormalizedNodeContext getModules(@PathParam("identifier") String identifier, @Context UriInfo uriInfo); /** - * @deprecated do not use this method. It is replaced by + * @deprecated do not use this method. It will be replaced by * {@link RestconfModulesService#getModule(String, UriInfo)} */ @Deprecated @@ -95,7 +97,7 @@ public interface RestconfService { public NormalizedNodeContext getModule(@PathParam("identifier") String identifier, @Context UriInfo uriInfo); /** - * @deprecated do not use this method. It is replaced by + * @deprecated do not use this method. It will be replaced by * {@link RestconfOperationsService#getOperations(UriInfo)} */ @Deprecated @@ -106,7 +108,7 @@ public interface RestconfService { public NormalizedNodeContext getOperations(@Context UriInfo uriInfo); /** - * @deprecated do not use this method. It is replaced by + * @deprecated do not use this method. It will be replaced by * {@link RestconfOperationsService#getOperations(String, UriInfo)} */ @Deprecated @@ -116,6 +118,11 @@ public interface RestconfService { MediaType.APPLICATION_XML, MediaType.TEXT_XML }) public NormalizedNodeContext getOperations(@PathParam("identifier") String identifier, @Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfInvokeOperationsService#invokeRpc(String, NormalizedNodeContext, UriInfo)} + */ + @Deprecated @POST @Path("/operations/{identifier:.+}") @Produces({ Draft02.MediaTypes.OPERATION + JSON, Draft02.MediaTypes.OPERATION + XML, @@ -136,6 +143,11 @@ public interface RestconfService { public NormalizedNodeContext invokeRpc(@Encoded @PathParam("identifier") String identifier, @DefaultValue("") String noPayload, @Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#readData(String, UriInfo)} + */ + @Deprecated @GET @Path("/config/{identifier:.+}") @Produces({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON, @@ -143,6 +155,11 @@ public interface RestconfService { public NormalizedNodeContext readConfigurationData(@Encoded @PathParam("identifier") String identifier, @Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#readData(String, UriInfo)} + */ + @Deprecated @GET @Path("/operational/{identifier:.+}") @Produces({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON, @@ -150,12 +167,22 @@ public interface RestconfService { public NormalizedNodeContext readOperationalData(@Encoded @PathParam("identifier") String identifier, @Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#putData(String, NormalizedNodeContext)} + */ + @Deprecated @PUT @Path("/config/{identifier:.+}") @Consumes({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML }) public Response updateConfigurationData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#postData(String, NormalizedNodeContext, UriInfo)} + */ + @Deprecated @POST @Path("/config/{identifier:.+}") @Consumes({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON, @@ -163,12 +190,22 @@ public interface RestconfService { public Response createConfigurationData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload, @Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#postData(NormalizedNodeContext, UriInfo)} + */ + @Deprecated @POST @Path("/config") @Consumes({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML }) public Response createConfigurationData(NormalizedNodeContext payload, @Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#deleteData(String)} + */ + @Deprecated @DELETE @Path("/config/{identifier:.+}") public Response deleteConfigurationData(@Encoded @PathParam("identifier") String identifier); @@ -178,7 +215,7 @@ public interface RestconfService { public Response subscribeToStream(@Encoded @PathParam("identifier") String identifier, @Context UriInfo uriInfo); /** - * @deprecated do not use this method. It is replaced by + * @deprecated do not use this method. It will be replaced by * {@link RestconfStreamsService#getAvailableStreams(UriInfo)} */ @Deprecated @@ -188,6 +225,11 @@ public interface RestconfService { MediaType.APPLICATION_XML, MediaType.TEXT_XML }) public NormalizedNodeContext getAvailableStreams(@Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#patchData(String, PATCHContext, UriInfo)} + */ + @Deprecated @PATCH @Path("/config/{identifier:.+}") @Consumes({MediaTypes.PATCH + JSON, MediaTypes.PATCH + XML}) @@ -195,6 +237,11 @@ public interface RestconfService { PATCHStatusContext patchConfigurationData(@Encoded @PathParam("identifier") String identifier, PATCHContext context, @Context UriInfo uriInfo); + /** + * @deprecated do not use this method. It will be replaced by + * {@link RestconfDataService#patchData(PATCHContext, UriInfo)} + */ + @Deprecated @PATCH @Path("/config") @Consumes({MediaTypes.PATCH + JSON, MediaTypes.PATCH + XML}) diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfDataService.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfDataService.java new file mode 100644 index 0000000000..d7ae1f65df --- /dev/null +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfDataService.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.restful.services.api; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.Encoded; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import org.opendaylight.netconf.sal.rest.impl.PATCH; +import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; +import org.opendaylight.netconf.sal.restconf.impl.PATCHContext; +import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext; +import org.opendaylight.restconf.Draft11; +import org.opendaylight.restconf.utils.RestconfConstants; + +/** + * The "{+restconf}/data" subtree represents the datastore resource type, which + * is a collection of configuration data and state data nodes + * + */ +public interface RestconfDataService { + + /** + * Get target data resource. + * + * @param identifier + * - path to target + * @param uriInfo + * - URI info + * @return {@link NormalizedNodeContext} + */ + @GET + @Path("/data/{identifier:.+}") + @Produces({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML }) + NormalizedNodeContext readData(@Encoded @PathParam("identifier") String identifier, + @Context UriInfo uriInfo); + + /** + * Create or replace the target data resource. + * + * @param identifier + * - path to target + * @param payload + * - data node for put to config DS + * @return {@link Response} + */ + @PUT + @Path("/data/{identifier:.+}") + @Consumes({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML }) + Response putData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload); + + /** + * Create a data resource in target. + * + * @param identifier + * - path to target + * @param payload + * - new data + * @param uriInfo + * - URI info + * @return {@link Response} + */ + @POST + @Path("/data/{identifier:.+}") + @Consumes({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML }) + Response postData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload, + @Context UriInfo uriInfo); + + /** + * Create a data resource. + * + * @param payload + * - new data + * @param uriInfo + * - URI info + * @return {@link Response} + */ + @POST + @Path("/data") + @Consumes({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML }) + Response postData(NormalizedNodeContext payload, @Context UriInfo uriInfo); + + /** + * Delete the target data resource. + * + * @param identifier + * - path to target + * @return {@link Response} + */ + @DELETE + @Path("/data/{identifier:.+}") + Response deleteData(@Encoded @PathParam("identifier") String identifier); + + /** + * Ordered list of edits that are applied to the target datastore by the + * server. + * + * @param identifier + * - path to target + * @param context + * - edits + * @param uriInfo + * - URI info + * @return {@link PATCHStatusContext} + */ + @PATCH + @Path("/data/{identifier:.+}") + @Consumes({ Draft11.MediaTypes.PATCH + RestconfConstants.JSON, Draft11.MediaTypes.PATCH + RestconfConstants.XML }) + @Produces({ Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.JSON, + Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.XML }) + PATCHStatusContext patchData(@Encoded @PathParam("identifier") String identifier, PATCHContext context, + @Context UriInfo uriInfo); + + /** + * Ordered list of edits that are applied to the datastore by the server. + * + * @param context + * - edits + * @param uriInfo + * - URI info + * @return {@link PATCHStatusContext} + */ + @PATCH + @Path("/data") + @Consumes({ Draft11.MediaTypes.PATCH + RestconfConstants.JSON, Draft11.MediaTypes.PATCH + RestconfConstants.XML }) + @Produces({ Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.JSON, + Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.XML }) + PATCHStatusContext patchData(PATCHContext context, @Context UriInfo uriInfo); +} diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfInvokeOperationsService.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfInvokeOperationsService.java new file mode 100644 index 0000000000..91a45556b9 --- /dev/null +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfInvokeOperationsService.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.restful.services.api; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Encoded; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; +import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; +import org.opendaylight.restconf.Draft11; +import org.opendaylight.restconf.utils.RestconfConstants; + +/** + * An operation resource represents a protocol operation defined with the YANG + * "rpc" statement. It is invoked using a POST method on the operation resource. + * + */ +public interface RestconfInvokeOperationsService { + + /** + * Invoke RPC operation + * + * @param identifier + * - module name and rpc identifier string for the desired + * operation + * @param payload + * - {@link NormalizedNodeContext} - the body of the operation + * @param uriInfo + * - URI info + * @return {@link NormalizedNodeContext} + */ + @POST + @Path("/operations/{identifier:.+}") + @Produces({ Draft11.MediaTypes.OPERATION + RestconfConstants.JSON, + Draft11.MediaTypes.OPERATION + RestconfConstants.XML, Draft11.MediaTypes.DATA + RestconfConstants.JSON, + Draft11.MediaTypes.DATA + RestconfConstants.XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, + MediaType.TEXT_XML }) + @Consumes({ Draft11.MediaTypes.OPERATION + RestconfConstants.JSON, + Draft11.MediaTypes.OPERATION + RestconfConstants.XML, Draft11.MediaTypes.DATA + RestconfConstants.JSON, + Draft11.MediaTypes.DATA + RestconfConstants.XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, + MediaType.TEXT_XML }) + NormalizedNodeContext invokeRpc(@Encoded @PathParam("identifier") String identifier, + NormalizedNodeContext payload, @Context UriInfo uriInfo); +} diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfStreamsSubscriptionService.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfStreamsSubscriptionService.java new file mode 100644 index 0000000000..0528d89c44 --- /dev/null +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfStreamsSubscriptionService.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.restful.services.api; + +import javax.ws.rs.Encoded; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +/** + * Subscribing to streams + * + */ +public interface RestconfStreamsSubscriptionService { + + /** + * Subscribing to receive notification from stream support + * + * @param identifier + * - name of stream + * @param uriInfo + * - URI info + * @return {@link Response} + */ + @GET + @Path("data/ietf-restconf-monitoring:restconf-state/streams/stream/{identifier:.+}") + Response subscribeToStream(@Encoded @PathParam("identifier") String identifier, @Context UriInfo uriInfo); +} -- 2.36.6