Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.restconf.api; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.glassfish.jersey.server.ChunkedOutput; |
| 20 | |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 21 | import java.net.URI; |
| 22 | import java.util.concurrent.CompletableFuture; |
| 23 | |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 24 | /** |
| 25 | * Abstraction of RESTCONF Server functionality according to the |
| 26 | * RESTCONF RFC (no official RFC number yet). |
| 27 | */ |
| 28 | public interface RestconfService { |
| 29 | /** |
| 30 | * Processes a GET request against a data resource. The |
| 31 | * target data resource is identified by its URI. If the |
| 32 | * GET operation cannot be fulfilled due to reasons such |
| 33 | * as the nonexistence of the target resource, then a |
| 34 | * RestconfException exception is raised. The proper |
| 35 | * HTTP error status code is enclosed in the exception, so |
| 36 | * that the caller may return it to the RESTCONF client to |
| 37 | * display. |
| 38 | * |
| 39 | * @param uri URI of the target data resource |
| 40 | * @return JSON representation of the data resource |
| 41 | * @throws RestconfException if the GET operation cannot be fulfilled |
| 42 | */ |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 43 | ObjectNode runGetOperationOnDataResource(URI uri) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 44 | throws RestconfException; |
| 45 | |
| 46 | /** |
| 47 | * Processes a POST request against a data resource. The location of |
| 48 | * the target resource is passed in as a URI. And the resource's |
| 49 | * content is passed in as a JSON ObjectNode. If the POST operation |
| 50 | * cannot be fulfilled due to reasons such as wrong input URIs or |
| 51 | * syntax errors in the JSON payloads, a RestconfException exception |
| 52 | * is raised. The proper HTTP error status code is enclosed in the |
| 53 | * exception. |
| 54 | * |
| 55 | * @param uri URI of the data resource to be created |
| 56 | * @param rootNode JSON representation of the data resource |
| 57 | * @throws RestconfException if the POST operation cannot be fulfilled |
| 58 | */ |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 59 | void runPostOperationOnDataResource(URI uri, ObjectNode rootNode) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 60 | throws RestconfException; |
| 61 | |
| 62 | /** |
| 63 | * Processes a PUT request against a data resource. The location of |
| 64 | * the target resource is passed in as a URI. And the resource's |
| 65 | * content is passed in as a JSON ObjectNode. If the PUT operation |
| 66 | * cannot be fulfilled due to reasons such as wrong input URIs or |
| 67 | * syntax errors in the JSON payloads, a RestconfException exception |
| 68 | * is raised. The proper HTTP error status code is enclosed in the |
| 69 | * exception. |
| 70 | * |
| 71 | * @param uri URI of the data resource to be created or updated |
| 72 | * @param rootNode JSON representation of the data resource |
| 73 | * @throws RestconfException if the PUT operation cannot be fulfilled |
| 74 | */ |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 75 | void runPutOperationOnDataResource(URI uri, ObjectNode rootNode) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 76 | throws RestconfException; |
| 77 | |
| 78 | /** |
| 79 | * Processes the DELETE operation against a data resource. The target |
| 80 | * data resource is identified by its URI. If the DELETE operation |
| 81 | * cannot be fulfilled due reasons such as the nonexistence of the |
| 82 | * target resource, a RestconfException exception is raised. The |
| 83 | * proper HTTP error status code is enclosed in the exception. |
| 84 | * |
| 85 | * @param uri URI of the data resource to be deleted |
| 86 | * @throws RestconfException if the DELETE operation cannot be fulfilled |
| 87 | */ |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 88 | void runDeleteOperationOnDataResource(URI uri) throws RestconfException; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Processes a PATCH operation on a data resource. The target data |
| 92 | * resource is identified by its URI passed in by the caller. |
| 93 | * And the content of the data resource is passed in as a JSON ObjectNode. |
| 94 | * If the PATCH operation cannot be fulfilled due reasons such as |
| 95 | * the nonexistence of the target resource, a RestconfException |
| 96 | * exception is raised. The proper HTTP error status code is |
| 97 | * enclosed in the exception. |
| 98 | * |
| 99 | * @param uri URI of the data resource to be patched |
| 100 | * @param rootNode JSON representation of the data resource |
| 101 | * @throws RestconfException if the PATCH operation cannot be fulfilled |
| 102 | */ |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 103 | void runPatchOperationOnDataResource(URI uri, ObjectNode rootNode) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 104 | throws RestconfException; |
| 105 | |
| 106 | /** |
| 107 | * Retrieves the RESTCONF Root directory. |
| 108 | * |
| 109 | * @return the RESTCONF Root directory |
| 110 | */ |
| 111 | String getRestconfRootPath(); |
| 112 | |
| 113 | /** |
| 114 | * Handles an Event Stream subscription request. This function creates |
| 115 | * a worker thread to listen to events and writes to a ChunkedOutput, |
| 116 | * which is passed in from the caller. (The worker thread blocks if |
| 117 | * no events arrive.) The ChuckedOutput is a pipe to which this |
| 118 | * function acts as the writer and the caller the reader. |
| 119 | * <p> |
| 120 | * If the Event Stream cannot be subscribed due to reasons such as |
| 121 | * the nonexistence of the target stream or failure to allocate |
| 122 | * worker thread to handle the request, a RestconfException exception |
| 123 | * is raised. The proper HTTP error status code is enclosed in the |
| 124 | * exception, so that the caller may return it to the RESTCONF client |
| 125 | * to display. |
| 126 | * |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 127 | * @param streamId ID of the RESTCONF stream to subscribe |
| 128 | * @param clientIpAddr IP address of the RESTCONF client sending the request |
| 129 | * @param output A string data stream |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 130 | * @throws RestconfException if the Event Stream cannot be subscribed |
| 131 | */ |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 132 | void subscribeEventStream(String streamId, |
| 133 | String clientIpAddr, |
| 134 | ChunkedOutput<String> output) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 135 | throws RestconfException; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Handles a RESTCONF RPC request. This function executes the RPC in |
| 139 | * the target application's context and returns the results as a Future. |
| 140 | * |
| 141 | * @param uri URI corresponding to the Name of the RPC |
| 142 | * @param rpcInput Input parameters |
| 143 | * @param clientIpAddr IP address of the RESTCONF client calling the RPC |
| 144 | * @return RPC output |
| 145 | */ |
| 146 | CompletableFuture<RestconfRpcOutput> runRpc(URI uri, |
| 147 | ObjectNode rpcInput, |
| 148 | String clientIpAddr); |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 149 | } |