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;
28 import org.onap.cps.spi.FetchDescendantsOption;
29 import org.onap.cps.spi.model.DataNode;
32 * Datastore interface for handling CPS data.
34 public interface CpsDataService {
37 * Persists data for the given anchor and dataspace.
39 * @param dataspaceName dataspace name
40 * @param anchorName anchor name
41 * @param jsonData json data
42 * @param observedTimestamp observedTimestamp
44 void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp);
47 * Persists child data fragment under existing data node for the given anchor and dataspace.
49 * @param dataspaceName dataspace name
50 * @param anchorName anchor name
51 * @param parentNodeXpath parent node xpath
52 * @param jsonData json data
53 * @param observedTimestamp observedTimestamp
55 void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
56 OffsetDateTime observedTimestamp);
59 * Persists child data fragment representing one or more list elements under existing data node for the
60 * given anchor and dataspace.
62 * @param dataspaceName dataspace name
63 * @param anchorName anchor name
64 * @param parentNodeXpath parent node xpath
65 * @param jsonData json data representing list element(s)
66 * @param observedTimestamp observedTimestamp
68 void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
69 OffsetDateTime observedTimestamp);
72 * Retrieves datanode by XPath for given dataspace and anchor.
74 * @param dataspaceName dataspace name
75 * @param anchorName anchor name
77 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
78 * (recursively) as well
79 * @return data node object
81 DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
82 FetchDescendantsOption fetchDescendantsOption);
85 * Updates data node for given dataspace and anchor using xpath to parent node.
87 * @param dataspaceName dataspace name
88 * @param anchorName anchor name
89 * @param parentNodeXpath xpath to parent node
90 * @param jsonData json data
91 * @param observedTimestamp observedTimestamp
93 void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
94 OffsetDateTime observedTimestamp);
97 * Replaces an existing data node's content including descendants.
99 * @param dataspaceName dataspace name
100 * @param anchorName anchor name
101 * @param parentNodeXpath xpath to parent node
102 * @param jsonData json data
103 * @param observedTimestamp observedTimestamp
105 void updateDataNodeAndDescendants(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
106 OffsetDateTime observedTimestamp);
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 nodesJsonData map of xpath and node JSON data
114 * @param observedTimestamp observedTimestamp
116 void updateDataNodesAndDescendants(String dataspaceName, String anchorName, Map<String, String> nodesJsonData,
117 OffsetDateTime observedTimestamp);
120 * Replaces list content by removing all existing elements and inserting the given new elements as json
121 * under given parent, anchor and dataspace.
123 * @param dataspaceName dataspace name
124 * @param anchorName anchor name
125 * @param parentNodeXpath parent node xpath
126 * @param jsonData json data representing the new list elements
127 * @param observedTimestamp observedTimestamp
129 void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
130 OffsetDateTime observedTimestamp);
133 * Replaces list content by removing all existing elements and inserting the given new elements as data nodes
134 * under given parent, anchor and dataspace.
136 * @param dataspaceName dataspace-name
137 * @param anchorName anchor name
138 * @param parentNodeXpath parent node xpath
139 * @param dataNodes datanodes representing the updated data
140 * @param observedTimestamp observedTimestamp
142 void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath,
143 Collection<DataNode> dataNodes, OffsetDateTime observedTimestamp);
146 * Deletes data node for given anchor and dataspace.
148 * @param dataspaceName dataspace name
149 * @param anchorName anchor name
150 * @param dataNodeXpath data node xpath
151 * @param observedTimestamp observed timestamp
153 void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
154 OffsetDateTime observedTimestamp);
157 * Deletes all data nodes for a given anchor in a dataspace.
159 * @param dataspaceName dataspace name
160 * @param anchorName anchor name
161 * @param observedTimestamp observed timestamp
163 void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
166 * Deletes a list or a list-element under given anchor and dataspace.
168 * @param dataspaceName dataspace name
169 * @param anchorName anchor name
170 * @param listElementXpath list element xpath
171 * @param observedTimestamp observedTimestamp
173 void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
174 OffsetDateTime observedTimestamp);
177 * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
178 * Node which already exists. This method will throw an exception if data node update or any descendant update does
181 * @param dataspaceName dataspace name
182 * @param anchorName anchor name
183 * @param parentNodeXpath xpath
184 * @param dataNodeUpdatesAsJson json data representing data node updates
185 * @param observedTimestamp observedTimestamp
187 void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
188 String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
191 * Starts a session which allows use of locks and batch interaction with the persistence service.
193 * @return Session ID string
195 String startSession();
200 * @param sessionId session ID
203 void closeSession(String sessionId);
206 * Lock anchor with default timeout.
207 * To release locks(s), the session holding the lock(s) must be closed.
209 * @param sessionID session ID
210 * @param dataspaceName dataspace name
211 * @param anchorName anchor name
213 void lockAnchor(String sessionID, String dataspaceName, String anchorName);
216 * Lock anchor with custom timeout.
217 * To release locks(s), the session holding the lock(s) must be closed.
219 * @param sessionID session ID
220 * @param dataspaceName dataspace name
221 * @param anchorName anchor name
222 * @param timeoutInMilliseconds lock attempt timeout in milliseconds
224 void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);