2cf63b3cf6c5416e19eebf8af7c268bd3d4ea721
[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 String PARAMETERS_PASSED_TO_SLI = "Parameters passed to SLI";
38     private static final String PARAMETERS_RETURNED_BY_SLI = "Parameters returned by SLI";
39
40     private static final Logger LOG = LoggerFactory.getLogger(A1AdapterClient.class);
41
42     private SvcLogicService svcLogicService = null;
43
44     public A1AdapterClient(final SvcLogicService svcLogicService) {
45         this.svcLogicService = svcLogicService;
46     }
47
48     public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
49         return svcLogicService.hasGraph(module, rpc, version, mode);
50     }
51
52     public Properties execute(String module, String rpc, String version, String mode,
53             GetA1PolicyTypeOutputBuilder serviceData, Properties parms) throws SvcLogicException {
54         Properties localProp;
55         localProp = MdsalHelper.toProperties(parms, serviceData);
56         if (LOG.isDebugEnabled()) {
57             logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
58         }
59         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
60         if (LOG.isDebugEnabled()) {
61             logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
62         }
63         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
64             return respProps;
65         }
66         MdsalHelper.toBuilder(respProps, serviceData);
67         return respProps;
68     }
69
70     public Properties execute(String module, String rpc, String version, String mode,
71             GetA1PolicyStatusOutputBuilder serviceData, Properties parms) throws SvcLogicException {
72         Properties localProp;
73         localProp = MdsalHelper.toProperties(parms, serviceData);
74         if (LOG.isDebugEnabled()) {
75             logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
76         }
77         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
78         if (LOG.isDebugEnabled()) {
79             logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
80         }
81         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
82             return respProps;
83         }
84         MdsalHelper.toBuilder(respProps, serviceData);
85         return respProps;
86     }
87
88     public Properties execute(String module, String rpc, String version, String mode,
89             GetA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
90         Properties localProp;
91         localProp = MdsalHelper.toProperties(parms, serviceData);
92         if (LOG.isDebugEnabled()) {
93             logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
94         }
95         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
96         if (LOG.isDebugEnabled()) {
97             logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
98         }
99         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
100             return respProps;
101         }
102         MdsalHelper.toBuilder(respProps, serviceData);
103         return respProps;
104     }
105
106     public Properties execute(String module, String rpc, String version, String mode,
107             DeleteA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
108         Properties localProp;
109         localProp = MdsalHelper.toProperties(parms, serviceData);
110         if (LOG.isDebugEnabled()) {
111             logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
112         }
113         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
114         if (LOG.isDebugEnabled()) {
115             logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
116         }
117         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
118             return respProps;
119         }
120         MdsalHelper.toBuilder(respProps, serviceData);
121         return respProps;
122     }
123
124     public Properties execute(String module, String rpc, String version, String mode,
125             PutA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
126         Properties localProp;
127         localProp = MdsalHelper.toProperties(parms, serviceData);
128         if (LOG.isDebugEnabled()) {
129             logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
130         }
131         Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
132         if (LOG.isDebugEnabled()) {
133             logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
134         }
135         if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
136             return respProps;
137         }
138         MdsalHelper.toBuilder(respProps, serviceData);
139         return respProps;
140     }
141
142     private void logParameters(String message, Properties localProp) {
143         LOG.debug(message);
144
145         for (Object key : localProp.keySet()) {
146             String parmName = (String) key;
147             String parmValue = localProp.getProperty(parmName);
148
149             LOG.debug("{}={}", parmName, parmValue);
150         }
151     }
152 }