Moving all files to root directory
[appc.git] / appc-provider / appc-provider-bundle / src / main / java / org / openecomp / appc / provider / AppcProviderClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-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.appc.provider;
23
24 import org.openecomp.appc.util.StringHelper;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import com.att.eelf.i18n.EELFResourceManager;
28 import org.openecomp.sdnc.sli.SvcLogicException;
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
34 import static com.att.eelf.configuration.Configuration.*;
35
36 import java.util.Properties;
37
38 public class AppcProviderClient {
39
40     //private static final Logger LOG = LoggerFactory.getLogger(AppcProviderClient.class);
41         private static EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
42     private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
43
44     private SvcLogicService svcLogic = null;
45
46     public AppcProviderClient() {
47         BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
48
49         // Get SvcLogicService reference
50         ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
51         if (sref != null) {
52             svcLogic = (SvcLogicService) bctx.getService(sref);
53
54         } else {
55             LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
56
57         }
58     }
59
60     public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
61         LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
62         return (svcLogic.hasGraph(module, rpc, version, mode));
63     }
64
65     public Properties execute(String module, String rpc, String version, String mode, Properties parms)
66         throws SvcLogicException {
67
68         LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
69         metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
70
71         Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
72
73         LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
74         metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
75
76         // No impact on flow. Not sure why it is here
77         // if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) { return (respProps); }
78
79         return respProps;
80     }
81 }