04b71e79741c19cdaf21a32cc745dd6501508e42
[sdnc/northbound.git] / generic-resource-api / provider / src / main / java / org / onap / sdnc / northbound / GenericResourceApiSvcLogicServiceClient.java
1 package org.onap.sdnc.northbound;
2
3 import java.util.Properties;
4
5 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
6 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
7 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadDataBuilder;
8 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
9 import org.osgi.framework.BundleContext;
10 import org.osgi.framework.FrameworkUtil;
11 import org.osgi.framework.ServiceReference;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 public class GenericResourceApiSvcLogicServiceClient {
16
17         private static final Logger LOG = LoggerFactory
18                         .getLogger(GenericResourceApiSvcLogicServiceClient.class);
19
20         private SvcLogicService svcLogic = null;
21
22         public GenericResourceApiSvcLogicServiceClient()
23         {
24                 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
25
26         // Get SvcLogicService reference
27                 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
28                 if (sref  != null)
29                 {
30                         svcLogic =  (SvcLogicService) bctx.getService(sref);
31
32                 }
33                 else
34                 {
35                         LOG.warn("Cannot find service reference for "+SvcLogicService.NAME);
36
37                 }
38         }
39
40         public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException
41         {
42                 return(svcLogic.hasGraph(module, rpc, version, mode));
43         }
44
45         public Properties execute(String module, String rpc, String version, String mode, ServiceDataBuilder serviceData)
46                         throws SvcLogicException {
47
48                 Properties parms = new Properties();
49
50                 return execute(module,rpc,version, mode,serviceData,parms);
51         }
52
53         public Properties execute(String module, String rpc, String version, String mode, PreloadDataBuilder serviceData)
54                         throws SvcLogicException {
55
56                 Properties parms = new Properties();
57
58                 return execute(module,rpc,version, mode,serviceData,parms);
59         }
60
61
62         public Properties execute(String module, String rpc, String version, String mode, ServiceDataBuilder serviceData, Properties parms)
63                                 throws SvcLogicException {
64
65                 parms = GenericResourceApiUtil.toProperties(parms, serviceData);
66
67                 if (LOG.isDebugEnabled())
68                 {
69                         LOG.debug("Parameters passed to SLI");
70
71                         for (Object key : parms.keySet()) {
72                                 String parmName = (String) key;
73                                 String parmValue = parms.getProperty(parmName);
74
75                                 LOG.debug(parmName+" = "+parmValue);
76
77                         }
78                 }
79
80                 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
81
82                 if (LOG.isDebugEnabled())
83                 {
84                         LOG.debug("Parameters returned by SLI");
85
86                         for (Object key : respProps.keySet()) {
87                                 String parmName = (String) key;
88                                 String parmValue = respProps.getProperty(parmName);
89
90                                 LOG.debug(parmName+" = "+parmValue);
91
92                         }
93                 }
94                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
95                         return (respProps);
96                 }
97
98                 GenericResourceApiUtil.toBuilder(respProps, serviceData);
99
100                 return (respProps);
101         }
102
103
104         public Properties execute(String module, String rpc, String version, String mode, PreloadDataBuilder serviceData, Properties parms)
105                                 throws SvcLogicException {
106
107                 parms = GenericResourceApiUtil.toProperties(parms, serviceData);
108
109                 if (LOG.isDebugEnabled())
110                 {
111                         LOG.debug("Parameters passed to SLI");
112
113                         for (Object key : parms.keySet()) {
114                                 String parmName = (String) key;
115                                 String parmValue = parms.getProperty(parmName);
116
117                                 LOG.debug(parmName+" = "+parmValue);
118
119                         }
120                 }
121
122                 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
123
124                 if (LOG.isDebugEnabled())
125                 {
126                         LOG.debug("Parameters returned by SLI");
127
128                         for (Object key : respProps.keySet()) {
129                                 String parmName = (String) key;
130                                 String parmValue = respProps.getProperty(parmName);
131
132                                 LOG.debug(parmName+" = "+parmValue);
133
134                         }
135                 }
136                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
137                         return (respProps);
138                 }
139
140                 GenericResourceApiUtil.toBuilder(respProps, serviceData);
141
142                 return (respProps);
143         }
144 }