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