Merge "Expose Prometheus metrics for monitoring"
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / NetworkCmProxyDataServiceImpl.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 highstreet technologies GmbH
4  *  Modifications Copyright (C) 2021 Nordix Foundation
5  *  Modifications Copyright (C) 2021 Pantheon.tech
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.ncmp.api.impl;
24
25 import java.util.Collection;
26 import org.onap.cps.api.CpsDataService;
27 import org.onap.cps.api.CpsQueryService;
28 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
29 import org.onap.cps.spi.FetchDescendantsOption;
30 import org.onap.cps.spi.model.DataNode;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Service;
33 import org.springframework.util.StringUtils;
34
35 @Service
36 public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
37
38     private static final String NF_PROXY_DATASPACE_NAME = "NFP-Operational";
39
40     @Autowired
41     private CpsDataService cpsDataService;
42
43     @Autowired
44     private CpsQueryService cpsQueryService;
45
46     private String getDataspaceName() {
47         return NF_PROXY_DATASPACE_NAME;
48     }
49
50     @Override
51     public DataNode getDataNode(final String cmHandle, final String xpath,
52         final FetchDescendantsOption fetchDescendantsOption) {
53         return cpsDataService.getDataNode(getDataspaceName(), cmHandle, xpath, fetchDescendantsOption);
54     }
55
56     @Override
57     public Collection<DataNode> queryDataNodes(final String cmHandle, final String cpsPath,
58         final FetchDescendantsOption fetchDescendantsOption) {
59         return cpsQueryService.queryDataNodes(getDataspaceName(), cmHandle, cpsPath, fetchDescendantsOption);
60     }
61
62     @Override
63     public void createDataNode(final String cmHandle, final String parentNodeXpath, final String jsonData) {
64         if (!StringUtils.hasText(parentNodeXpath) || "/".equals(parentNodeXpath)) {
65             cpsDataService.saveData(getDataspaceName(), cmHandle, jsonData);
66         } else {
67             cpsDataService.saveData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
68         }
69     }
70
71     @Override
72     public void addListNodeElements(final String cmHandle, final String parentNodeXpath, final String jsonData) {
73         cpsDataService.saveListNodeData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
74     }
75
76     @Override
77     public void updateNodeLeaves(final String cmHandle, final String parentNodeXpath, final String jsonData) {
78         cpsDataService.updateNodeLeaves(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
79     }
80
81     @Override
82     public void replaceNodeTree(final String cmHandle, final String parentNodeXpath, final String jsonData) {
83         cpsDataService.replaceNodeTree(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
84     }
85 }