2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.provider;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.onap.appc.logging.LoggingConstants;
31 import org.onap.appc.logging.LoggingUtils;
32 import org.onap.appc.util.StringHelper;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
37 import java.time.Instant;
38 import java.time.temporal.ChronoUnit;
39 import java.util.Date;
40 import java.util.Properties;
42 public class AppcProviderClient {
44 private final EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
45 private final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
47 private final SvcLogicService svcLogic;
49 public AppcProviderClient(final SvcLogicService svcLogicService) {
50 LOG.info("provider alert: appcprovider client init");
51 this.svcLogic = svcLogicService;
54 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
55 LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
56 return (svcLogic.hasGraph(module, rpc, version, mode));
59 public Properties execute(String module, String rpc, String version, String mode, Properties parms)
60 throws SvcLogicException {
63 * Set properties for Metrics Logger
65 Date startTimestamp = new Date();
66 Instant startTimestampInstant = startTimestamp.toInstant();
67 String startTimeStr = LoggingUtils.generateTimestampStr(startTimestampInstant);
68 MDC.put(LoggingConstants.MDCKeys.TARGET_ENTITY, "sli");
69 MDC.put(LoggingConstants.MDCKeys.TARGET_SERVICE_NAME, "execute");
70 MDC.put(LoggingConstants.MDCKeys.CLASS_NAME, "org.onap.appc.provider.AppcProviderClient");
72 LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
73 metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
75 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
78 * Set End time for Metrics Logger
80 Date endTimestamp = new Date();
81 Instant endTimestampInstant = endTimestamp.toInstant();
82 String endTimeStr = LoggingUtils.generateTimestampStr(endTimestampInstant);
83 long duration = ChronoUnit.MILLIS.between(startTimestampInstant, endTimestampInstant);
84 String durationStr = String.valueOf(duration);
85 MDC.put(LoggingConstants.MDCKeys.BEGIN_TIMESTAMP, startTimeStr);
86 MDC.put(LoggingConstants.MDCKeys.END_TIMESTAMP, endTimeStr);
87 MDC.put(LoggingConstants.MDCKeys.ELAPSED_TIME, durationStr);
89 LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
90 metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));