Move integration test (DataService)
[cps.git] / cps-service / src / main / java / org / onap / cps / spi / CpsDataPersistenceService.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2023 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 Pantheon.tech
5  *  Modifications Copyright (C) 2022 Bell Canada
6  *  Modifications Copyright (C) 2022-2023 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      * Store multiple datanodes at once.
41      * @param dataspaceName dataspace name
42      * @param anchorName    anchor name
43      * @param dataNodes     data nodes
44      */
45     void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
46
47
48     /**
49      * Add multiple children to a Fragment.
50      *
51      * @param dataspaceName dataspace name
52      * @param anchorName    anchor name
53      * @param parentXpath   parent xpath
54      * @param dataNodes     collection of dataNodes
55      */
56     void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
57
58     /**
59      * Adds list child elements to a Fragment.
60      *
61      * @param dataspaceName          dataspace name
62      * @param anchorName             anchor name
63      * @param parentNodeXpath        parent node xpath
64      * @param listElementsCollection collection of data nodes representing list elements
65      */
66     void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
67         Collection<DataNode> listElementsCollection);
68
69     /**
70      * Add multiple lists of data nodes to a parent node at the same time.
71      *
72      * @param dataspaceName           dataspace name
73      * @param anchorName              anchor name
74      * @param parentNodeXpath         parent node xpath
75      * @param newLists collections of lists of data nodes representing list elements
76      */
77     void addMultipleLists(String dataspaceName, String anchorName, String parentNodeXpath,
78             Collection<Collection<DataNode>> newLists);
79
80     /**
81      * Retrieves multiple datanodes for a single XPath for given dataspace and anchor.
82      * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node
83      * is returned when a specific xpath is used (Example: /bookstore).
84      *
85      * @param dataspaceName          dataspace name
86      * @param anchorName             anchor name
87      * @param xpath                  one xpath
88      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
89      *                               (recursively) as well
90      * @return collection of data node object
91      */
92     Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
93                                       FetchDescendantsOption fetchDescendantsOption);
94
95     /**
96      * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
97      *
98      * @param dataspaceName           dataspace name
99      * @param anchorName              anchor name
100      * @param xpaths                  collection of xpaths
101      * @param fetchDescendantsOption  defines the scope of data to fetch: either single node or all the descendant nodes
102      *                                (recursively) as well
103      * @return collection of data node object
104      */
105     Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
106                                                        Collection<String> xpaths,
107                                                        FetchDescendantsOption fetchDescendantsOption);
108
109     /**
110      * Updates data leaves for multiple data nodes.
111      *
112      * @param dataspaceName              dataspace name
113      * @param anchorName                 anchor name
114      * @param updatedLeavesPerXPath      Map of xPaths to updated leaf nodes
115      */
116     void batchUpdateDataLeaves(String dataspaceName, String anchorName,
117                                Map<String, Map<String, Serializable>> updatedLeavesPerXPath);
118
119     /**
120      * Replaces multiple existing data nodes' content including descendants in a batch operation.
121      *
122      * @param dataspaceName dataspace name
123      * @param anchorName    anchor name
124      * @param dataNodes     data nodes
125      */
126     void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final Collection<DataNode> dataNodes);
127
128     /**
129      * Replaces list content by removing all existing elements and inserting the given new elements
130      * under given parent, anchor and dataspace.
131      *
132      * @param dataspaceName   dataspace name
133      * @param anchorName      anchor name
134      * @param parentNodeXpath parent node xpath
135      * @param newListElements collection of data nodes representing the new list content
136      */
137     void replaceListContent(String dataspaceName, String anchorName,
138                             String parentNodeXpath, Collection<DataNode> newListElements);
139
140     /**
141      * Deletes any dataNode, yang container or yang list or yang list element.
142      *
143      * @param dataspaceName   dataspace name
144      * @param anchorName      anchor name
145      * @param targetXpath     xpath to list or list element (include [@key=value] to delete a single list element)
146      */
147     void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
148
149     /**
150      * Deletes multiple dataNode, yang container or yang list or yang list element.
151      *
152      * @param dataspaceName   dataspace name
153      * @param anchorName      anchor name
154      * @param targetXpaths    xpaths of nodes to delete
155      */
156     void deleteDataNodes(String dataspaceName, String anchorName, Collection<String> targetXpaths);
157
158     /**
159      * Deletes all dataNodes in a given anchor.
160      *
161      * @param dataspaceName   dataspace name
162      * @param anchorName      anchor name
163      */
164     void deleteDataNodes(String dataspaceName, String anchorName);
165
166     /**
167      * Deletes all dataNodes in multiple anchors.
168      *
169      * @param dataspaceName   dataspace name
170      * @param anchorNames     anchor names
171      */
172     void deleteDataNodes(String dataspaceName, Collection<String> anchorNames);
173
174     /**
175      * Deletes a single existing list element or the whole list.
176      *
177      * @param dataspaceName   dataspace name
178      * @param anchorName      anchor name
179      * @param targetXpath     xpath to list or list element (include [@key=value] to delete a single list element)
180      */
181     void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
182
183     /**
184      * Get a datanode by cps path.
185      *
186      * @param dataspaceName          dataspace name
187      * @param anchorName             anchor name
188      * @param cpsPath                cps path
189      * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
190      *                               included in the output
191      * @return the data nodes found i.e. 0 or more data nodes
192      */
193     List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
194                                   String cpsPath, FetchDescendantsOption fetchDescendantsOption);
195
196     /**
197      * Get a datanode by dataspace name and cps path across all anchors.
198      *
199      * @param dataspaceName          dataspace name
200      * @param cpsPath                cps path
201      * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
202      *                               included in the output
203      * @return the data nodes found i.e. 0 or more data nodes
204      */
205     List<DataNode> queryDataNodesAcrossAnchors(String dataspaceName,
206                                   String cpsPath, FetchDescendantsOption fetchDescendantsOption);
207
208
209     /**
210      * Starts a session which allows use of locks and batch interaction with the persistence service.
211      *
212      * @return Session ID string
213      */
214     String startSession();
215
216     /**
217      * Close session.
218      *
219      * @param sessionId session ID
220      */
221     void closeSession(String sessionId);
222
223     /**
224      * Lock anchor.
225      * To release locks(s), the session holding the lock(s) must be closed.
226      *
227      * @param sessionID session ID
228      * @param dataspaceName dataspace name
229      * @param anchorName anchor name
230      * @param timeoutInMilliseconds lock attempt timeout in milliseconds
231      */
232     void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);
233 }