blob: 053356b0709507e0db2c108aebb1473c607cf391 [file] [log] [blame]
Henry Yue20926e2016-08-25 22:58:02 -04001/*
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 */
16package org.onosproject.protocol.restconf.server.api;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import 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 */
25public interface RestconfService {
26 /**
27 * Processes a GET request against a data resource. The
chengfanc58d4be2016-09-20 10:33:12 +080028 * 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 Yue20926e2016-08-25 22:58:02 -040035 *
36 * @param uri URI of the target data resource
37 * @return JSON representation of the data resource
chengfanc58d4be2016-09-20 10:33:12 +080038 * @throws RestconfException if the GET operation cannot be fulfilled
Henry Yue20926e2016-08-25 22:58:02 -040039 */
chengfanc58d4be2016-09-20 10:33:12 +080040 ObjectNode runGetOperationOnDataResource(String uri)
41 throws RestconfException;
Henry Yue20926e2016-08-25 22:58:02 -040042
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
chengfanc58d4be2016-09-20 10:33:12 +080046 * 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 Yue20926e2016-08-25 22:58:02 -040051 *
52 * @param uri URI of the data resource to be created
53 * @param rootNode JSON representation of the data resource
chengfanc58d4be2016-09-20 10:33:12 +080054 * @throws RestconfException if the POST operation cannot be fulfilled
Henry Yue20926e2016-08-25 22:58:02 -040055 */
chengfanc58d4be2016-09-20 10:33:12 +080056 void runPostOperationOnDataResource(String uri, ObjectNode rootNode)
57 throws RestconfException;
Henry Yue20926e2016-08-25 22:58:02 -040058
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
chengfanc58d4be2016-09-20 10:33:12 +080062 * 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 Yue20926e2016-08-25 22:58:02 -040067 *
68 * @param uri URI of the data resource to be created or updated
69 * @param rootNode JSON representation of the data resource
chengfanc58d4be2016-09-20 10:33:12 +080070 * @throws RestconfException if the PUT operation cannot be fulfilled
Henry Yue20926e2016-08-25 22:58:02 -040071 */
chengfanc58d4be2016-09-20 10:33:12 +080072 void runPutOperationOnDataResource(String uri, ObjectNode rootNode)
73 throws RestconfException;
Henry Yue20926e2016-08-25 22:58:02 -040074
75 /**
76 * Processes the DELETE operation against a data resource. The target
chengfanc58d4be2016-09-20 10:33:12 +080077 * 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 Yue20926e2016-08-25 22:58:02 -040081 *
82 * @param uri URI of the data resource to be deleted
chengfanc58d4be2016-09-20 10:33:12 +080083 * @throws RestconfException if the DELETE operation cannot be fulfilled
Henry Yue20926e2016-08-25 22:58:02 -040084 */
85 void runDeleteOperationOnDataResource(String uri) throws RestconfException;
86
87 /**
chengfanc58d4be2016-09-20 10:33:12 +080088 * 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 Yue20926e2016-08-25 22:58:02 -0400104 * 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.
chengfanc58d4be2016-09-20 10:33:12 +0800116 * <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 Yue20926e2016-08-25 22:58:02 -0400123 *
124 * @param streamId ID of the RESTCONF stream to subscribe
125 * @param output A string data stream
chengfanc58d4be2016-09-20 10:33:12 +0800126 * @throws RestconfException if the Event Stream cannot be subscribed
Henry Yue20926e2016-08-25 22:58:02 -0400127 */
chengfanc58d4be2016-09-20 10:33:12 +0800128 void subscribeEventStream(String streamId, ChunkedOutput<String> output)
129 throws RestconfException;
Henry Yue20926e2016-08-25 22:58:02 -0400130}