Release version 2.1.1 and roll versions
[sdnc/northbound.git] / vnfapi / provider / src / main / java / org / onap / sdnc / vnfapi / VNFSDNSvcLogicServiceClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.sdnc.vnfapi;
23
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
26 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.data.PreloadDataBuilder;
27 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.data.ServiceDataBuilder;
28 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.preload.data.VfModulePreloadDataBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.service.data.VfModuleServiceDataBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.preload.data.VnfInstancePreloadDataBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.service.data.VnfInstanceServiceDataBuilder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 import java.util.Properties;
36
37 public class VNFSDNSvcLogicServiceClient {
38     static final String FAILURE_RESULT = "failure";
39     static final String SVC_LOGIC_STATUS_KEY = "SvcLogic.status";
40     private static final String TO_SLI_MSG = "Parameters passed to SLI";
41     private static final String FROM_SLI_MSG = "Parameters returned by SLI";
42
43     private final Logger logger = LoggerFactory.getLogger(VNFSDNSvcLogicServiceClient.class);
44
45     private final SvcLogicService svcLogic;
46
47     public VNFSDNSvcLogicServiceClient(final SvcLogicService svcLogicService) {
48         this.svcLogic = svcLogicService;
49     }
50
51     public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
52         return svcLogic.hasGraph(module, rpc, version, mode);
53     }
54
55     public Properties execute(String module, String rpc, String version, String mode, ServiceDataBuilder serviceData)
56             throws SvcLogicException {
57         return execute(module, rpc, version, mode, serviceData, new Properties());
58     }
59
60     public Properties execute(String module, String rpc, String version, String mode, PreloadDataBuilder serviceData)
61             throws SvcLogicException {
62         return execute(module, rpc, version, mode, serviceData, new Properties());
63     }
64
65     public Properties execute(String module,
66                               String rpc,
67                               String version,
68                               String mode,
69                               ServiceDataBuilder serviceData,
70                               Properties properties)
71             throws SvcLogicException {
72
73         Properties props = VnfSdnUtil.toProperties(properties, serviceData);
74         printDebugLog(props, TO_SLI_MSG);
75
76         Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
77         printDebugLog(respProps, FROM_SLI_MSG);
78
79         if (respProps == null
80                 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
81             return respProps;
82         }
83
84         VnfSdnUtil.toBuilder(respProps, serviceData);
85
86         return respProps;
87     }
88
89     public Properties execute(String module,
90                               String rpc,
91                               String version,
92                               String mode,
93                               PreloadDataBuilder serviceData,
94                               Properties properties)
95             throws SvcLogicException {
96
97         Properties props = VnfSdnUtil.toProperties(properties, serviceData);
98         printDebugLog(props, TO_SLI_MSG);
99
100         Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
101         printDebugLog(respProps, FROM_SLI_MSG);
102
103         if (respProps == null
104                 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
105             return respProps;
106         }
107
108         VnfSdnUtil.toBuilder(respProps, serviceData);
109
110         return respProps;
111     }
112
113
114     //1610 vnf-instance
115     public Properties execute(String module,
116                               String rpc,
117                               String version,
118                               String mode,
119                               VnfInstanceServiceDataBuilder serviceData)
120             throws SvcLogicException {
121         return execute(module, rpc, version, mode, serviceData, new Properties());
122     }
123
124     //1610 vnf-instance
125     public Properties execute(String module,
126                               String rpc,
127                               String version,
128                               String mode,
129                               VnfInstanceServiceDataBuilder serviceData,
130                               Properties properties)
131             throws SvcLogicException {
132
133         Properties props = VnfSdnUtil.toProperties(properties, serviceData);
134         printDebugLog(props, TO_SLI_MSG);
135
136         Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
137         printDebugLog(respProps, FROM_SLI_MSG);
138
139         if (respProps == null
140                 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
141             return respProps;
142         }
143
144         VnfSdnUtil.toBuilder(respProps, serviceData);
145
146         return respProps;
147     }
148
149     //1610 vf-module
150     public Properties execute(String module,
151                               String rpc,
152                               String version,
153                               String mode,
154                               VfModuleServiceDataBuilder serviceData)
155             throws SvcLogicException {
156         return execute(module, rpc, version, mode, serviceData, new Properties());
157     }
158
159     //1610 vf-module
160     public Properties execute(String module,
161                               String rpc,
162                               String version,
163                               String mode,
164                               VfModuleServiceDataBuilder serviceData,
165                               Properties properties)
166             throws SvcLogicException {
167
168         Properties props = VnfSdnUtil.toProperties(properties, serviceData);
169         printDebugLog(props, TO_SLI_MSG);
170
171         Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
172         printDebugLog(respProps, FROM_SLI_MSG);
173
174         if (respProps == null
175                 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
176             return respProps;
177         }
178
179         VnfSdnUtil.toBuilder(respProps, serviceData);
180
181         return respProps;
182     }
183
184     //1610 vnf-instance-preload
185     public Properties execute(String module,
186                               String rpc,
187                               String version,
188                               String mode,
189                               VnfInstancePreloadDataBuilder serviceData)
190             throws SvcLogicException {
191         return execute(module, rpc, version, mode, serviceData, new Properties());
192     }
193
194     //1610 vnf-instance-preload
195     public Properties execute(String module,
196                               String rpc,
197                               String version,
198                               String mode,
199                               VnfInstancePreloadDataBuilder serviceData,
200                               Properties properties)
201             throws SvcLogicException {
202
203         Properties props = VnfSdnUtil.toProperties(properties, serviceData);
204         printDebugLog(props, TO_SLI_MSG);
205
206         Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
207         printDebugLog(respProps, FROM_SLI_MSG);
208
209         if (respProps == null
210                 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
211             return respProps;
212         }
213
214         VnfSdnUtil.toBuilder(respProps, serviceData);
215
216         return respProps;
217     }
218
219     //1610 vf-module-preload
220     public Properties execute(String module,
221                               String rpc,
222                               String version,
223                               String mode,
224                               VfModulePreloadDataBuilder serviceData)
225             throws SvcLogicException {
226         return execute(module, rpc, version, mode, serviceData, new Properties());
227     }
228
229     //1610 vf-module-preload
230     public Properties execute(String module,
231                               String rpc,
232                               String version,
233                               String mode,
234                               VfModulePreloadDataBuilder serviceData,
235                               Properties properties)
236             throws SvcLogicException {
237
238         Properties props = VnfSdnUtil.toProperties(properties, serviceData);
239         printDebugLog(props, TO_SLI_MSG);
240
241         Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
242         printDebugLog(respProps, FROM_SLI_MSG);
243
244         if (respProps == null
245                 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
246             return respProps;
247         }
248
249         VnfSdnUtil.toBuilder(respProps, serviceData);
250
251         return respProps;
252     }
253
254     private void printDebugLog(Properties properties, String msg) {
255         if (!logger.isDebugEnabled()) {
256             return;
257         }
258         if (properties == null) {
259             logger.debug(msg, "properties is null");
260             return;
261         }
262
263         logger.debug(msg);
264         for (Object key : properties.keySet()) {
265             String paramName = (String) key;
266             logger.debug(paramName, " = ", properties.getProperty(paramName));
267         }
268     }
269
270 }