Performance Improvement: Batch Update DataNodes
[cps.git] / cps-service / src / main / java / org / onap / cps / api / CpsDataService.java
1 /*
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
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *  SPDX-License-Identifier: Apache-2.0
20  *  ============LICENSE_END=========================================================
21  */
22
23 package org.onap.cps.api;
24
25 import java.time.OffsetDateTime;
26 import java.util.Collection;
27 import java.util.Map;
28 import org.onap.cps.spi.FetchDescendantsOption;
29 import org.onap.cps.spi.model.DataNode;
30
31 /*
32  * Datastore interface for handling CPS data.
33  */
34 public interface CpsDataService {
35
36     /**
37      * Persists data for the given anchor and dataspace.
38      *
39      * @param dataspaceName dataspace name
40      * @param anchorName    anchor name
41      * @param jsonData      json data
42      * @param observedTimestamp observedTimestamp
43      */
44     void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp);
45
46     /**
47      * Persists child data fragment under existing data node for the given anchor and dataspace.
48      *
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
54      */
55     void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
56         OffsetDateTime observedTimestamp);
57
58     /**
59      * Persists child data fragment representing one or more list elements under existing data node for the
60      * given anchor and dataspace.
61      *
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
67      */
68     void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
69         OffsetDateTime observedTimestamp);
70
71     /**
72      * Retrieves datanode by XPath for given dataspace and anchor.
73      *
74      * @param dataspaceName          dataspace name
75      * @param anchorName             anchor name
76      * @param xpath                  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 data node object
80      */
81     DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
82         FetchDescendantsOption fetchDescendantsOption);
83
84     /**
85      * Updates data node for given dataspace and anchor using xpath to parent node.
86      *
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
92      */
93     void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
94         OffsetDateTime observedTimestamp);
95
96     /**
97      * Replaces an existing data node's content including descendants.
98      *
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
104      */
105     void updateDataNodeAndDescendants(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
106                                        OffsetDateTime observedTimestamp);
107
108     /**
109      * Replaces multiple existing data nodes' content including descendants in a batch operation.
110      *
111      * @param dataspaceName   dataspace name
112      * @param anchorName      anchor name
113      * @param nodesJsonData   map of xpath and node JSON data
114      * @param observedTimestamp observedTimestamp
115      */
116     void updateDataNodesAndDescendants(String dataspaceName, String anchorName, Map<String, String> nodesJsonData,
117                                        OffsetDateTime observedTimestamp);
118
119     /**
120      * Replaces list content by removing all existing elements and inserting the given new elements as json
121      * under given parent, anchor and dataspace.
122      *
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
128      */
129     void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
130         OffsetDateTime observedTimestamp);
131
132     /**
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.
135      *
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
141      */
142     void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath,
143             Collection<DataNode> dataNodes, OffsetDateTime observedTimestamp);
144
145     /**
146      * Deletes data node for given anchor and dataspace.
147      *
148      * @param dataspaceName dataspace name
149      * @param anchorName anchor name
150      * @param dataNodeXpath data node xpath
151      * @param observedTimestamp observed timestamp
152      */
153     void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
154         OffsetDateTime observedTimestamp);
155
156     /**
157      * Deletes all data nodes for a given anchor in a dataspace.
158      *
159      * @param dataspaceName     dataspace name
160      * @param anchorName       anchor name
161      * @param observedTimestamp observed timestamp
162      */
163     void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
164
165     /**
166      * Deletes a list or a list-element under given anchor and dataspace.
167      *
168      * @param dataspaceName dataspace name
169      * @param anchorName    anchor name
170      * @param listElementXpath list element xpath
171      * @param observedTimestamp observedTimestamp
172      */
173     void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
174         OffsetDateTime observedTimestamp);
175
176     /**
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
179      * not exist.
180      *
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
186      */
187     void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
188         String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
189
190     /**
191      * Starts a session which allows use of locks and batch interaction with the persistence service.
192      *
193      * @return Session ID string
194      */
195     String startSession();
196
197     /**
198      * Close session.
199      *
200      * @param sessionId session ID
201      *
202      */
203     void closeSession(String sessionId);
204
205     /**
206      * Lock anchor with default timeout.
207      * To release locks(s), the session holding the lock(s) must be closed.
208      *
209      * @param sessionID session ID
210      * @param dataspaceName dataspace name
211      * @param anchorName anchor name
212      */
213     void lockAnchor(String sessionID, String dataspaceName, String anchorName);
214
215     /**
216      * Lock anchor with custom timeout.
217      * To release locks(s), the session holding the lock(s) must be closed.
218      *
219      * @param sessionID session ID
220      * @param dataspaceName dataspace name
221      * @param anchorName anchor name
222      * @param timeoutInMilliseconds lock attempt timeout in milliseconds
223      */
224     void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);
225 }