Merge "Added depth parameter in query nodes API."
[cps.git] / cps-service / src / main / java / org / onap / cps / spi / CpsDataPersistenceService.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2022 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 Pantheon.tech
5  *  Modifications Copyright (C) 2022 Bell Canada
6  *  Modifications Copyright (C) 2022 TechMahindra Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * SPDX-License-Identifier: Apache-2.0
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.cps.spi;
25
26 import java.io.Serializable;
27 import java.util.Collection;
28 import java.util.List;
29 import java.util.Map;
30 import org.onap.cps.spi.model.DataNode;
31
32 /*
33     Data Store interface that is responsible for handling yang data.
34     Please follow guidelines in https://gerrit.nordix.org/#/c/onap/ccsdk/features/+/6698/19/cps/interface-proposal/src/main/java/cps/javadoc/spi/DataStoreService.java
35     when adding methods.
36  */
37 public interface CpsDataPersistenceService {
38
39
40     /**
41      * Store a datanode.
42      *
43      * @param dataspaceName dataspace name
44      * @param anchorName    anchor name
45      * @param dataNode      data node
46      * @deprecated Please use {@link #storeDataNodes(String, String, Collection)} as it supports multiple data nodes.
47      */
48     @Deprecated
49     void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
50
51     /**
52      * Store multiple datanodes at once.
53      * @param dataspaceName dataspace name
54      * @param anchorName    anchor name
55      * @param dataNodes     data nodes
56      */
57     void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
58
59     /**
60      * Add a child to a Fragment.
61      *
62      * @param dataspaceName dataspace name
63      * @param anchorName    anchor name
64      * @param parentXpath   parent xpath
65      * @param dataNode      dataNode
66      */
67     void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
68
69     /**
70      * Add multiple children to a Fragment.
71      *
72      * @param dataspaceName dataspace name
73      * @param anchorName    anchor name
74      * @param parentXpath   parent xpath
75      * @param dataNodes     collection of dataNodes
76      */
77     void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
78
79     /**
80      * Adds list child elements to a Fragment.
81      *
82      * @param dataspaceName          dataspace name
83      * @param anchorName             anchor name
84      * @param parentNodeXpath        parent node xpath
85      * @param listElementsCollection collection of data nodes representing list elements
86      */
87     void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
88         Collection<DataNode> listElementsCollection);
89
90     /**
91      * Add multiple lists of data nodes to a parent node at the same time.
92      *
93      * @param dataspaceName           dataspace name
94      * @param anchorName              anchor name
95      * @param parentNodeXpath         parent node xpath
96      * @param newLists collections of lists of data nodes representing list elements
97      */
98     void addMultipleLists(String dataspaceName, String anchorName, String parentNodeXpath,
99             Collection<Collection<DataNode>> newLists);
100
101     /**
102      * Retrieves datanode by XPath for given dataspace and anchor.
103      *
104      * @param dataspaceName          dataspace name
105      * @param anchorName             anchor name
106      * @param xpath                  xpath
107      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
108      *                               (recursively) as well
109      * @return data node object
110      */
111     DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
112         FetchDescendantsOption fetchDescendantsOption);
113
114     /**
115      * Retrieves datanode by XPath for given dataspace and anchor.
116      *
117      * @param dataspaceName          dataspace name
118      * @param anchorName             anchor name
119      * @param xpaths                 collection of xpaths
120      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
121      *                               (recursively) as well
122      * @return data node object
123      */
124     Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, Collection<String> xpaths,
125                          FetchDescendantsOption fetchDescendantsOption);
126
127     /**
128      * Updates leaves for existing data node.
129      *
130      * @param dataspaceName dataspace name
131      * @param anchorName    anchor name
132      * @param xpath         xpath
133      * @param leaves        the leaves as a map where key is a leaf name and a value is a leaf value
134      */
135     void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
136
137     /**
138      * Replaces an existing data node's content including descendants.
139      *
140      * @param dataspaceName dataspace name
141      * @param anchorName    anchor name
142      * @param dataNode      data node
143      */
144     void updateDataNodeAndDescendants(String dataspaceName, String anchorName, DataNode dataNode);
145
146     /**
147      * Replaces multiple existing data nodes' content including descendants in a batch operation.
148      *
149      * @param dataspaceName dataspace name
150      * @param anchorName    anchor name
151      * @param dataNodes     data nodes
152      */
153     void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final List<DataNode> dataNodes);
154
155     /**
156      * Replaces list content by removing all existing elements and inserting the given new elements
157      * under given parent, anchor and dataspace.
158      *
159      * @param dataspaceName   dataspace name
160      * @param anchorName      anchor name
161      * @param parentNodeXpath parent node xpath
162      * @param newListElements collection of data nodes representing the new list content
163      */
164     void replaceListContent(String dataspaceName, String anchorName,
165                             String parentNodeXpath, Collection<DataNode> newListElements);
166
167     /**
168      * Deletes any dataNode, yang container or yang list or yang list element.
169      *
170      * @param dataspaceName   dataspace name
171      * @param anchorName      anchor name
172      * @param targetXpath     xpath to list or list element (include [@key=value] to delete a single list element)
173      */
174     void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
175
176     /**
177      * Deletes all dataNodes in a given anchor.
178      *
179      * @param dataspaceName   dataspace name
180      * @param anchorName      anchor name
181      */
182     void deleteDataNodes(String dataspaceName, String anchorName);
183
184     /**
185      * Deletes existing a single list element or the whole list.
186      *
187      * @param dataspaceName   dataspace name
188      * @param anchorName      anchor name
189      * @param targetXpath     xpath to list or list element (include [@key=value] to delete a single list element)
190      */
191     void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
192
193     /**
194      * Get a datanode by cps path.
195      *
196      * @param dataspaceName          dataspace name
197      * @param anchorName             anchor name
198      * @param cpsPath                cps path
199      * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
200      *                               included in the output
201      * @return the data nodes found i.e. 0 or more data nodes
202      */
203     List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
204                                   String cpsPath, FetchDescendantsOption fetchDescendantsOption);
205
206     /**
207      * Starts a session which allows use of locks and batch interaction with the persistence service.
208      *
209      * @return Session ID string
210      */
211     String startSession();
212
213     /**
214      * Close session.
215      *
216      * @param sessionId session ID
217      */
218     void closeSession(String sessionId);
219
220     /**
221      * Lock anchor.
222      * To release locks(s), the session holding the lock(s) must be closed.
223      *
224      * @param sessionID session ID
225      * @param dataspaceName dataspace name
226      * @param anchorName anchor name
227      * @param timeoutInMilliseconds lock attempt timeout in milliseconds
228      */
229     void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);
230 }