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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.cps.spi;
25 import java.util.Collection;
27 import org.onap.cps.spi.model.DataNode;
30 Data Store interface that is responsible for handling yang data.
31 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
34 public interface CpsDataPersistenceService {
39 * @param dataspaceName dataspace name
40 * @param anchorName anchor name
41 * @param dataNode data node
43 void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
46 * Add a child to a Fragment.
48 * @param dataspaceName dataspace name
49 * @param anchorName anchor name
50 * @param parentXpath parent xpath
51 * @param dataNode dataNode
53 void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
56 * Adds list child elements to a Fragment.
58 * @param dataspaceName dataspace name
59 * @param anchorName anchor name
60 * @param parentNodeXpath parent node xpath
61 * @param listElementsCollection collection of data nodes representing list elements
64 void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
65 Collection<DataNode> listElementsCollection);
68 * Retrieves datanode by XPath for given dataspace and anchor.
70 * @param dataspaceName dataspace name
71 * @param anchorName anchor name
73 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
74 * (recursively) as well
75 * @return data node object
77 DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
78 FetchDescendantsOption fetchDescendantsOption);
82 * Updates leaves for existing data node.
84 * @param dataspaceName dataspace name
85 * @param anchorName anchor name
87 * @param leaves the leaves as a map where key is a leaf name and a value is a leaf value
89 void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves);
92 * Replaces existing data node content including descendants.
94 * @param dataspaceName dataspace name
95 * @param anchorName anchor name
96 * @param dataNode data node
98 void replaceDataNodeTree(String dataspaceName, String anchorName, DataNode dataNode);
101 * Replaces list content by removing all existing elements and inserting the given new elements
102 * under given parent, anchor and dataspace.
104 * @param dataspaceName dataspace name
105 * @param anchorName anchor name
106 * @param parentNodeXpath parent node xpath
107 * @param newListElements collection of data nodes representing the new list content
109 void replaceListContent(String dataspaceName, String anchorName,
110 String parentNodeXpath, Collection<DataNode> newListElements);
113 * Deletes any dataNode, yang container or yang list or yang list element.
115 * @param dataspaceName dataspace name
116 * @param anchorName anchor name
117 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
119 void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
122 * Deletes all dataNodes in a given anchor.
124 * @param dataspaceName dataspace name
125 * @param anchorName anchor name
127 void deleteDataNodes(String dataspaceName, String anchorName);
130 * Deletes existing a single list element or the whole list.
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 deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
139 * Get a datanode by cps path.
141 * @param dataspaceName dataspace name
142 * @param anchorName anchor name
143 * @param cpsPath cps path
144 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
145 * included in the output
146 * @return the data nodes found i.e. 0 or more data nodes
148 Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName,
149 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
152 * Starts a session which allows use of locks and batch interaction with the persistence service.
154 * @return Session ID string
156 String startSession();
161 * @param sessionId session ID
163 void closeSession(String sessionId);
167 * To release locks(s), the session holding the lock(s) must be closed.
169 * @param sessionID session ID
170 * @param dataspaceName dataspace name
171 * @param anchorName anchor name
172 * @param timeoutInMilliseconds lock attempt timeout in milliseconds
174 void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);