RestconfServer is strictly asynchronous
[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.opendaylight.restconf.api.ApiPath;
14 import org.opendaylight.restconf.common.errors.RestconfFuture;
15 import org.opendaylight.restconf.common.patch.PatchStatusContext;
16 import org.opendaylight.restconf.nb.rfc8040.ReadDataParams;
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.restconf.server.spi.OperationOutput;
25 import org.opendaylight.yangtools.yang.common.Empty;
26
27 /**
28  * An implementation of a RESTCONF server, implementing the
29  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.3">RESTCONF API Resource</a>.
30  */
31 @NonNullByDefault
32 public interface RestconfServer {
33     /**
34      * Delete a data resource.
35      *
36      * @param identifier resource identifier
37      * @return A {@link RestconfFuture} of the operation
38      */
39     @SuppressWarnings("checkstyle:abbreviationAsWordInName")
40     RestconfFuture<Empty> dataDELETE(String identifier);
41
42     /**
43      * Return the content of the datastore.
44      *
45      * @param readParams {@link ReadDataParams} for this request
46      * @return A {@link RestconfFuture} of the {@link NormalizedNodePayload} content
47      */
48     RestconfFuture<NormalizedNodePayload> dataGET(ReadDataParams readParams);
49
50     /**
51      * Return the content of a data resource.
52      *
53      * @param identifier resource identifier
54      * @param readParams {@link ReadDataParams} for this request
55      * @return A {@link RestconfFuture} of the {@link NormalizedNodePayload} content
56      */
57     RestconfFuture<NormalizedNodePayload> dataGET(String identifier, ReadDataParams readParams);
58
59     /**
60      * Partially modify the target data resource, as defined in
61      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.6.1">RFC8040, section 4.6.1</a>.
62      *
63      * @param body data node for put to config DS
64      * @return A {@link RestconfFuture} of the operation
65      */
66     RestconfFuture<Empty> dataPATCH(ResourceBody body);
67
68     /**
69      * Partially modify the target data resource, as defined in
70      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.6.1">RFC8040, section 4.6.1</a>.
71      *
72      * @param identifier resource identifier
73      * @param body data node for put to config DS
74      * @return A {@link RestconfFuture} of the operation
75      */
76     RestconfFuture<Empty> dataPATCH(String identifier, ResourceBody body);
77
78     /**
79      * Ordered list of edits that are applied to the datastore by the server, as defined in
80      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
81      *
82      * @param body YANG Patch body
83      * @return A {@link RestconfFuture} of the {@link PatchStatusContext} content
84      */
85     RestconfFuture<PatchStatusContext> dataPATCH(PatchBody body);
86
87     /**
88      * Ordered list of edits that are applied to the datastore by the server, as defined in
89      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
90      *
91      * @param identifier path to target
92      * @param body YANG Patch body
93      * @return A {@link RestconfFuture} of the {@link PatchStatusContext} content
94      */
95     RestconfFuture<PatchStatusContext> dataPATCH(String identifier, PatchBody body);
96
97     RestconfFuture<CreateResource> dataPOST(ChildBody body, Map<String, String> queryParameters);
98
99     RestconfFuture<? extends DataPostResult> dataPOST(String identifier, DataPostBody body,
100         Map<String, String> queryParameters);
101
102     /**
103      * Replace the data store.
104      *
105      * @param body data node for put to config DS
106      * @param queryParameters Query parameters
107      * @return A {@link RestconfFuture} completing with {@link DataPutResult}
108      */
109     RestconfFuture<DataPutResult> dataPUT(ResourceBody body, Map<String, String> queryParameters);
110
111     /**
112      * Create or replace a data store resource.
113      *
114      * @param identifier resource identifier
115      * @param body data node for put to config DS
116      * @param queryParameters Query parameters
117      * @return A {@link RestconfFuture} completing with {@link DataPutResult}
118      */
119     RestconfFuture<DataPutResult> dataPUT(String identifier, ResourceBody body, Map<String, String> queryParameters);
120
121     /**
122      * Return the set of supported RPCs supported by {@link #operationsPOST(URI, String, OperationInputBody)},
123      * as expressed in the <a href="https://www.rfc-editor.org/rfc/rfc8040#page-84">ietf-restconf.yang</a>
124      * {@code container operations} statement.
125      *
126      * @return A {@link RestconfFuture} completing with an {@link OperationsGetResult}
127      */
128     RestconfFuture<OperationsGetResult> operationsGET();
129
130     /*
131      * Return the details about a particular operation supported by
132      * {@link #operationsPOST(URI, String, OperationInputBody)}, as expressed in the
133      * <a href="https://www.rfc-editor.org/rfc/rfc8040#page-84">ietf-restconfig.yang</a>
134      * {@code container operations} statement.
135      *
136      * @param operation An operation
137      * @return A {@link RestconfFuture} completing with an {@link OperationsGetResult}
138      */
139     RestconfFuture<OperationsGetResult> operationsGET(String operation);
140
141     /**
142      * Invoke an RPC operation, as defined in
143      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.6">RFC8040 Operation Resource</a>.
144      *
145      * @param restconfURI Base URI of the request
146      * @param operation {@code <operation>} path, really an {@link ApiPath} to an {@code rpc}
147      * @param body RPC operation
148      * @return A {@link RestconfFuture} completing with {@link OperationOutput}
149      */
150     // FIXME: 'operation' should really be an ApiIdentifier with non-null module, but we also support ang-ext:mount,
151     //        and hence it is a path right now
152     // FIXME: use ApiPath instead of String
153     RestconfFuture<OperationOutput> operationsPOST(URI restconfURI, String operation, OperationInputBody body);
154
155     /**
156      * Return the revision of {@code ietf-yang-library} module implemented by this server, as defined in
157      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.3.3">RFC8040 {+restconf}/yang-library-version</a>.
158      *
159      * @return A {@link RestconfFuture} completing with {@link NormalizedNodePayload} containing a single
160      *        {@code yang-library-version} leaf element.
161      */
162     // FIXME: this is a simple encoding-variadic return, similar to how OperationsContent is handled use a common
163     //        construct for both cases -- in this case it carries a yang.common.Revision
164     RestconfFuture<NormalizedNodePayload> yangLibraryVersionGET();
165 }