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