Improve logs in Policy methods.
Add info to the logs of the methods calling policy.
Issue-ID: CLAMP-85
Change-Id: I6213b380ba66a93be3a0c06d62781b1e4934544b
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
index 2e2169f..b4cad94 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -62,18 +62,18 @@
* Policy utility methods - specifically, send the policy.
*/
public class PolicyClient {
- protected static final String POLICY_PREFIX_BASE = "Config_";
- protected static final String LOG_POLICY_PREFIX = "Response is ";
+ protected static final String POLICY_PREFIX_BASE = "Config_";
+ protected static final String LOG_POLICY_PREFIX = "Response is ";
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyClient.class);
- protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- protected static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type";
- protected static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name";
+ protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ protected static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type";
+ protected static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name";
@Value("${org.onap.clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}")
- protected String cldsPolicyConfigFile;
+ protected String cldsPolicyConfigFile;
@Autowired
- protected ApplicationContext appContext;
+ protected ApplicationContext appContext;
@Autowired
- protected RefProp refProp;
+ protected RefProp refProp;
/**
* Perform BRMS policy type.
@@ -229,15 +229,19 @@
responseMessage = response.getResponseMessage();
}
} catch (Exception e) {
+ LoggingUtils.setResponseContext("900", "Policy send failed", this.getClass().getName());
+ LoggingUtils.setErrorContext("900", "Policy send error");
logger.error("Exception occurred during policy communication", e);
throw new PolicyClientException("Exception while communicating with Policy", e);
}
logger.info(LOG_POLICY_PREFIX + responseMessage);
LoggingUtils.setTimeContext(startTime, new Date());
if (response.getResponseCode() == 200) {
+ LoggingUtils.setResponseContext("0", "Policy send success", this.getClass().getName());
logger.info("Policy send successful");
metricsLogger.info("Policy send success");
} else {
+ LoggingUtils.setResponseContext("900", "Policy send failed", this.getClass().getName());
logger.warn("Policy send failed: " + responseMessage);
metricsLogger.info("Policy send failure");
throw new BadRequestException("Policy send failed: " + responseMessage);
@@ -274,20 +278,27 @@
PolicyChangeResponse response;
String responseMessage = "";
try {
+ LoggingUtils.setTargetContext("Policy", "pushPolicy");
logger.info("Attempting to push policy...");
response = getPolicyEngine().pushPolicy(pushPolicyParameters);
if (response != null) {
responseMessage = response.getResponseMessage();
}
} catch (Exception e) {
+ LoggingUtils.setResponseContext("900", "Policy push failed", this.getClass().getName());
+ LoggingUtils.setErrorContext("900", "Policy push error");
logger.error("Exception occurred during policy communication", e);
throw new PolicyClientException("Exception while communicating with Policy", e);
}
logger.info(LOG_POLICY_PREFIX + responseMessage);
if (response != null && (response.getResponseCode() == 200 || response.getResponseCode() == 204)) {
+ LoggingUtils.setResponseContext("0", "Policy push success", this.getClass().getName());
logger.info("Policy push successful");
+ metricsLogger.info("Policy push success");
} else {
+ LoggingUtils.setResponseContext("900", "Policy push failed", this.getClass().getName());
logger.warn("Policy push failed: " + responseMessage);
+ metricsLogger.info("Policy push failure");
throw new BadRequestException("Policy push failed: " + responseMessage);
}
return responseMessage;
@@ -331,6 +342,11 @@
return versions;
}
+ /**
+ * This method create a new policy engine.
+ *
+ * @return A new policy engine
+ */
private PolicyEngine getPolicyEngine() {
PolicyEngine policyEngine;
try {
@@ -383,6 +399,7 @@
*
* @param prop
* The ModelProperties
+ *
* @return The response message from policy
*/
protected String deletePolicy(ModelProperties prop, String policyType) {