2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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;
26 import java.util.List;
28 import org.onap.cps.spi.model.DataNode;
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
35 public interface CpsDataPersistenceService {
40 * @param dataspaceName dataspace name
41 * @param anchorName anchor name
42 * @param dataNode data node
44 void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
47 * Add a child to a Fragment.
49 * @param dataspaceName dataspace name
50 * @param anchorName anchor name
51 * @param parentXpath parent xpath
52 * @param dataNode dataNode
54 void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
57 * Adds list child elements to a Fragment.
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
65 void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
66 Collection<DataNode> listElementsCollection);
69 * Retrieves datanode by XPath for given dataspace and anchor.
71 * @param dataspaceName dataspace name
72 * @param anchorName anchor name
74 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
75 * (recursively) as well
76 * @return data node object
78 DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
79 FetchDescendantsOption fetchDescendantsOption);
83 * Updates leaves for existing data node.
85 * @param dataspaceName dataspace name
86 * @param anchorName anchor name
88 * @param leaves the leaves as a map where key is a leaf name and a value is a leaf value
90 void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves);
93 * Replaces existing data node content including descendants.
95 * @param dataspaceName dataspace name
96 * @param anchorName anchor name
97 * @param dataNode data node
99 void replaceDataNodeTree(String dataspaceName, String anchorName, DataNode dataNode);
102 * Replaces list content by removing all existing elements and inserting the given new elements
103 * under given parent, anchor and dataspace.
105 * @param dataspaceName dataspace name
106 * @param anchorName anchor name
107 * @param parentNodeXpath parent node xpath
108 * @param newListElements collection of data nodes representing the new list content
110 void replaceListContent(String dataspaceName, String anchorName,
111 String parentNodeXpath, Collection<DataNode> newListElements);
114 * Deletes any dataNode, yang container or yang list or yang list element.
116 * @param dataspaceName dataspace name
117 * @param anchorName anchor name
118 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
120 void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
123 * Deletes all dataNodes in a given anchor.
125 * @param dataspaceName dataspace name
126 * @param anchorName anchor name
128 void deleteDataNodes(String dataspaceName, String anchorName);
131 * Deletes existing a single list element or the whole list.
133 * @param dataspaceName dataspace name
134 * @param anchorName anchor name
135 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
137 void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
140 * Get a datanode by cps path.
142 * @param dataspaceName dataspace name
143 * @param anchorName anchor name
144 * @param cpsPath cps path
145 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
146 * included in the output
147 * @return the data nodes found i.e. 0 or more data nodes
149 List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
150 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
153 * Starts a session which allows use of locks and batch interaction with the persistence service.
155 * @return Session ID string
157 String startSession();
162 * @param sessionId session ID
164 void closeSession(String sessionId);