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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.cps.spi;
26 import java.io.Serializable;
27 import java.util.Collection;
28 import java.util.List;
30 import org.onap.cps.spi.model.DataNode;
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
37 public interface CpsDataPersistenceService {
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.
49 void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
52 * Store multiple datanodes at once.
53 * @param dataspaceName dataspace name
54 * @param anchorName anchor name
55 * @param dataNodes data nodes
57 void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
60 * Add a child to a Fragment.
62 * @param dataspaceName dataspace name
63 * @param anchorName anchor name
64 * @param parentXpath parent xpath
65 * @param dataNode dataNode
67 void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
70 * Add multiple children to a Fragment.
72 * @param dataspaceName dataspace name
73 * @param anchorName anchor name
74 * @param parentXpath parent xpath
75 * @param dataNodes collection of dataNodes
77 void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
80 * Adds list child elements to a Fragment.
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
87 void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
88 Collection<DataNode> listElementsCollection);
91 * Add multiple lists of data nodes to a parent node at the same time.
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
98 void addMultipleLists(String dataspaceName, String anchorName, String parentNodeXpath,
99 Collection<Collection<DataNode>> newLists);
102 * Retrieves multiple datanodes for a single XPath for given dataspace and anchor.
103 * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node
104 * is returned when a specific xpath is used (Example: /bookstore).
106 * @param dataspaceName dataspace name
107 * @param anchorName anchor name
108 * @param xpath one xpath
109 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
110 * (recursively) as well
111 * @return collection of data node object
113 Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
114 FetchDescendantsOption fetchDescendantsOption);
117 * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
119 * @param dataspaceName dataspace name
120 * @param anchorName anchor name
121 * @param xpaths collection of xpaths
122 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
123 * (recursively) as well
124 * @return collection of data node object
126 Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
127 Collection<String> xpaths,
128 FetchDescendantsOption fetchDescendantsOption);
131 * Updates leaves for existing data node.
133 * @param dataspaceName dataspace name
134 * @param anchorName anchor name
136 * @param leaves the leaves as a map where key is a leaf name and a value is a leaf value
138 void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
141 * Replaces multiple existing data nodes' content including descendants in a batch operation.
143 * @param dataspaceName dataspace name
144 * @param anchorName anchor name
145 * @param dataNodes data nodes
147 void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final Collection<DataNode> dataNodes);
150 * Replaces list content by removing all existing elements and inserting the given new elements
151 * under given parent, anchor and dataspace.
153 * @param dataspaceName dataspace name
154 * @param anchorName anchor name
155 * @param parentNodeXpath parent node xpath
156 * @param newListElements collection of data nodes representing the new list content
158 void replaceListContent(String dataspaceName, String anchorName,
159 String parentNodeXpath, Collection<DataNode> newListElements);
162 * Deletes any dataNode, yang container or yang list or yang list element.
164 * @param dataspaceName dataspace name
165 * @param anchorName anchor name
166 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
168 void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
171 * Deletes multiple dataNode, yang container or yang list or yang list element.
173 * @param dataspaceName dataspace name
174 * @param anchorName anchor name
175 * @param targetXpaths xpaths of nodes to delete
177 void deleteDataNodes(String dataspaceName, String anchorName, Collection<String> targetXpaths);
180 * Deletes all dataNodes in a given anchor.
182 * @param dataspaceName dataspace name
183 * @param anchorName anchor name
185 void deleteDataNodes(String dataspaceName, String anchorName);
188 * Deletes all dataNodes in multiple anchors.
190 * @param dataspaceName dataspace name
191 * @param anchorNames anchor names
193 void deleteDataNodes(String dataspaceName, Collection<String> anchorNames);
196 * Deletes a single existing list element or the whole list.
198 * @param dataspaceName dataspace name
199 * @param anchorName anchor name
200 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
202 void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
205 * Get a datanode by cps path.
207 * @param dataspaceName dataspace name
208 * @param anchorName anchor name
209 * @param cpsPath cps path
210 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
211 * included in the output
212 * @return the data nodes found i.e. 0 or more data nodes
214 List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
215 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
218 * Get a datanode by dataspace name and cps path across all anchors.
220 * @param dataspaceName dataspace name
221 * @param cpsPath cps path
222 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
223 * included in the output
224 * @return the data nodes found i.e. 0 or more data nodes
226 List<DataNode> queryDataNodesAcrossAnchors(String dataspaceName,
227 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
231 * Starts a session which allows use of locks and batch interaction with the persistence service.
233 * @return Session ID string
235 String startSession();
240 * @param sessionId session ID
242 void closeSession(String sessionId);
246 * To release locks(s), the session holding the lock(s) must be closed.
248 * @param sessionID session ID
249 * @param dataspaceName dataspace name
250 * @param anchorName anchor name
251 * @param timeoutInMilliseconds lock attempt timeout in milliseconds
253 void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);