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 {
40 * Store multiple datanodes at once.
41 * @param dataspaceName dataspace name
42 * @param anchorName anchor name
43 * @param dataNodes data nodes
45 void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
48 * Add a child to a Fragment.
50 * @param dataspaceName dataspace name
51 * @param anchorName anchor name
52 * @param parentXpath parent xpath
53 * @param dataNode dataNode
55 void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
58 * Add multiple children to a Fragment.
60 * @param dataspaceName dataspace name
61 * @param anchorName anchor name
62 * @param parentXpath parent xpath
63 * @param dataNodes collection of dataNodes
65 void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
68 * Adds list child elements to a Fragment.
70 * @param dataspaceName dataspace name
71 * @param anchorName anchor name
72 * @param parentNodeXpath parent node xpath
73 * @param listElementsCollection collection of data nodes representing list elements
75 void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
76 Collection<DataNode> listElementsCollection);
79 * Add multiple lists of data nodes to a parent node at the same time.
81 * @param dataspaceName dataspace name
82 * @param anchorName anchor name
83 * @param parentNodeXpath parent node xpath
84 * @param newLists collections of lists of data nodes representing list elements
86 void addMultipleLists(String dataspaceName, String anchorName, String parentNodeXpath,
87 Collection<Collection<DataNode>> newLists);
90 * Retrieves multiple datanodes for a single XPath for given dataspace and anchor.
91 * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node
92 * is returned when a specific xpath is used (Example: /bookstore).
94 * @param dataspaceName dataspace name
95 * @param anchorName anchor name
96 * @param xpath one xpath
97 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
98 * (recursively) as well
99 * @return collection of data node object
101 Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
102 FetchDescendantsOption fetchDescendantsOption);
105 * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
107 * @param dataspaceName dataspace name
108 * @param anchorName anchor name
109 * @param xpaths collection of xpaths
110 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
111 * (recursively) as well
112 * @return collection of data node object
114 Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
115 Collection<String> xpaths,
116 FetchDescendantsOption fetchDescendantsOption);
119 * Updates leaves for existing data node.
121 * @param dataspaceName dataspace name
122 * @param anchorName anchor name
124 * @param leaves the leaves as a map where key is a leaf name and a value is a leaf value
126 void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
129 * Replaces multiple existing data nodes' content including descendants in a batch operation.
131 * @param dataspaceName dataspace name
132 * @param anchorName anchor name
133 * @param dataNodes data nodes
135 void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final Collection<DataNode> dataNodes);
138 * Replaces list content by removing all existing elements and inserting the given new elements
139 * under given parent, anchor and dataspace.
141 * @param dataspaceName dataspace name
142 * @param anchorName anchor name
143 * @param parentNodeXpath parent node xpath
144 * @param newListElements collection of data nodes representing the new list content
146 void replaceListContent(String dataspaceName, String anchorName,
147 String parentNodeXpath, Collection<DataNode> newListElements);
150 * Deletes any dataNode, yang container or yang list or yang list element.
152 * @param dataspaceName dataspace name
153 * @param anchorName anchor name
154 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
156 void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
159 * Deletes multiple dataNode, yang container or yang list or yang list element.
161 * @param dataspaceName dataspace name
162 * @param anchorName anchor name
163 * @param targetXpaths xpaths of nodes to delete
165 void deleteDataNodes(String dataspaceName, String anchorName, Collection<String> targetXpaths);
168 * Deletes all dataNodes in a given anchor.
170 * @param dataspaceName dataspace name
171 * @param anchorName anchor name
173 void deleteDataNodes(String dataspaceName, String anchorName);
176 * Deletes all dataNodes in multiple anchors.
178 * @param dataspaceName dataspace name
179 * @param anchorNames anchor names
181 void deleteDataNodes(String dataspaceName, Collection<String> anchorNames);
184 * Deletes a single existing list element or the whole list.
186 * @param dataspaceName dataspace name
187 * @param anchorName anchor name
188 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
190 void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
193 * Get a datanode by cps path.
195 * @param dataspaceName dataspace name
196 * @param anchorName anchor name
197 * @param cpsPath cps path
198 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
199 * included in the output
200 * @return the data nodes found i.e. 0 or more data nodes
202 List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
203 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
206 * Get a datanode by dataspace name and cps path across all anchors.
208 * @param dataspaceName dataspace 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> queryDataNodesAcrossAnchors(String dataspaceName,
215 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
219 * Starts a session which allows use of locks and batch interaction with the persistence service.
221 * @return Session ID string
223 String startSession();
228 * @param sessionId session ID
230 void closeSession(String sessionId);
234 * To release locks(s), the session holding the lock(s) must be closed.
236 * @param sessionID session ID
237 * @param dataspaceName dataspace name
238 * @param anchorName anchor name
239 * @param timeoutInMilliseconds lock attempt timeout in milliseconds
241 void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);