Merge "Expose Prometheus metrics for monitoring"
[cps.git] / cps-service / src / main / java / org / onap / cps / api / CpsDataService.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation
4  *  Modifications Copyright (C) 2021 Pantheon.tech
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.api;
23
24 import org.checkerframework.checker.nullness.qual.NonNull;
25 import org.onap.cps.spi.FetchDescendantsOption;
26 import org.onap.cps.spi.exceptions.AlreadyDefinedException;
27 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
28 import org.onap.cps.spi.exceptions.DataValidationException;
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      * @throws DataValidationException when json data is invalid
43      */
44     void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData);
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      * @throws DataValidationException   when json data is invalid
54      * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
55      * @throws AlreadyDefinedException   when child data node with same xpath already exists
56      */
57     void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
58         @NonNull String jsonData);
59
60     /**
61      * Persists child data fragment representing list-node (with one or more elements) under existing data node
62      * for the given anchor and dataspace.
63      *
64      * @param dataspaceName   dataspace name
65      * @param anchorName      anchor name
66      * @param parentNodeXpath parent node xpath
67      * @param jsonData        json data representing list element
68      * @throws DataValidationException   when json data is invalid (incl. list-node being empty)
69      * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
70      * @throws AlreadyDefinedException   when any of child data nodes is having xpath of already existing node
71      */
72     void saveListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
73         @NonNull String jsonData);
74
75     /**
76      * Retrieves datanode by XPath for given dataspace and anchor.
77      *
78      * @param dataspaceName          dataspace name
79      * @param anchorName             anchor name
80      * @param xpath                  xpath
81      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
82      *                               (recursively) as well
83      * @return data node object
84      */
85     DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
86         @NonNull FetchDescendantsOption fetchDescendantsOption);
87
88     /**
89      * Updates data node for given dataspace and anchor using xpath to parent node.
90      *
91      * @param dataspaceName   dataspace name
92      * @param anchorName      anchor name
93      * @param parentNodeXpath xpath to parent node
94      * @param jsonData        json data
95      */
96     void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
97         @NonNull String jsonData);
98
99     /**
100      * Replaces existing data node content including descendants.
101      *
102      * @param dataspaceName   dataspace name
103      * @param anchorName      anchor name
104      * @param parentNodeXpath xpath to parent node
105      * @param jsonData        json data
106      */
107     void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
108         @NonNull String jsonData);
109
110     /**
111      * Replaces (if exists) child data fragment representing list-node (with one or more elements)
112      * under existing data node for the given anchor and dataspace.
113      *
114      * @param dataspaceName   dataspace name
115      * @param anchorName      anchor name
116      * @param parentNodeXpath parent node xpath
117      * @param jsonData        json data representing list element
118      * @throws DataValidationException   when json data is invalid (incl. list-node being empty)
119      * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
120      */
121     void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
122         @NonNull String jsonData);
123 }