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";
36 static final String SKIP_MDSAL_UPDATE_PROP = "skip-mdsal-update";
38 // Next 2 fields protected so they can be overridden in jUnit without resorting to Java reflection
39 protected Logger LOG = LoggerFactory
40 .getLogger(GenericResourceApiSvcLogicServiceClient.class);
41 protected SvcLogicService svcLogic = null;
43 public GenericResourceApiSvcLogicServiceClient(SvcLogicService svcLogic)
45 this.svcLogic = svcLogic;
48 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException
50 return svcLogic.hasGraph(module, rpc, version, mode);
53 public Properties execute(String module, String rpc, String version, String mode, ServiceDataBuilder serviceData)
54 throws SvcLogicException {
55 return execute(module, rpc, version, mode, serviceData, new Properties());
58 public Properties execute(String module, String rpc, String version, String mode, PreloadDataBuilder serviceData)
59 throws SvcLogicException {
60 return execute(module, rpc, version, mode, serviceData, new Properties());
63 public Properties execute(String module,
67 ServiceDataBuilder serviceData,
68 Properties properties)
69 throws SvcLogicException {
71 Properties props = GenericResourceApiUtil.toProperties(properties, serviceData);
72 printPropsDebugLogs(props, "Parameters passed to SLI");
74 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
75 printPropsDebugLogs(respProps, "Parameters returned by SLI");
77 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
81 String skipMdsalUpdate = respProps.getProperty(SKIP_MDSAL_UPDATE_PROP);
82 if ((skipMdsalUpdate == null) || !skipMdsalUpdate.equals("Y")) {
83 GenericResourceApiUtil.toBuilder(respProps, serviceData);
85 LOG.debug("Skipping call to MdsalHelper.toBuilder");
92 public Properties execute(String module,
96 PreloadDataBuilder serviceData,
97 Properties properties)
98 throws SvcLogicException {
100 Properties props = GenericResourceApiUtil.toProperties(properties, serviceData);
101 printPropsDebugLogs(props, "Parameters passed to SLI");
103 Properties respProps = svcLogic.execute(module, rpc, version, mode, props);
104 printPropsDebugLogs(respProps, "Parameters returned by SLI");
105 if (respProps == null
106 || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
110 GenericResourceApiUtil.toBuilder(respProps, serviceData);
115 public Properties execute(String module, String rpc, String version, String mode, Properties properties)
116 throws SvcLogicException {
118 printPropsDebugLogs(properties, "Parameters passed to SLI");
120 Properties respProps = svcLogic.execute(module, rpc, version, mode, properties);
121 printPropsDebugLogs(respProps, "Parameters returned by SLI");
122 if (respProps == null || FAILURE_RESULT.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_STATUS_KEY))) {
130 private void printPropsDebugLogs(Properties properties, String msg) {
131 if (!LOG.isDebugEnabled()) {
134 if (properties == null) {
135 LOG.debug(msg, "properties is null");
140 for (Object key : properties.keySet()) {
141 String paramName = (String) key;
142 LOG.debug(paramName + " = " + properties.getProperty(paramName));