Add Start and Stop sessions on JAVA API
[cps.git] / cps-service / src / main / java / org / onap / cps / spi / CpsDataPersistenceService.java
1 /*
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
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.spi;
24
25 import java.util.Collection;
26 import java.util.Map;
27 import org.onap.cps.spi.model.DataNode;
28
29 /*
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
32     when adding methods.
33  */
34 public interface CpsDataPersistenceService {
35
36     /**
37      * Store a datanode.
38      *
39      * @param dataspaceName dataspace name
40      * @param anchorName    anchor name
41      * @param dataNode      data node
42      */
43     void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
44
45     /**
46      * Add a child to a Fragment.
47      *
48      * @param dataspaceName dataspace name
49      * @param anchorName    anchor name
50      * @param parentXpath   parent xpath
51      * @param dataNode      dataNode
52      */
53     void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
54
55     /**
56      * Adds list child elements to a Fragment.
57      *
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
62      */
63
64     void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
65         Collection<DataNode> listElementsCollection);
66
67     /**
68      * Retrieves datanode by XPath for given dataspace and anchor.
69      *
70      * @param dataspaceName          dataspace name
71      * @param anchorName             anchor name
72      * @param xpath                  xpath
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
76      */
77     DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
78         FetchDescendantsOption fetchDescendantsOption);
79
80
81     /**
82      * Updates leaves for existing data node.
83      *
84      * @param dataspaceName dataspace name
85      * @param anchorName    anchor name
86      * @param xpath         xpath
87      * @param leaves        the leaves as a map where key is a leaf name and a value is a leaf value
88      */
89     void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves);
90
91     /**
92      * Replaces existing data node content including descendants.
93      *
94      * @param dataspaceName dataspace name
95      * @param anchorName    anchor name
96      * @param dataNode      data node
97      */
98     void replaceDataNodeTree(String dataspaceName, String anchorName, DataNode dataNode);
99
100     /**
101      * Replaces list content by removing all existing elements and inserting the given new elements
102      * under given parent, anchor and dataspace.
103      *
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
108      */
109     void replaceListContent(String dataspaceName, String anchorName,
110                             String parentNodeXpath, Collection<DataNode> newListElements);
111
112     /**
113      * Deletes any dataNode, yang container or yang list or yang list element.
114      *
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)
118      */
119     void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
120
121     /**
122      * Deletes all dataNodes in a given anchor.
123      *
124      * @param dataspaceName   dataspace name
125      * @param anchorName      anchor name
126      */
127     void deleteDataNodes(String dataspaceName, String anchorName);
128
129     /**
130      * Deletes existing a single list element or the whole list.
131      *
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)
135      */
136     void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
137
138     /**
139      * Get a datanode by cps path.
140      *
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
147      */
148     Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName,
149         String cpsPath, FetchDescendantsOption fetchDescendantsOption);
150
151     /**
152      * Starts a session which allows use of locks and batch interaction with the persistence service.
153      *
154      * @return Session ID string
155      */
156     String startSession();
157
158     /**
159      * Close session.
160      *
161      * @param sessionId session ID
162      */
163     void closeSession(String sessionId);
164 }