2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2022 Nordix Foundation
4 * Modifications Copyright (C) 2021 Pantheon.tech
5 * Modifications Copyright (C) 2021-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.api;
25 import java.time.OffsetDateTime;
26 import java.util.Collection;
27 import org.onap.cps.spi.FetchDescendantsOption;
28 import org.onap.cps.spi.model.DataNode;
31 * Datastore interface for handling CPS data.
33 public interface CpsDataService {
36 * Persists data for the given anchor and dataspace.
38 * @param dataspaceName dataspace name
39 * @param anchorName anchor name
40 * @param jsonData json data
41 * @param observedTimestamp observedTimestamp
43 void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp);
46 * Persists child data fragment under existing data node for the given anchor and dataspace.
48 * @param dataspaceName dataspace name
49 * @param anchorName anchor name
50 * @param parentNodeXpath parent node xpath
51 * @param jsonData json data
52 * @param observedTimestamp observedTimestamp
54 void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
55 OffsetDateTime observedTimestamp);
58 * Persists child data fragment representing one or more list elements under existing data node for the
59 * given anchor and dataspace.
61 * @param dataspaceName dataspace name
62 * @param anchorName anchor name
63 * @param parentNodeXpath parent node xpath
64 * @param jsonData json data representing list element(s)
65 * @param observedTimestamp observedTimestamp
67 void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
68 OffsetDateTime observedTimestamp);
71 * Retrieves datanode by XPath for given dataspace and anchor.
73 * @param dataspaceName dataspace name
74 * @param anchorName anchor name
76 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
77 * (recursively) as well
78 * @return data node object
80 DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
81 FetchDescendantsOption fetchDescendantsOption);
84 * Updates data node for given dataspace and anchor using xpath to parent node.
86 * @param dataspaceName dataspace name
87 * @param anchorName anchor name
88 * @param parentNodeXpath xpath to parent node
89 * @param jsonData json data
90 * @param observedTimestamp observedTimestamp
92 void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
93 OffsetDateTime observedTimestamp);
96 * Replaces existing data node content including descendants.
98 * @param dataspaceName dataspace name
99 * @param anchorName anchor name
100 * @param parentNodeXpath xpath to parent node
101 * @param jsonData json data
102 * @param observedTimestamp observedTimestamp
104 void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
105 OffsetDateTime observedTimestamp);
108 * Replaces list content by removing all existing elements and inserting the given new elements as json
109 * under given parent, anchor and dataspace.
111 * @param dataspaceName dataspace name
112 * @param anchorName anchor name
113 * @param parentNodeXpath parent node xpath
114 * @param jsonData json data representing the new list elements
115 * @param observedTimestamp observedTimestamp
117 void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
118 OffsetDateTime observedTimestamp);
121 * Replaces list content by removing all existing elements and inserting the given new elements as data nodes
122 * under given parent, anchor and dataspace.
124 * @param dataspaceName dataspace-name
125 * @param anchorName anchor name
126 * @param parentNodeXpath parent node xpath
127 * @param dataNodes datanodes representing the updated data
128 * @param observedTimestamp observedTimestamp
130 void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath,
131 Collection<DataNode> dataNodes, OffsetDateTime observedTimestamp);
134 * Deletes data node for given anchor and dataspace.
136 * @param dataspaceName dataspace name
137 * @param anchorName anchor name
138 * @param dataNodeXpath data node xpath
139 * @param observedTimestamp observed timestamp
141 void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
142 OffsetDateTime observedTimestamp);
145 * Deletes all data nodes for a given anchor in a dataspace.
147 * @param dataspaceName dataspace name
148 * @param anchorName anchor name
149 * @param observedTimestamp observed timestamp
151 void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
154 * Deletes a list or a list-element under given anchor and dataspace.
156 * @param dataspaceName dataspace name
157 * @param anchorName anchor name
158 * @param listElementXpath list element xpath
159 * @param observedTimestamp observedTimestamp
161 void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
162 OffsetDateTime observedTimestamp);
165 * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
166 * Node which already exists. This method will throw an exception if data node update or any descendant update does
169 * @param dataspaceName dataspace name
170 * @param anchorName anchor name
171 * @param parentNodeXpath xpath
172 * @param dataNodeUpdatesAsJson json data representing data node updates
173 * @param observedTimestamp observedTimestamp
175 void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
176 String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
179 * Starts a session which allows use of locks and batch interaction with the persistence service.
181 * @return Session ID string
183 String startSession();
188 * @param sessionId session ID
191 void closeSession(String sessionId);