2 z * ============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.northbound;
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.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadDataBuilder;
27 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import java.util.Properties;
33 public class GenericResourceApiSvcLogicServiceClient {
34 static final String FAILURE_RESULT = "failure";
35 static final String SVC_LOGIC_STATUS_KEY = "SvcLogic.status";
37 private final Logger LOG = LoggerFactory
38 .getLogger(GenericResourceApiSvcLogicServiceClient.class);
40 private SvcLogicService svcLogic = null;
42 public GenericResourceApiSvcLogicServiceClient(SvcLogicService svcLogic)
44 this.svcLogic = svcLogic;
47 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException
49 return svcLogic.hasGraph(module, rpc, version, mode);
52 public Properties execute(String module, String rpc, String version, String mode, ServiceDataBuilder serviceData)
53 throws SvcLogicException {
54 return execute(module, rpc, version, mode, serviceData, new Properties());
57 public Properties execute(String module, String rpc, String version, String mode, PreloadDataBuilder serviceData)
58 throws SvcLogicException {
59 return execute(module, rpc, version, mode, serviceData, new Properties());
62 public Properties execute(String module,
66 ServiceDataBuilder serviceData,
67 Properties properties)
68 throws SvcLogicException {
70 Properties props = GenericResourceApiUtil.toProperties(properties, serviceData);
71 printPropsDebugLogs(props, "Parameters passed to SLI");
73 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
74 printPropsDebugLogs(respProps, "Parameters returned by SLI");
76 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
80 GenericResourceApiUtil.toBuilder(respProps, serviceData);
86 public Properties execute(String module,
90 PreloadDataBuilder serviceData,
91 Properties properties)
92 throws SvcLogicException {
94 Properties props = GenericResourceApiUtil.toProperties(properties, serviceData);
95 printPropsDebugLogs(props, "Parameters passed to SLI");
97 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
98 printPropsDebugLogs(respProps, "Parameters returned by SLI");
100 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
104 GenericResourceApiUtil.toBuilder(respProps, serviceData);
109 public Properties execute(String module, String rpc, String version, String mode, Properties properties)
110 throws SvcLogicException {
112 printPropsDebugLogs(properties, "Parameters passed to SLI");
114 Properties respProps = svcLogic.execute(module, rpc, version, mode, properties);
115 printPropsDebugLogs(respProps, "Parameters returned by SLI");
116 if (respProps == null || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
124 private void printPropsDebugLogs(Properties properties, String msg) {
125 if (!LOG.isDebugEnabled()) {
128 if (properties == null) {
129 LOG.debug(msg, "properties is null");
134 for (Object key : properties.keySet()) {
135 String paramName = (String) key;
136 LOG.debug(paramName, " = ", properties.getProperty(paramName));