f1b2eaeebf16a5b782a20d1b706bd5157166f1a3
[ccsdk/oran.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.features.a1.adapter;
22
23 import java.util.Properties;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
26 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
27 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder;
28 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutputBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutputBuilder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class A1AdapterClient {
36
37     private static final Logger LOG = LoggerFactory.getLogger(A1AdapterClient.class);
38
39     private SvcLogicService svcLogicService = null;
40
41     public A1AdapterClient(final SvcLogicService svcLogicService) {
42         this.svcLogicService = svcLogicService;
43     }
44
45     public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
46         return svcLogicService.hasGraph(module, rpc, version, mode);
47     }
48
49     public Properties execute(String module, String rpc, String version, String mode,
50             GetA1PolicyTypeOutputBuilder serviceData, Properties parms) throws SvcLogicException {
51         Properties localProp;
52         localProp = MdsalHelper.toProperties(parms, serviceData);
53         if (LOG.isDebugEnabled()) {
54             LOG.debug("Parameters passed to SLI");
55
56             for (Object key : localProp.keySet()) {
57                 String parmName = (String) key;
58                 String parmValue = localProp.getProperty(parmName);
59
60                 LOG.debug(parmName + " = " + parmValue);
61             }
62         }
63         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
64         if (LOG.isDebugEnabled()) {
65             LOG.debug("Parameters returned by SLI");
66             for (Object key : respProps.keySet()) {
67                 String parmName = (String) key;
68                 String parmValue = respProps.getProperty(parmName);
69                 LOG.debug(parmName + " = " + parmValue);
70             }
71         }
72         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
73             return respProps;
74         }
75         MdsalHelper.toBuilder(respProps, serviceData);
76         return respProps;
77     }
78
79     public Properties execute(String module, String rpc, String version, String mode,
80             GetA1PolicyStatusOutputBuilder serviceData, Properties parms) throws SvcLogicException {
81         Properties localProp;
82         localProp = MdsalHelper.toProperties(parms, serviceData);
83         if (LOG.isDebugEnabled()) {
84             LOG.debug("Parameters passed to SLI");
85
86             for (Object key : localProp.keySet()) {
87                 String parmName = (String) key;
88                 String parmValue = localProp.getProperty(parmName);
89
90                 LOG.debug(parmName + " = " + parmValue);
91             }
92         }
93         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
94         if (LOG.isDebugEnabled()) {
95             LOG.debug("Parameters returned by SLI");
96             for (Object key : respProps.keySet()) {
97                 String parmName = (String) key;
98                 String parmValue = respProps.getProperty(parmName);
99                 LOG.debug(parmName + " = " + parmValue);
100             }
101         }
102         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
103             return respProps;
104         }
105         MdsalHelper.toBuilder(respProps, serviceData);
106         return respProps;
107     }
108
109     public Properties execute(String module, String rpc, String version, String mode,
110             GetA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
111         Properties localProp;
112         localProp = MdsalHelper.toProperties(parms, serviceData);
113         if (LOG.isDebugEnabled()) {
114             LOG.debug("Parameters passed to SLI");
115
116             for (Object key : localProp.keySet()) {
117                 String parmName = (String) key;
118                 String parmValue = localProp.getProperty(parmName);
119
120                 LOG.debug(parmName + " = " + parmValue);
121             }
122         }
123         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
124         if (LOG.isDebugEnabled()) {
125             LOG.debug("Parameters returned by SLI");
126             for (Object key : respProps.keySet()) {
127                 String parmName = (String) key;
128                 String parmValue = respProps.getProperty(parmName);
129                 LOG.debug(parmName + " = " + parmValue);
130             }
131         }
132         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
133             return respProps;
134         }
135         MdsalHelper.toBuilder(respProps, serviceData);
136         return respProps;
137     }
138
139     public Properties execute(String module, String rpc, String version, String mode,
140             DeleteA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
141         Properties localProp;
142         localProp = MdsalHelper.toProperties(parms, serviceData);
143         if (LOG.isDebugEnabled()) {
144             LOG.debug("Parameters passed to SLI");
145
146             for (Object key : localProp.keySet()) {
147                 String parmName = (String) key;
148                 String parmValue = localProp.getProperty(parmName);
149
150                 LOG.debug(parmName + " = " + parmValue);
151             }
152         }
153         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
154         if (LOG.isDebugEnabled()) {
155             LOG.debug("Parameters returned by SLI");
156             for (Object key : respProps.keySet()) {
157                 String parmName = (String) key;
158                 String parmValue = respProps.getProperty(parmName);
159                 LOG.debug(parmName + " = " + parmValue);
160             }
161         }
162         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
163             return respProps;
164         }
165         MdsalHelper.toBuilder(respProps, serviceData);
166         return respProps;
167     }
168
169     public Properties execute(String module, String rpc, String version, String mode,
170             PutA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
171         Properties localProp;
172         localProp = MdsalHelper.toProperties(parms, serviceData);
173         if (LOG.isDebugEnabled()) {
174             LOG.debug("Parameters passed to SLI");
175
176             for (Object key : localProp.keySet()) {
177                 String parmName = (String) key;
178                 String parmValue = localProp.getProperty(parmName);
179
180                 LOG.debug(parmName + " = " + parmValue);
181             }
182         }
183         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
184         if (LOG.isDebugEnabled()) {
185             LOG.debug("Parameters returned by SLI");
186             for (Object key : respProps.keySet()) {
187                 String parmName = (String) key;
188                 String parmValue = respProps.getProperty(parmName);
189                 LOG.debug(parmName + " = " + parmValue);
190             }
191         }
192         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
193             return respProps;
194         }
195         MdsalHelper.toBuilder(respProps, serviceData);
196         return respProps;
197     }
198 }