Refactor ReadDataParams
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / RestconfServer.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.server.api;
9
10 import java.net.URI;
11 import java.util.Map;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.restconf.api.ApiPath;
15 import org.opendaylight.restconf.common.errors.RestconfFuture;
16 import org.opendaylight.restconf.common.patch.PatchStatusContext;
17 import org.opendaylight.restconf.nb.rfc8040.databind.ChildBody;
18 import org.opendaylight.restconf.nb.rfc8040.databind.DataPostBody;
19 import org.opendaylight.restconf.nb.rfc8040.databind.OperationInputBody;
20 import org.opendaylight.restconf.nb.rfc8040.databind.PatchBody;
21 import org.opendaylight.restconf.nb.rfc8040.databind.ResourceBody;
22 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
23 import org.opendaylight.restconf.server.api.DataPostResult.CreateResource;
24 import org.opendaylight.yangtools.yang.common.Empty;
25
26 /**
27  * An implementation of a RESTCONF server, implementing the
28  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.3">RESTCONF API Resource</a>.
29  */
30 // FIXME: configuration datastore should maintain ETag and Last-Modified headers, so that these can be returned when
31 //        GET/PATCH/POST/PUT modify the data.
32 // FIXME: NETCONF-773: as a first step in doing that we should carry those fields in our responses
33 @NonNullByDefault
34 public interface RestconfServer {
35     /**
36      * Delete a data resource.
37      *
38      * @param identifier resource identifier
39      * @return A {@link RestconfFuture} of the operation
40      */
41     @SuppressWarnings("checkstyle:abbreviationAsWordInName")
42     RestconfFuture<Empty> dataDELETE(ApiPath identifier);
43
44     /**
45      * Return the content of the datastore.
46      *
47      * @param params {@link DataGetParams} for this request
48      * @return A {@link RestconfFuture} of the {@link NormalizedNodePayload} content
49      */
50     RestconfFuture<NormalizedNodePayload> dataGET(DataGetParams params);
51
52     /**
53      * Return the content of a data resource.
54      *
55      * @param identifier resource identifier
56      * @param params {@link DataGetParams} for this request
57      * @return A {@link RestconfFuture} of the {@link NormalizedNodePayload} content
58      */
59     RestconfFuture<NormalizedNodePayload> dataGET(ApiPath identifier, DataGetParams params);
60
61     /**
62      * Partially modify the target data resource, as defined in
63      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.6.1">RFC8040, section 4.6.1</a>.
64      *
65      * @param body data node for put to config DS
66      * @return A {@link RestconfFuture} of the operation
67      */
68     RestconfFuture<Empty> dataPATCH(ResourceBody body);
69
70     /**
71      * Partially modify the target data resource, as defined in
72      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.6.1">RFC8040, section 4.6.1</a>.
73      *
74      * @param identifier resource identifier
75      * @param body data node for put to config DS
76      * @return A {@link RestconfFuture} of the operation
77      */
78     RestconfFuture<Empty> dataPATCH(ApiPath identifier, ResourceBody body);
79
80     /**
81      * Ordered list of edits that are applied to the datastore by the server, as defined in
82      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
83      *
84      * @param body YANG Patch body
85      * @return A {@link RestconfFuture} of the {@link PatchStatusContext} content
86      */
87     RestconfFuture<PatchStatusContext> dataPATCH(PatchBody body);
88
89     /**
90      * Ordered list of edits that are applied to the datastore by the server, as defined in
91      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
92      *
93      * @param identifier path to target
94      * @param body YANG Patch body
95      * @return A {@link RestconfFuture} of the {@link PatchStatusContext} content
96      */
97     RestconfFuture<PatchStatusContext> dataPATCH(ApiPath identifier, PatchBody body);
98
99     RestconfFuture<CreateResource> dataPOST(ChildBody body, Map<String, String> queryParameters);
100
101     RestconfFuture<? extends DataPostResult> dataPOST(ApiPath identifier, DataPostBody body,
102         Map<String, String> queryParameters);
103
104     /**
105      * Replace the data store.
106      *
107      * @param body data node for put to config DS
108      * @param queryParameters Query parameters
109      * @return A {@link RestconfFuture} completing with {@link DataPutResult}
110      */
111     RestconfFuture<DataPutResult> dataPUT(ResourceBody body, Map<String, String> queryParameters);
112
113     /**
114      * Create or replace a data store resource.
115      *
116      * @param identifier resource identifier
117      * @param body data node for put to config DS
118      * @param queryParameters Query parameters
119      * @return A {@link RestconfFuture} completing with {@link DataPutResult}
120      */
121     RestconfFuture<DataPutResult> dataPUT(ApiPath identifier, ResourceBody body, Map<String, String> queryParameters);
122
123     /**
124      * Return the set of supported RPCs supported by {@link #operationsPOST(URI, ApiPath, OperationInputBody)},
125      * as expressed in the <a href="https://www.rfc-editor.org/rfc/rfc8040#page-84">ietf-restconf.yang</a>
126      * {@code container operations} statement.
127      *
128      * @return A {@link RestconfFuture} completing with an {@link OperationsGetResult}
129      */
130     RestconfFuture<OperationsGetResult> operationsGET();
131
132     /*
133      * Return the details about a particular operation supported by
134      * {@link #operationsPOST(URI, String, OperationInputBody)}, as expressed in the
135      * <a href="https://www.rfc-editor.org/rfc/rfc8040#page-84">ietf-restconfig.yang</a>
136      * {@code container operations} statement.
137      *
138      * @param operation An operation
139      * @return A {@link RestconfFuture} completing with an {@link OperationsGetResult}
140      */
141     RestconfFuture<OperationsGetResult> operationsGET(ApiPath operation);
142
143     /**
144      * Invoke an RPC operation, as defined in
145      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.6">RFC8040 Operation Resource</a>.
146      *
147      * @param restconfURI Base URI of the request
148      * @param operation {@code <operation>} path, really an {@link ApiPath} to an {@code rpc}
149      * @param body RPC operation
150      * @return A {@link RestconfFuture} completing with {@link OperationsPostResult}
151      */
152     // FIXME: 'operation' should really be an ApiIdentifier with non-null module, but we also support ang-ext:mount,
153     //        and hence it is a path right now
154     RestconfFuture<OperationsPostResult> operationsPOST(URI restconfURI, ApiPath operation, OperationInputBody body);
155
156     /**
157      * Return the revision of {@code ietf-yang-library} module implemented by this server, as defined in
158      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.3.3">RFC8040 {+restconf}/yang-library-version</a>.
159      *
160      * @return A {@link RestconfFuture} completing with {@link NormalizedNodePayload} containing a single
161      *        {@code yang-library-version} leaf element.
162      */
163     // FIXME: this is a simple encoding-variadic return, similar to how OperationsContent is handled use a common
164     //        construct for both cases -- in this case it carries a yang.common.Revision
165     RestconfFuture<NormalizedNodePayload> yangLibraryVersionGET();
166
167     RestconfFuture<ModulesGetResult> modulesYangGET(String fileName, @Nullable String revision);
168
169     RestconfFuture<ModulesGetResult> modulesYangGET(ApiPath mountPath, String fileName, @Nullable String revision);
170
171     RestconfFuture<ModulesGetResult> modulesYinGET(String fileName, @Nullable String revision);
172
173     RestconfFuture<ModulesGetResult> modulesYinGET(ApiPath mountPath, String fileName, @Nullable String revision);
174 }