2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.provider;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.onap.appc.util.StringHelper;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
32 import org.osgi.framework.BundleContext;
33 import org.osgi.framework.FrameworkUtil;
34 import org.osgi.framework.ServiceReference;
37 import java.text.DateFormat;
38 import java.text.SimpleDateFormat;
39 import java.util.Date;
40 import java.util.Properties;
41 import java.util.TimeZone;
43 public class AppcProviderClient {
45 private final EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
46 private final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
48 private SvcLogicService svcLogic = null;
50 public AppcProviderClient() {
51 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
52 // Handle BundleContext returning null
54 LOG.warn("Cannot find bundle context for " + SvcLogicService.NAME);
56 // Get SvcLogicService reference
57 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
59 svcLogic = (SvcLogicService) bctx.getService(sref);
62 LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
68 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
69 LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
70 return (svcLogic.hasGraph(module, rpc, version, mode));
73 public Properties execute(String module, String rpc, String version, String mode, Properties parms)
74 throws SvcLogicException {
77 * Set End time for Metrics Logger
79 long startTime = System.currentTimeMillis();
80 TimeZone tz = TimeZone.getTimeZone("UTC");
81 DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
83 long endTime = System.currentTimeMillis();
84 long duration = endTime - startTime;
85 String durationStr = String.valueOf(duration);
86 String endTimeStrUTC = df.format(new Date());
87 MDC.put("EndTimestamp", endTimeStrUTC);
88 MDC.put("ElapsedTime", durationStr);
89 MDC.put("TargetEntity", "sli");
90 MDC.put("TargetServiceName", "execute");
91 MDC.put("ClassName", "org.onap.appc.provider.AppcProviderClient");
93 LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
94 metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
96 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
99 * Set End time for Metrics Logger
101 endTime = System.currentTimeMillis();
102 duration = endTime - startTime;
103 durationStr = String.valueOf(duration);
104 endTimeStrUTC = df.format(new Date());
105 MDC.put("EndTimestamp", endTimeStrUTC);
106 MDC.put("ElapsedTime", durationStr);
108 LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
109 metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));