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