2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.sdnc.vnfapi;
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;
35 import java.util.Properties;
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";
43 private final Logger logger = LoggerFactory.getLogger(VNFSDNSvcLogicServiceClient.class);
45 private final SvcLogicService svcLogic;
47 public VNFSDNSvcLogicServiceClient(final SvcLogicService svcLogicService) {
48 this.svcLogic = svcLogicService;
51 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
52 return svcLogic.hasGraph(module, rpc, version, mode);
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());
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());
65 public Properties execute(String module,
69 ServiceDataBuilder serviceData,
70 Properties properties)
71 throws SvcLogicException {
73 Properties props = VnfSdnUtil.toProperties(properties, serviceData);
74 printDebugLog(props, TO_SLI_MSG);
76 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
77 printDebugLog(respProps, FROM_SLI_MSG);
80 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
84 VnfSdnUtil.toBuilder(respProps, serviceData);
89 public Properties execute(String module,
93 PreloadDataBuilder serviceData,
94 Properties properties)
95 throws SvcLogicException {
97 Properties props = VnfSdnUtil.toProperties(properties, serviceData);
98 printDebugLog(props, TO_SLI_MSG);
100 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
101 printDebugLog(respProps, FROM_SLI_MSG);
103 if (respProps == null
104 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
108 VnfSdnUtil.toBuilder(respProps, serviceData);
115 public Properties execute(String module,
119 VnfInstanceServiceDataBuilder serviceData)
120 throws SvcLogicException {
121 return execute(module, rpc, version, mode, serviceData, new Properties());
125 public Properties execute(String module,
129 VnfInstanceServiceDataBuilder serviceData,
130 Properties properties)
131 throws SvcLogicException {
133 Properties props = VnfSdnUtil.toProperties(properties, serviceData);
134 printDebugLog(props, TO_SLI_MSG);
136 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
137 printDebugLog(respProps, FROM_SLI_MSG);
139 if (respProps == null
140 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
144 VnfSdnUtil.toBuilder(respProps, serviceData);
150 public Properties execute(String module,
154 VfModuleServiceDataBuilder serviceData)
155 throws SvcLogicException {
156 return execute(module, rpc, version, mode, serviceData, new Properties());
160 public Properties execute(String module,
164 VfModuleServiceDataBuilder serviceData,
165 Properties properties)
166 throws SvcLogicException {
168 Properties props = VnfSdnUtil.toProperties(properties, serviceData);
169 printDebugLog(props, TO_SLI_MSG);
171 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
172 printDebugLog(respProps, FROM_SLI_MSG);
174 if (respProps == null
175 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
179 VnfSdnUtil.toBuilder(respProps, serviceData);
184 //1610 vnf-instance-preload
185 public Properties execute(String module,
189 VnfInstancePreloadDataBuilder serviceData)
190 throws SvcLogicException {
191 return execute(module, rpc, version, mode, serviceData, new Properties());
194 //1610 vnf-instance-preload
195 public Properties execute(String module,
199 VnfInstancePreloadDataBuilder serviceData,
200 Properties properties)
201 throws SvcLogicException {
203 Properties props = VnfSdnUtil.toProperties(properties, serviceData);
204 printDebugLog(props, TO_SLI_MSG);
206 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
207 printDebugLog(respProps, FROM_SLI_MSG);
209 if (respProps == null
210 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
214 VnfSdnUtil.toBuilder(respProps, serviceData);
219 //1610 vf-module-preload
220 public Properties execute(String module,
224 VfModulePreloadDataBuilder serviceData)
225 throws SvcLogicException {
226 return execute(module, rpc, version, mode, serviceData, new Properties());
229 //1610 vf-module-preload
230 public Properties execute(String module,
234 VfModulePreloadDataBuilder serviceData,
235 Properties properties)
236 throws SvcLogicException {
238 Properties props = VnfSdnUtil.toProperties(properties, serviceData);
239 printDebugLog(props, TO_SLI_MSG);
241 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
242 printDebugLog(respProps, FROM_SLI_MSG);
244 if (respProps == null
245 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
249 VnfSdnUtil.toBuilder(respProps, serviceData);
254 private void printDebugLog(Properties properties, String msg) {
255 if (!logger.isDebugEnabled()) {
258 if (properties == null) {
259 logger.debug(msg, "properties is null");
264 for (Object key : properties.keySet()) {
265 String paramName = (String) key;
266 logger.debug(paramName, " = ", properties.getProperty(paramName));