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