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
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);
49 * Add multiple children to a Fragment.
51 * @param dataspaceName dataspace name
52 * @param anchorName anchor name
53 * @param parentXpath parent xpath
54 * @param dataNodes collection of dataNodes
56 void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
59 * Adds list child elements to a Fragment.
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
66 void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
67 Collection<DataNode> listElementsCollection);
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).
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
81 Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
82 FetchDescendantsOption fetchDescendantsOption);
85 * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
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
94 Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
95 Collection<String> xpaths,
96 FetchDescendantsOption fetchDescendantsOption);
99 * Updates data leaves for multiple data nodes.
101 * @param dataspaceName dataspace name
102 * @param anchorName anchor name
103 * @param updatedLeavesPerXPath Map of xPaths to updated leaf nodes
105 void batchUpdateDataLeaves(String dataspaceName, String anchorName,
106 Map<String, Map<String, Serializable>> updatedLeavesPerXPath);
109 * Replaces multiple existing data nodes' content including descendants in a batch operation.
111 * @param dataspaceName dataspace name
112 * @param anchorName anchor name
113 * @param dataNodes data nodes
115 void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final Collection<DataNode> dataNodes);
118 * Replaces list content by removing all existing elements and inserting the given new elements
119 * under given parent, anchor and dataspace.
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
126 void replaceListContent(String dataspaceName, String anchorName,
127 String parentNodeXpath, Collection<DataNode> newListElements);
130 * Deletes any dataNode, yang container or yang list or yang list element.
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)
136 void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
139 * Deletes multiple dataNode, yang container or yang list or yang list element.
141 * @param dataspaceName dataspace name
142 * @param anchorName anchor name
143 * @param targetXpaths xpaths of nodes to delete
145 void deleteDataNodes(String dataspaceName, String anchorName, Collection<String> targetXpaths);
148 * Deletes all dataNodes in a given anchor.
150 * @param dataspaceName dataspace name
151 * @param anchorName anchor name
153 void deleteDataNodes(String dataspaceName, String anchorName);
156 * Deletes all dataNodes in multiple anchors.
158 * @param dataspaceName dataspace name
159 * @param anchorNames anchor names
161 void deleteDataNodes(String dataspaceName, Collection<String> anchorNames);
164 * Deletes a single existing list element or the whole list.
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)
170 void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
173 * Get a datanode by cps path.
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
182 List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
183 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
186 * Get a datanode by dataspace name and cps path across all anchors.
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
195 List<DataNode> queryDataNodesAcrossAnchors(String dataspaceName,
196 String cpsPath, FetchDescendantsOption fetchDescendantsOption,
197 PaginationOption paginationOption);
200 * Starts a session which allows use of locks and batch interaction with the persistence service.
202 * @return Session ID string
204 String startSession();
209 * @param sessionId session ID
211 void closeSession(String sessionId);
215 * To release locks(s), the session holding the lock(s) must be closed.
217 * @param sessionID session ID
218 * @param dataspaceName dataspace name
219 * @param anchorName anchor name
220 * @param timeoutInMilliseconds lock attempt timeout in milliseconds
222 void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);
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
230 Integer countAnchorsForDataspaceAndCpsPath(String dataspaceName, String cpsPath);