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 |
| 28 | * target data resource is identified by its URI. |
| 29 | * |
| 30 | * @param uri URI of the target data resource |
| 31 | * @return JSON representation of the data resource |
| 32 | * @throws RestconfException if the GET operation cannot be fulfilled due |
| 33 | * reasons such as the nonexistence of the target |
| 34 | * resource. The proper HTTP error status code is |
| 35 | * enclosed in the exception, so that the caller |
| 36 | * may return it to the RESTCONF client |
| 37 | */ |
| 38 | ObjectNode runGetOperationOnDataResource(String uri) throws RestconfException; |
| 39 | |
| 40 | /** |
| 41 | * Processes a POST request against a data resource. The location of |
| 42 | * the target resource is passed in as a URI. And the resource's |
| 43 | * content is passed in as a JSON ObjectNode. |
| 44 | * |
| 45 | * @param uri URI of the data resource to be created |
| 46 | * @param rootNode JSON representation of the data resource |
| 47 | * @throws RestconfException if the POST operation cannot be fulfilled due |
| 48 | * reasons such as wrong URI or syntax error |
| 49 | * in JSON payload. The proper HTTP error status |
| 50 | * code is enclosed in the exception |
| 51 | */ |
| 52 | void runPostOperationOnDataResource(String uri, ObjectNode rootNode) throws RestconfException; |
| 53 | |
| 54 | /** |
| 55 | * Processes a PUT request against a data resource. The location of |
| 56 | * the target resource is passed in as a URI. And the resource's |
| 57 | * content is passed in as a JSON ObjectNode. |
| 58 | * |
| 59 | * @param uri URI of the data resource to be created or updated |
| 60 | * @param rootNode JSON representation of the data resource |
| 61 | * @throws RestconfException if the PUT operation cannot be fulfilled due |
| 62 | * reasons such as wrong URI or syntax error |
| 63 | * in JSON payload. The proper HTTP error status |
| 64 | * code is enclosed in the exception |
| 65 | */ |
| 66 | void runPutOperationOnDataResource(String uri, ObjectNode rootNode) throws RestconfException; |
| 67 | |
| 68 | /** |
| 69 | * Processes the DELETE operation against a data resource. The target |
| 70 | * data resource is identified by its URI. |
| 71 | * |
| 72 | * @param uri URI of the data resource to be deleted |
| 73 | * @throws RestconfException if the DELETE operation cannot be fulfilled due |
| 74 | * reasons such as the nonexistence of the target |
| 75 | * resource. The proper HTTP error status code is |
| 76 | * enclosed in the exception |
| 77 | */ |
| 78 | void runDeleteOperationOnDataResource(String uri) throws RestconfException; |
| 79 | |
| 80 | /** |
| 81 | * Retrieves the RESTCONF Root directory. |
| 82 | * |
| 83 | * @return the RESTCONF Root directory |
| 84 | */ |
| 85 | String getRestconfRootPath(); |
| 86 | |
| 87 | /** |
| 88 | * Handles an Event Stream subscription request. This function creates |
| 89 | * a worker thread to listen to events and writes to a ChunkedOutput, |
| 90 | * which is passed in from the caller. (The worker thread blocks if |
| 91 | * no events arrive.) The ChuckedOutput is a pipe to which this |
| 92 | * function acts as the writer and the caller the reader. |
| 93 | * |
| 94 | * @param streamId ID of the RESTCONF stream to subscribe |
| 95 | * @param output A string data stream |
| 96 | * @throws RestconfException if the Event Stream cannot be subscribed due to |
| 97 | * reasons such as the nonexistence of the target |
| 98 | * stream or unable to allocate any free worker |
| 99 | * thread to handle the request |
| 100 | */ |
| 101 | void subscribeEventStream(String streamId, ChunkedOutput<String> output) throws RestconfException; |
| 102 | } |