Initial commit for OpenECOMP SDN-C northbound
[sdnc/northbound.git] / dataChange / provider / src / main / java / org / openecomp / sdnc / datachange / DataChangeClient.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.openecomp.sdnc.datachange;
23
24 import java.util.Properties;
25
26 import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.rev150519.DataChangeNotificationOutputBuilder;
27 import org.openecomp.sdnc.sli.SvcLogicException;
28 import org.openecomp.sdnc.sli.provider.MdsalHelper;
29 import org.openecomp.sdnc.sli.provider.SvcLogicService;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.FrameworkUtil;
32 import org.osgi.framework.ServiceReference;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class DataChangeClient {
37
38         private static final Logger LOG = LoggerFactory
39                         .getLogger(DataChangeClient.class);
40
41         private SvcLogicService svcLogic = null;
42
43         public DataChangeClient()
44         {
45                 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
46
47         // Get SvcLogicService reference
48                 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
49                 if (sref  != null)
50                 {
51                         svcLogic =  (SvcLogicService) bctx.getService(sref);
52
53                 }
54                 else
55                 {
56                         LOG.warn("Cannot find service reference for "+SvcLogicService.NAME);
57
58                 }
59         }
60
61         public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException
62         {
63                 return(svcLogic.hasGraph(module, rpc, version, mode));
64         }
65
66         public Properties execute(String module, String rpc, String version, String mode, DataChangeNotificationOutputBuilder serviceData)
67                         throws SvcLogicException {
68
69                 Properties parms = new Properties();
70
71                 return execute(module,rpc,version, mode,serviceData,parms);
72         }
73
74         public Properties execute(String module, String rpc, String version, String mode, DataChangeNotificationOutputBuilder serviceData, Properties parms)
75                                 throws SvcLogicException {
76
77                 parms = MdsalHelper.toProperties(parms, serviceData);
78
79                 if (LOG.isDebugEnabled())
80                 {
81                         LOG.debug("Parameters passed to SLI");
82
83                         for (Object key : parms.keySet()) {
84                                 String parmName = (String) key;
85                                 String parmValue = parms.getProperty(parmName);
86
87                                 LOG.debug(parmName+" = "+parmValue);
88
89                         }
90                 }
91
92                 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
93
94                 if (LOG.isDebugEnabled())
95                 {
96                         LOG.debug("Parameters returned by SLI");
97
98                         for (Object key : respProps.keySet()) {
99                                 String parmName = (String) key;
100                                 String parmValue = respProps.getProperty(parmName);
101
102                                 LOG.debug(parmName+" = "+parmValue);
103
104                         }
105                 }
106                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
107                         return (respProps);
108                 }
109
110                 MdsalHelper.toBuilder(respProps, serviceData);
111
112                 return (respProps);
113         }
114
115 }