Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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.protocol.restconf.server.api; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.glassfish.jersey.server.ChunkedOutput; |
| 20 | |
| 21 | /** |
| 22 | * Abstraction of RESTCONF Server functionality according to the |
| 23 | * RESTCONF RFC (no official RFC number yet). |
| 24 | */ |
| 25 | public interface RestconfService { |
| 26 | /** |
| 27 | * Processes a GET request against a data resource. The |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 28 | * target data resource is identified by its URI. If the |
| 29 | * GET operation cannot be fulfilled due to reasons such |
| 30 | * as the nonexistence of the target resource, then a |
| 31 | * RestconfException exception is raised. The proper |
| 32 | * HTTP error status code is enclosed in the exception, so |
| 33 | * that the caller may return it to the RESTCONF client to |
| 34 | * display. |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 35 | * |
| 36 | * @param uri URI of the target data resource |
| 37 | * @return JSON representation of the data resource |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 38 | * @throws RestconfException if the GET operation cannot be fulfilled |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 39 | */ |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 40 | ObjectNode runGetOperationOnDataResource(String uri) |
| 41 | throws RestconfException; |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Processes a POST request against a data resource. The location of |
| 45 | * the target resource is passed in as a URI. And the resource's |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 46 | * content is passed in as a JSON ObjectNode. If the POST operation |
| 47 | * cannot be fulfilled due to reasons such as wrong input URIs or |
| 48 | * syntax errors in the JSON payloads, a RestconfException exception |
| 49 | * is raised. The proper HTTP error status code is enclosed in the |
| 50 | * exception. |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 51 | * |
| 52 | * @param uri URI of the data resource to be created |
| 53 | * @param rootNode JSON representation of the data resource |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 54 | * @throws RestconfException if the POST operation cannot be fulfilled |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 55 | */ |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 56 | void runPostOperationOnDataResource(String uri, ObjectNode rootNode) |
| 57 | throws RestconfException; |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Processes a PUT request against a data resource. The location of |
| 61 | * the target resource is passed in as a URI. And the resource's |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 62 | * content is passed in as a JSON ObjectNode. If the PUT operation |
| 63 | * cannot be fulfilled due to reasons such as wrong input URIs or |
| 64 | * syntax errors in the JSON payloads, a RestconfException exception |
| 65 | * is raised. The proper HTTP error status code is enclosed in the |
| 66 | * exception. |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 67 | * |
| 68 | * @param uri URI of the data resource to be created or updated |
| 69 | * @param rootNode JSON representation of the data resource |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 70 | * @throws RestconfException if the PUT operation cannot be fulfilled |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 71 | */ |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 72 | void runPutOperationOnDataResource(String uri, ObjectNode rootNode) |
| 73 | throws RestconfException; |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Processes the DELETE operation against a data resource. The target |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 77 | * data resource is identified by its URI. If the DELETE operation |
| 78 | * cannot be fulfilled due reasons such as the nonexistence of the |
| 79 | * target resource, a RestconfException exception is raised. The |
| 80 | * proper HTTP error status code is enclosed in the exception. |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 81 | * |
| 82 | * @param uri URI of the data resource to be deleted |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 83 | * @throws RestconfException if the DELETE operation cannot be fulfilled |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 84 | */ |
| 85 | void runDeleteOperationOnDataResource(String uri) throws RestconfException; |
| 86 | |
| 87 | /** |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 88 | * Processes a PATCH operation on a data resource. The target data |
| 89 | * resource is identified by its URI passed in by the caller. |
| 90 | * And the content of the data resource is passed in as a JSON ObjectNode. |
| 91 | * If the PATCH operation cannot be fulfilled due reasons such as |
| 92 | * the nonexistence of the target resource, a RestconfException |
| 93 | * exception is raised. The proper HTTP error status code is |
| 94 | * enclosed in the exception. |
| 95 | * |
| 96 | * @param uri URI of the data resource to be patched |
| 97 | * @param rootNode JSON representation of the data resource |
| 98 | * @throws RestconfException if the PATCH operation cannot be fulfilled |
| 99 | */ |
| 100 | void runPatchOperationOnDataResource(String uri, ObjectNode rootNode) |
| 101 | throws RestconfException; |
| 102 | |
| 103 | /** |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 104 | * Retrieves the RESTCONF Root directory. |
| 105 | * |
| 106 | * @return the RESTCONF Root directory |
| 107 | */ |
| 108 | String getRestconfRootPath(); |
| 109 | |
| 110 | /** |
| 111 | * Handles an Event Stream subscription request. This function creates |
| 112 | * a worker thread to listen to events and writes to a ChunkedOutput, |
| 113 | * which is passed in from the caller. (The worker thread blocks if |
| 114 | * no events arrive.) The ChuckedOutput is a pipe to which this |
| 115 | * function acts as the writer and the caller the reader. |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 116 | * <p> |
| 117 | * If the Event Stream cannot be subscribed due to reasons such as |
| 118 | * the nonexistence of the target stream or failure to allocate |
| 119 | * worker thread to handle the request, a RestconfException exception |
| 120 | * is raised. The proper HTTP error status code is enclosed in the |
| 121 | * exception, so that the caller may return it to the RESTCONF client |
| 122 | * to display. |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 123 | * |
| 124 | * @param streamId ID of the RESTCONF stream to subscribe |
| 125 | * @param output A string data stream |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 126 | * @throws RestconfException if the Event Stream cannot be subscribed |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 127 | */ |
chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 128 | void subscribeEventStream(String streamId, ChunkedOutput<String> output) |
| 129 | throws RestconfException; |
Henry Yu | e20926e | 2016-08-25 22:58:02 -0400 | [diff] [blame] | 130 | } |