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