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 final SvcLogicService svcLogic;
53 public AppcProviderClient(final SvcLogicService svcLogicService) {
54 LOG.info("provider alert: appcprovider client init");
55 this.svcLogic = svcLogicService;
58 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
59 LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
60 return (svcLogic.hasGraph(module, rpc, version, mode));
63 public Properties execute(String module, String rpc, String version, String mode, Properties parms)
64 throws SvcLogicException {
67 * Set properties for Metrics Logger
69 Date startTimestamp = new Date();
70 Instant startTimestampInstant = startTimestamp.toInstant();
71 String startTimeStr = LoggingUtils.generateTimestampStr(startTimestampInstant);
72 MDC.put(LoggingConstants.MDCKeys.TARGET_ENTITY, "sli");
73 MDC.put(LoggingConstants.MDCKeys.TARGET_SERVICE_NAME, "execute");
74 MDC.put(LoggingConstants.MDCKeys.CLASS_NAME, "org.onap.appc.provider.AppcProviderClient");
76 LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
77 metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
79 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
82 * Set End time for Metrics Logger
84 Date endTimestamp = new Date();
85 Instant endTimestampInstant = endTimestamp.toInstant();
86 String endTimeStr = LoggingUtils.generateTimestampStr(endTimestampInstant);
87 long duration = ChronoUnit.MILLIS.between(startTimestampInstant, endTimestampInstant);
88 String durationStr = String.valueOf(duration);
89 MDC.put(LoggingConstants.MDCKeys.BEGIN_TIMESTAMP, startTimeStr);
90 MDC.put(LoggingConstants.MDCKeys.END_TIMESTAMP, endTimeStr);
91 MDC.put(LoggingConstants.MDCKeys.ELAPSED_TIME, durationStr);
93 LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
94 metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));