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.openecomp.appc.provider;
27 import org.openecomp.appc.util.StringHelper;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import com.att.eelf.i18n.EELFResourceManager;
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 static com.att.eelf.configuration.Configuration.*;
40 import java.util.Properties;
41 import java.text.DateFormat;
42 import java.text.SimpleDateFormat;
43 import java.util.Date;
44 import java.util.TimeZone;
46 public class AppcProviderClient {
48 private static EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
49 private static 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);
60 // Get SvcLogicService reference
61 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
63 svcLogic = (SvcLogicService) bctx.getService(sref);
66 LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
72 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
73 LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
74 return (svcLogic.hasGraph(module, rpc, version, mode));
77 public Properties execute(String module, String rpc, String version, String mode, Properties parms)
78 throws SvcLogicException {
81 * Set End time for Metrics Logger
83 long startTime = System.currentTimeMillis();
84 TimeZone tz = TimeZone.getTimeZone("UTC");
85 DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
87 String startTimeStr = df.format(new Date());
88 long endTime = System.currentTimeMillis();
89 long duration = endTime - startTime;
90 String endTimeStr = String.valueOf(endTime);
91 String durationStr = String.valueOf(duration);
92 String endTimeStrUTC = df.format(new Date());
93 MDC.put("EndTimestamp", endTimeStrUTC);
94 MDC.put("ElapsedTime", durationStr);
95 MDC.put("TargetEntity", "sli");
96 MDC.put("TargetServiceName", "execute");
97 MDC.put("ClassName", "org.openecomp.appc.provider.AppcProviderClient");
99 LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
100 metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
102 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
105 * Set End time for Metrics Logger
107 endTime = System.currentTimeMillis();
108 duration = endTime - startTime;
109 endTimeStr = String.valueOf(endTime);
110 durationStr = String.valueOf(duration);
111 endTimeStrUTC = df.format(new Date());
112 MDC.put("EndTimestamp", endTimeStrUTC);
113 MDC.put("ElapsedTime", durationStr);
115 LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
116 metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));