2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.provider;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import org.onap.appc.util.StringHelper;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
31 import org.osgi.framework.BundleContext;
32 import org.osgi.framework.FrameworkUtil;
33 import org.osgi.framework.ServiceReference;
36 import java.text.DateFormat;
37 import java.text.SimpleDateFormat;
38 import java.util.Date;
39 import java.util.Properties;
40 import java.util.TimeZone;
42 public class AppcProviderClient {
44 private final EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
45 private final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
47 private SvcLogicService svcLogic = null;
49 public AppcProviderClient() {
50 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
51 // Handle BundleContext returning null
53 LOG.warn("Cannot find bundle context for " + SvcLogicService.NAME);
55 // Get SvcLogicService reference
56 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
58 svcLogic = (SvcLogicService) bctx.getService(sref);
61 LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
67 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
68 LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
69 return (svcLogic.hasGraph(module, rpc, version, mode));
72 public Properties execute(String module, String rpc, String version, String mode, Properties parms)
73 throws SvcLogicException {
76 * Set End time for Metrics Logger
78 long startTime = System.currentTimeMillis();
79 TimeZone tz = TimeZone.getTimeZone("UTC");
80 DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
82 long endTime = System.currentTimeMillis();
83 long duration = endTime - startTime;
84 String durationStr = String.valueOf(duration);
85 String endTimeStrUTC = df.format(new Date());
86 MDC.put("EndTimestamp", endTimeStrUTC);
87 MDC.put("ElapsedTime", durationStr);
88 MDC.put("TargetEntity", "sli");
89 MDC.put("TargetServiceName", "execute");
90 MDC.put("ClassName", "org.onap.appc.provider.AppcProviderClient");
92 LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
93 metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
95 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
98 * Set End time for Metrics Logger
100 endTime = System.currentTimeMillis();
101 duration = endTime - startTime;
102 durationStr = String.valueOf(duration);
103 endTimeStrUTC = df.format(new Date());
104 MDC.put("EndTimestamp", endTimeStrUTC);
105 MDC.put("ElapsedTime", durationStr);
107 LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
108 metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));