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.logging.LoggingConstants;
29 import org.onap.appc.logging.LoggingUtils;
30 import org.onap.appc.util.StringHelper;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
33 import org.osgi.framework.BundleContext;
34 import org.osgi.framework.FrameworkUtil;
35 import org.osgi.framework.ServiceReference;
38 import java.text.DateFormat;
39 import java.text.SimpleDateFormat;
40 import java.time.Instant;
41 import java.time.temporal.ChronoUnit;
42 import java.util.Date;
43 import java.util.Properties;
44 import java.util.TimeZone;
46 public class AppcProviderClient {
48 private final EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
49 private final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
51 private SvcLogicService svcLogic = null;
53 public AppcProviderClient() {
54 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
55 // Handle BundleContext returning null
57 LOG.warn("Cannot find bundle context for " + SvcLogicService.NAME);
59 // Get SvcLogicService reference
60 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
62 svcLogic = (SvcLogicService) bctx.getService(sref);
65 LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
71 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
72 LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
73 return (svcLogic.hasGraph(module, rpc, version, mode));
76 public Properties execute(String module, String rpc, String version, String mode, Properties parms)
77 throws SvcLogicException {
80 * Set properties for Metrics Logger
82 Date startTimestamp = new Date();
83 Instant startTimestampInstant = startTimestamp.toInstant();
84 String startTimeStr = LoggingUtils.generateTimestampStr(startTimestampInstant);
85 MDC.put(LoggingConstants.MDCKeys.TARGET_ENTITY, "sli");
86 MDC.put(LoggingConstants.MDCKeys.TARGET_SERVICE_NAME, "execute");
87 MDC.put(LoggingConstants.MDCKeys.CLASS_NAME, "org.onap.appc.provider.AppcProviderClient");
89 LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
90 metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
92 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
95 * Set End time for Metrics Logger
97 Date endTimestamp = new Date();
98 Instant endTimestampInstant = endTimestamp.toInstant();
99 String endTimeStr = LoggingUtils.generateTimestampStr(endTimestampInstant);
100 long duration = ChronoUnit.MILLIS.between(startTimestampInstant, endTimestampInstant);
101 String durationStr = String.valueOf(duration);
102 MDC.put(LoggingConstants.MDCKeys.BEGIN_TIMESTAMP, startTimeStr);
103 MDC.put(LoggingConstants.MDCKeys.END_TIMESTAMP, endTimeStr);
104 MDC.put(LoggingConstants.MDCKeys.ELAPSED_TIME, durationStr);
106 LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
107 metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));