blob: 9f3ba533e0a2cc299fc0bffbef10d12ac820bd90 [file] [log] [blame]
Jin Gan79f75372017-01-05 15:08:11 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jin Gan79f75372017-01-05 15:08:11 -08003 *
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 */
16package org.onosproject.restconf.api;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.glassfish.jersey.server.ChunkedOutput;
20
Henry Yuc10f7fc2017-07-26 13:42:08 -040021import java.net.URI;
22import java.util.concurrent.CompletableFuture;
23
Jin Gan79f75372017-01-05 15:08:11 -080024/**
25 * Abstraction of RESTCONF Server functionality according to the
26 * RESTCONF RFC (no official RFC number yet).
27 */
28public 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 Yuc10f7fc2017-07-26 13:42:08 -040043 ObjectNode runGetOperationOnDataResource(URI uri)
Jin Gan79f75372017-01-05 15:08:11 -080044 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 Yuc10f7fc2017-07-26 13:42:08 -040059 void runPostOperationOnDataResource(URI uri, ObjectNode rootNode)
Jin Gan79f75372017-01-05 15:08:11 -080060 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 Yuc10f7fc2017-07-26 13:42:08 -040075 void runPutOperationOnDataResource(URI uri, ObjectNode rootNode)
Jin Gan79f75372017-01-05 15:08:11 -080076 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 Yuc10f7fc2017-07-26 13:42:08 -040088 void runDeleteOperationOnDataResource(URI uri) throws RestconfException;
Jin Gan79f75372017-01-05 15:08:11 -080089
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 Yuc10f7fc2017-07-26 13:42:08 -0400103 void runPatchOperationOnDataResource(URI uri, ObjectNode rootNode)
Jin Gan79f75372017-01-05 15:08:11 -0800104 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 Yuc10f7fc2017-07-26 13:42:08 -0400127 * @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 Gan79f75372017-01-05 15:08:11 -0800130 * @throws RestconfException if the Event Stream cannot be subscribed
131 */
Henry Yuc10f7fc2017-07-26 13:42:08 -0400132 void subscribeEventStream(String streamId,
133 String clientIpAddr,
134 ChunkedOutput<String> output)
Jin Gan79f75372017-01-05 15:08:11 -0800135 throws RestconfException;
Henry Yuc10f7fc2017-07-26 13:42:08 -0400136
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 Gan79f75372017-01-05 15:08:11 -0800149}