aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/guard/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/guard/src/main/java')
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java17
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java11
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java8
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java9
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java26
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java6
6 files changed, 42 insertions, 35 deletions
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java
index 53e972941..6b311bf45 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java
@@ -63,19 +63,19 @@ public class CallGuardTask implements Runnable {
try {
request = RequestParser.parseRequest(xacmlReq);
} catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) {
- logger.error("CallGuardTask.run threw: ", e);
+ logger.error("CallGuardTask.run threw: {}", e);
}
- System.out.println("\n********** XACML REQUEST START ********");
- System.out.println(request);
- System.out.println("********** XACML REQUEST END ********\n");
+ logger.debug("\n********** XACML REQUEST START ********");
+ logger.debug("{}", request);
+ logger.debug("********** XACML REQUEST END ********\n");
com.att.research.xacml.api.Response xacmlResponse = PolicyGuardXacmlHelper.callPDP(embeddedPdpEngine, "", request, false);
- System.out.println("\n********** XACML RESPONSE START ********");
- System.out.println(xacmlResponse);
- System.out.println("********** XACML RESPONSE END ********\n");
+ logger.debug("\n********** XACML RESPONSE START ********");
+ logger.debug("{}", xacmlResponse);
+ logger.debug("********** XACML RESPONSE END ********\n");
PolicyGuardResponse guardResponse = PolicyGuardXacmlHelper.ParseXacmlPdpResponse(xacmlResponse);
@@ -88,7 +88,8 @@ public class CallGuardTask implements Runnable {
}
long estimatedTime = System.nanoTime() - startTime;
- System.out.println("\n\n============ Guard inserted with decision "+ guardResponse.result + " !!! =========== time took: " +(double)estimatedTime/1000/1000 +" mili sec \n\n");
+ logger.debug("\n\n============ Guard inserted with decision {} !!! =========== time took: {} mili sec \n\n",
+ guardResponse.result, (double)estimatedTime/1000/1000);
workingMemory.insert(guardResponse);
}
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java
index 67ac170db..9e8ed9db0 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java
@@ -134,7 +134,7 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
else{
//Notice, we are checking here for the base issuer prefix.
if (!string.contains(this.getIssuer())) {
- logger.debug("Requested issuer '{}' does not match {}", string, (this.getIssuer() == null ? "null" : "'" + this.getIssuer() + "'"));
+ logger.debug("Requested issuer '{}' does not match {}", string, getIssuer());
logger.debug("FeqLimiter PIP - Issuer {} does not match with: ", string, this.getIssuer());
return StdPIPResponse.PIP_RESPONSE_EMPTY;
}
@@ -187,11 +187,16 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
pipResponse = pipFinder.getMatchingAttributes(pipRequest, this);
if (pipResponse != null) {
if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) {
- logger.debug("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString());
+ logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString());
pipResponse = null;
}
if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) {
- logger.debug("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString());
+ logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString());
+ logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus());
+ pipResponse = null;
+ }
+ if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) {
+ logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus());
pipResponse = null;
}
}
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java
index b4aee2fda..fabc48511 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java
@@ -26,11 +26,13 @@ import java.util.UUID;
import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.guard.impl.PNFTargetLock;
import org.onap.policy.guard.impl.VMTargetLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PolicyGuard {
private static Map<String, TargetLock> activeLocks = new HashMap<String, TargetLock>();
-
+ private static final Logger logger = LoggerFactory.getLogger(PolicyGuard.class);
public static class LockResult<A, B> {
private A a;
private B b;
@@ -86,7 +88,7 @@ public class PolicyGuard {
//
// Return result
//
- System.out.println("Locking " + lock);
+ logger.debug("Locking {}", lock);
return LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock);
}
}
@@ -94,7 +96,7 @@ public class PolicyGuard {
public static boolean unlockTarget(TargetLock lock) {
synchronized(activeLocks) {
if (activeLocks.containsKey(lock.getTargetInstance())) {
- System.out.println("Unlocking " + lock);
+ logger.debug("Unlocking {}", lock);
return (activeLocks.remove(lock.getTargetInstance()) != null);
}
return false;
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java
index c0ed80086..dbaf711c4 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java
@@ -61,7 +61,7 @@ public class PolicyGuardXacmlHelper {
//
response = (com.att.research.xacml.api.Response) callRESTfulPDP(new ByteArrayInputStream(jsonString.getBytes()), new URL(restfulPdpUrl/*"https://localhost:8443/pdp/"*/));
} catch (Exception e) {
- System.err.println("Error in sending RESTful request: " + e);
+ logger.error("Error in sending RESTful request: ", e);
}
} else if(xacmlEmbeddedPdpEngine != null){
//
@@ -71,10 +71,10 @@ public class PolicyGuardXacmlHelper {
try {
response = (com.att.research.xacml.api.Response) xacmlEmbeddedPdpEngine.decide((com.att.research.xacml.api.Request) request);
} catch (PDPException e) {
- System.err.println(e);
+ logger.error(e.getMessage(), e);
}
long lTimeEnd = System.currentTimeMillis();
- System.out.println("Elapsed Time: " + (lTimeEnd - lTimeStart) + "ms");
+ logger.debug("Elapsed Time: {} ms", (lTimeEnd - lTimeStart));
}
return response;
}
@@ -178,16 +178,13 @@ public class PolicyGuardXacmlHelper {
while(it_attr.hasNext()){
Attribute current_attr = it_attr.next();
String s = current_attr.getAttributeId().stringValue();
- //System.out.println("ATTR ID = " + s);
if(s.equals("urn:oasis:names:tc:xacml:1.0:request:request-id")){
Iterator<AttributeValue<?>> it_values = current_attr.getValues().iterator();
req_id_from_xacml_response = UUID.fromString(it_values.next().getValue().toString());
- //System.out.println("UUID = " + req_id_from_xacml_response);
}
if(s.equals("urn:oasis:names:tc:xacml:1.0:operation:operation-id")){
Iterator<AttributeValue<?>> it_values = current_attr.getValues().iterator();
operation_from_xacml_response = it_values.next().getValue().toString();
- //System.out.println("OPERATION = " + operation_from_xacml_response);
}
}
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java
index 21584f0b5..72b723c1f 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java
@@ -42,12 +42,12 @@ public class PolicyGuardYamlToXacml {
public static void fromYamlToXacml(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput){
ControlLoopGuard yamlGuardObject = Util.loadYamlGuard(yamlFile);
- System.out.println("clname: " + yamlGuardObject.getGuards().getFirst().getMatch_parameters().getControlLoopName());
- System.out.println("actor: " + yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
- System.out.println("recipe: " + yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
- System.out.println("num: " + yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target());
- System.out.println("duration: " + yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window());
- System.out.println("time_in_range: " + yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range());
+ logger.debug("clname: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getControlLoopName());
+ logger.debug("actor: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
+ logger.debug("recipe: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
+ logger.debug("num: {}", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target());
+ logger.debug("duration: {}", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window());
+ logger.debug("time_in_range: {}", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range());
Path xacmlTemplatePath = Paths.get(xacmlTemplate);
String xacmlTemplateContent;
@@ -142,7 +142,7 @@ public class PolicyGuardYamlToXacml {
p = Pattern.compile("\\$\\{guardActiveEnd\\}");
m = p.matcher(xacmlFileContent);
xacmlFileContent = m.replaceAll(guardActiveEnd);
- System.out.println(xacmlFileContent);
+ logger.debug(xacmlFileContent);
return xacmlFileContent;
}
@@ -175,11 +175,11 @@ public class PolicyGuardYamlToXacml {
public static void fromYamlToXacmlBlacklist(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput){
ControlLoopGuard yamlGuardObject = Util.loadYamlGuard(yamlFile);
- System.out.println("actor: " + yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
- System.out.println("recipe: " + yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
- System.out.println("freq_limit_per_target: " + yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target());
- System.out.println("time_window: " + yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window());
- System.out.println("active_time_range: " + yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range());
+ logger.debug("actor: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
+ logger.debug("recipe: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
+ logger.debug("freq_limit_per_target: {}", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target());
+ logger.debug("time_window: {}", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window());
+ logger.debug("active_time_range: {}", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range());
Path xacmlTemplatePath = Paths.get(xacmlTemplate);
String xacmlTemplateContent;
@@ -236,7 +236,7 @@ public class PolicyGuardYamlToXacml {
p = Pattern.compile("\\$\\{guardActiveEnd\\}");
m = p.matcher(xacmlFileContent);
xacmlFileContent = m.replaceAll(guardActiveEnd);
- System.out.println(xacmlFileContent);
+ logger.debug(xacmlFileContent);
for(String target : blacklist){
p = Pattern.compile("\\$\\{blackListElement\\}");
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java
index 702f27ccb..6018c2cab 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java
@@ -35,10 +35,12 @@ import org.yaml.snakeyaml.constructor.Constructor;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class Util {
+ private static final Logger logger = LoggerFactory.getLogger(Util.class);
public static class Pair<A, B> {
public final A a;
public final B b;
@@ -59,7 +61,7 @@ public final class Util {
Object obj = yaml.load(contents);
//String ttt = ((ControlLoopPolicy)obj).policies.getFirst().payload.get("asdas");
- System.out.println(contents);
+ logger.debug(contents);
//for(Policy policy : ((ControlLoopPolicy)obj).policies){
return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);