diff options
author | Jorge Hernandez <jh1730@att.com> | 2017-06-22 17:17:28 -0500 |
---|---|---|
committer | Jorge Hernandez <jh1730@att.com> | 2017-06-22 17:17:28 -0500 |
commit | 8f61e18ef0457745719f05bd5c186992a7155416 (patch) | |
tree | 884f4653f957a88a65ea981727dfe26494fb7c55 /policy-management/src/main/java/org | |
parent | 3cc1a85a832771cb70ed9cbaab9031bc4a114308 (diff) |
[POLICY-30] remove problematic layers
add configurability through telemetry API
Change-Id: I77ebde12a417d421b98646c32dc74824f4494c2e
Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'policy-management/src/main/java/org')
11 files changed, 521 insertions, 469 deletions
diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java index d94e773c..276573eb 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java @@ -30,8 +30,8 @@ import org.openecomp.policy.drools.controller.internal.MavenDroolsController; import org.openecomp.policy.drools.controller.internal.NullDroolsController; import org.openecomp.policy.drools.event.comm.Topic; import org.openecomp.policy.drools.event.comm.Topic.CommInfrastructure; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.event.comm.TopicSource; import org.openecomp.policy.drools.event.comm.TopicSink; import org.openecomp.policy.drools.properties.PolicyProperties; @@ -140,11 +140,11 @@ public interface DroolsControllerFactory { * Factory of Drools Controllers indexed by the Maven coordinates */ class IndexedDroolsControllerFactory implements DroolsControllerFactory { - + /** * logger */ - private static Logger logger = FlexLogger.getLogger(MavenDroolsController.class); + private static Logger logger = LoggerFactory.getLogger(MavenDroolsController.class); /** * Policy Controller Name Index @@ -262,7 +262,8 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { try { customGsonCoder = new CustomGsonCoder(customGson); } catch (IllegalArgumentException e) { - e.printStackTrace(); + logger.warn("{}: cannot create custom-gson-coder {} because of {}", + this, customGson, e.getMessage(), e); } } @@ -276,7 +277,8 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { try { customJacksonCoder = new CustomJacksonCoder(customJackson); } catch (IllegalArgumentException e) { - e.printStackTrace(); + logger.warn("{}: cannot create custom-jackson-coder {} because of {}", + this, customJackson, e.getMessage(), e); } } @@ -537,4 +539,12 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { return controllers; } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IndexedDroolsControllerFactory [#droolsControllers=").append(droolsControllers.size()) + .append("]"); + return builder.toString(); + } + } diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java index e404a092..06d2aaf7 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java @@ -32,9 +32,8 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; import org.kie.api.runtime.rule.QueryResults; import org.kie.api.runtime.rule.QueryResultsRow; -import org.openecomp.policy.common.logging.eelf.MessageCodes; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.controller.DroolsController; import org.openecomp.policy.drools.core.PolicyContainer; import org.openecomp.policy.drools.core.PolicySession; @@ -61,7 +60,7 @@ public class MavenDroolsController implements DroolsController { /** * logger */ - private static Logger logger = FlexLogger.getLogger(MavenDroolsController.class); + private static Logger logger = LoggerFactory.getLogger(MavenDroolsController.class); /** * Policy Container, the access object to the policy-core layer @@ -423,16 +422,14 @@ public class MavenDroolsController implements DroolsController { * {@inheritDoc} */ @Override - public void shutdown() throws IllegalStateException { - - if (logger.isInfoEnabled()) - logger.info(this + "SHUTDOWN"); + public void shutdown() throws IllegalStateException { + logger.info("{}: SHUTDOWN", this); try { this.stop(); this.removeCoders(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "stop", this.toString()); + logger.error("{} SHUTDOWN FAILED because of {}", this, e.getMessage(), e); } finally { this.policyContainer.shutdown(); } @@ -445,14 +442,13 @@ public class MavenDroolsController implements DroolsController { */ @Override public void halt() throws IllegalStateException { - if (logger.isInfoEnabled()) - logger.info(this + "SHUTDOWN"); + logger.info("{}: HALT", this); try { this.stop(); this.removeCoders(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "halt", this.toString()); + logger.error("{} HALT FAILED because of {}", this, e.getMessage(), e); } finally { this.policyContainer.destroy(); } @@ -462,20 +458,18 @@ public class MavenDroolsController implements DroolsController { * removes this drools controllers and encoders and decoders from operation */ protected void removeCoders() { - - if (logger.isInfoEnabled()) - logger.info(this + "REMOVE-CODERS"); + logger.info("{}: REMOVE-CODERS", this); try { this.removeDecoders(); } catch (IllegalArgumentException e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "removeDecoders", this.toString()); + logger.error("{} REMOVE-DECODERS FAILED because of {}", this, e.getMessage(), e); } try { this.removeEncoders(); } catch (IllegalArgumentException e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "removeEncoders", this.toString()); + logger.error("{} REMOVE-ENCODERS FAILED because of {}", this, e.getMessage(), e); } } @@ -492,9 +486,7 @@ public class MavenDroolsController implements DroolsController { */ @Override public boolean offer(String topic, String event) { - - if (logger.isInfoEnabled()) - logger.info("OFFER: " + topic + ":" + event + " INTO " + this); + logger.debug("{}: OFFER: {} <- {}", this, topic, event); if (this.locked) return true; @@ -515,8 +507,8 @@ public class MavenDroolsController implements DroolsController { this.getArtifactId(), topic)) { - logger.warn("DECODING-UNSUPPORTED: " + ":" + this.getGroupId() + - ":" + this.getArtifactId() + ":" + topic + " IN " + this); + logger.warn("{}: DECODING-UNSUPPORTED {}:{}:{}", this, + topic, this.getGroupId(), this.getArtifactId()); return true; } @@ -529,12 +521,12 @@ public class MavenDroolsController implements DroolsController { topic, event); } catch (UnsupportedOperationException uoe) { - if (logger.isInfoEnabled()) - logger.info("DECODE:"+ this + ":" + topic + ":" + event); + logger.info("{}: DECODE FAILED: {} <- {} because of {}", this, topic, + event, uoe.getMessage(), uoe); return true; } catch (Exception e) { - e.printStackTrace(); - logger.error("DECODE:"+ this + ":" + topic + ":" + event); + logger.warn("{}: DECODE FAILED: {} <- {} because of {}", this, topic, + event, e.getMessage(), e); return true; } diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java b/policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java index 6bb1185d..dda20a08 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java @@ -28,10 +28,9 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Properties; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.policy.common.logging.eelf.MessageCodes; import org.openecomp.policy.drools.utils.PropertyUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public interface SystemPersistence { @@ -119,7 +118,7 @@ class SystemPropertiesPersistence implements SystemPersistence { /** * logger */ - private static Logger logger = FlexLogger.getLogger(SystemPropertiesPersistence.class); + private static Logger logger = LoggerFactory.getLogger(SystemPropertiesPersistence.class); /** * backs up the properties-based controller configuration @@ -142,8 +141,7 @@ class SystemPropertiesPersistence implements SystemPersistence { Files.copy(controllerPropertiesPath, controllerPropertiesBakPath, StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, "SystemPersistenceProperties"); + logger.warn("{}: cannot be backed up", controllerName, e); return false; } } @@ -178,7 +176,7 @@ class SystemPropertiesPersistence implements SystemPersistence { this.backupController(controllerName); } } catch (Exception e) { - logger.info("No existing Properties"); + logger.info("{}: no existing Properties", controllerName); // continue } } @@ -188,8 +186,7 @@ class SystemPropertiesPersistence implements SystemPersistence { FileWriter writer = new FileWriter(controllerPropertiesFile); properties.store(writer, "Machine created Policy Controller Configuration"); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, "SystemPersistenceProperties"); + logger.warn("{}: cannot be STORED", controllerName, e); return false; } @@ -217,8 +214,7 @@ class SystemPropertiesPersistence implements SystemPersistence { controllerPropertiesBakPath, StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, "SystemPersistenceProperties"); + logger.warn("{}: cannot be DELETED", controllerName, e); return false; } } @@ -243,10 +239,7 @@ class SystemPropertiesPersistence implements SystemPersistence { try { return PropertyUtil.getProperties(propertiesPath.toFile()); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - name, "SystemPersistenceProperties can't retrieved properties for " + - propertiesPath); - e.printStackTrace(); + logger.warn("{}: can't read properties @ {}", name, propertiesPath); throw new IllegalArgumentException("can't read properties for " + name + " @ " + propertiesPath); diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java index d82b3724..1030186b 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java @@ -26,14 +26,13 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.openecomp.policy.common.logging.eelf.MessageCodes; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.drools.controller.DroolsController; import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; import org.openecomp.policy.drools.utils.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Coder (Encoder/Decoder) of Events. @@ -399,8 +398,11 @@ public interface EventProtocolCoder { * class and best fitted json parsing tools. */ class MultiplexorEventProtocolCoder implements EventProtocolCoder { - // get an instance of logger - private static Logger logger = FlexLogger.getLogger(MultiplexorEventProtocolCoder.class); + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(MultiplexorEventProtocolCoder.class); + /** * Decoders */ @@ -423,11 +425,10 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { CustomJacksonCoder customJacksonCoder, int modelClassLoaderHash) throws IllegalArgumentException { - logger.info("ADD-DECODER: " + groupId + ":" + artifactId + ":" + - topic + ":" + eventClass + ":" + - protocolFilter + ":" + customGsonCoder + - ":" + customJacksonCoder + ":" + modelClassLoaderHash + - " INTO " + this); + logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this, + groupId, artifactId, topic, eventClass, + protocolFilter, customGsonCoder, customJacksonCoder, + modelClassLoaderHash); this.decoders.add(groupId, artifactId, topic, eventClass, protocolFilter, customGsonCoder, customJacksonCoder, modelClassLoaderHash); } @@ -443,11 +444,10 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { CustomJacksonCoder customJacksonCoder, int modelClassLoaderHash) throws IllegalArgumentException { - logger.info("ADD-ENCODER: " + groupId + ":" + artifactId + ":" + - topic + ":" + eventClass + ":" + - protocolFilter + ":" + customGsonCoder + - ":" + customJacksonCoder + ":" + modelClassLoaderHash + - " INTO " + this); + logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this, + groupId, artifactId, topic, eventClass, + protocolFilter, customGsonCoder, customJacksonCoder, + modelClassLoaderHash); this.encoders.add(groupId, artifactId, topic, eventClass, protocolFilter, customGsonCoder, customJacksonCoder, modelClassLoaderHash); } @@ -458,8 +458,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public void removeDecoders(String groupId, String artifactId, String topic) throws IllegalArgumentException { - logger.info("REMOVE-DECODER: " + groupId + ":" + artifactId + ":" + - topic + " FROM " + this); + logger.info("{}: remove-decoder {}:{}:{}", this, groupId, artifactId, topic); this.decoders.remove(groupId, artifactId, topic); } @@ -469,8 +468,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public void removeEncoders(String groupId, String artifactId, String topic) throws IllegalArgumentException { - logger.info("REMOVE-ENCODER: " + groupId + ":" + artifactId + ":" + - topic + " FROM " + this); + logger.info("{}: remove-encoder {}:{}:{}", this, groupId, artifactId, topic); this.encoders.remove(groupId, artifactId, topic); } @@ -496,8 +494,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public Object decode(String groupId, String artifactId, String topic, String json) throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { - logger.info("DECODE: " + groupId + ":" + artifactId + ":" + - topic + ":" + json + " WITH " + this); + logger.debug("{}: decode {}:{}:{}:{}", this, groupId, artifactId, topic, json); return this.decoders.decode(groupId, artifactId, topic, json); } @@ -507,8 +504,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public String encode(String groupId, String artifactId, String topic, Object event) throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { - logger.info("ENCODE: " + groupId + ":" + artifactId + ":" + - topic + ":" + event + " WITH " + this); + logger.debug("{}: encode {}:{}:{}:{}", this, groupId, artifactId, topic, event); return this.encoders.encode(groupId, artifactId, topic, event); } @@ -518,7 +514,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public String encode(String topic, Object event) throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { - logger.info("ENCODE: " + topic + ":" + event + " WITH " + this); + logger.debug("{}: encode {}:{}", this, topic, event); return this.encoders.encode(topic, event); } @@ -528,7 +524,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public String encode(String topic, Object event, DroolsController droolsController) throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { - logger.info("ENCODE: " + topic + ":" + event + ":" + droolsController + " WITH " + this); + logger.debug("{}: encode {}:{}:{}", this, topic, event, droolsController); return this.encoders.encode(topic, event, droolsController); } @@ -537,8 +533,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { */ @Override public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic) - throws IllegalArgumentException { - + throws IllegalArgumentException { return this.decoders.getFilters(groupId, artifactId, topic); } @@ -547,8 +542,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { */ @Override public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) - throws IllegalArgumentException { - + throws IllegalArgumentException { Pair<ProtocolCoderToolset,ProtocolCoderToolset> decoderToolsets = this.decoders.getCoders(groupId, artifactId, topic); if (decoderToolsets == null) throw new IllegalArgumentException("Decoders not found for " + groupId + ":" + artifactId + ":" + topic); @@ -561,8 +555,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { */ @Override public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic) - throws IllegalArgumentException { - + throws IllegalArgumentException { return this.encoders.getFilters(groupId, artifactId, topic); } @@ -571,8 +564,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { */ @Override public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) - throws IllegalArgumentException { - + throws IllegalArgumentException { return this.decoders.getFilters(groupId, artifactId, topic, classname); } @@ -581,8 +573,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { */ @Override public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) - throws IllegalArgumentException { - + throws IllegalArgumentException { return this.encoders.getFilters(groupId, artifactId, topic, classname); } @@ -669,7 +660,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * class and best fitted json parsing tools. */ abstract class GenericEventProtocolCoder { - private static Logger logger = FlexLogger.getLogger(GenericEventProtocolCoder.class); + private static Logger logger = LoggerFactory.getLogger(GenericEventProtocolCoder.class); /** * Mapping topic:controller-id -> <protocol-decoder-toolset-pair> @@ -717,13 +708,11 @@ abstract class GenericEventProtocolCoder { throw new IllegalArgumentException("Invalid group id"); } - if (artifactId == null || artifactId.isEmpty()) { + if (artifactId == null || artifactId.isEmpty()) throw new IllegalArgumentException("Invalid artifact id"); - } - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Invalid Topic"); - } if (eventClass == null) { throw new IllegalArgumentException("Invalid Event Class"); @@ -736,16 +725,14 @@ abstract class GenericEventProtocolCoder { if (coders.containsKey(key)) { Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolsets = coders.get(key); - if (logger.isInfoEnabled()) - logger.info("ADDING CODER TO EXISTING: " + toolsets + " for " + key); + logger.info("{}: adding coders for existing {}: ", this, key, toolsets.first()); toolsets.first().addCoder(eventClass, protocolFilter, modelClassLoaderHash); toolsets.second().addCoder(eventClass, protocolFilter, modelClassLoaderHash); if (!reverseCoders.containsKey(reverseKey)) { - if (logger.isInfoEnabled()) - logger.info("Multiple coder classes case: " + toolsets.first() + - " for " + reverseKey + " - " + key); + logger.info("{}: adding new reverse coders (multiple classes case) for {}:{}: {}", + this, reverseKey, key, toolsets.first()); List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> reverseMappings = new ArrayList<Pair<ProtocolCoderToolset,ProtocolCoderToolset>>(); @@ -783,8 +770,7 @@ abstract class GenericEventProtocolCoder { new Pair<ProtocolCoderToolset,ProtocolCoderToolset>(gsonCoderTools, jacksonCoderTools); - logger.info("ADDED TOOLSET: " + key + " : " + - coderTools + ":" + this); + logger.info("{}: adding coders for new {}: {}", this, key, coderTools.first()); coders.put(key, coderTools); @@ -800,24 +786,24 @@ abstract class GenericEventProtocolCoder { present = parserSet.first().getControllerId().equals(key); if (present) { /* anomaly */ - logger.error("UNEXPECTED TOOLSET REVERSE MAPPING FOUND: " + parserSet.first() + - " for " + reverseKey + " - " + key); + logger.error("{}: unexpected toolset reverse mapping found for {}:{}: {}", + this, reverseKey, key, parserSet.first()); } } if (present) { return; } else { - logger.info("ADDING TOOLSET REVERSE MAPPING: " + reverseKey + " : " + - toolsets + ":" + coderTools + ":" + this); + logger.info("{}: adding coder set for {}: {} ", this, + reverseKey, coderTools.getFirst()); toolsets.add(coderTools); } } else { List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> toolsets = new ArrayList<Pair<ProtocolCoderToolset,ProtocolCoderToolset>>(); - logger.info("ADDING TOOLSET REVERSE MAPPING: " + reverseKey + " : " + - toolsets + ":" + coderTools + ":" + this); toolsets.add(coderTools); + + logger.info("{}: adding toolset for reverse key {}: {}", this, reverseKey, toolsets); reverseCoders.put(reverseKey, toolsets); } @@ -858,25 +844,22 @@ abstract class GenericEventProtocolCoder { public void remove(String groupId, String artifactId, String topic) throws IllegalArgumentException { - if (groupId == null || groupId.isEmpty()) { + if (groupId == null || groupId.isEmpty()) throw new IllegalArgumentException("Invalid group id"); - } - if (artifactId == null || artifactId.isEmpty()) { + if (artifactId == null || artifactId.isEmpty()) throw new IllegalArgumentException("Invalid artifact id"); - } - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Invalid Topic"); - } String key = this.codersKey(groupId, artifactId, topic); synchronized(this) { if (coders.containsKey(key)) { Pair<ProtocolCoderToolset, ProtocolCoderToolset> p = coders.remove(key); - logger.info("REMOVED TOOLSET: " + key + " : " + p + " FROM " + - coders + " : " + this); + + logger.info("{}: removed toolset for {}: {}", this, key, p.getFirst()); for (CoderFilters codeFilter : p.first().getCoders()) { String className = codeFilter.getCodedClass(); @@ -889,15 +872,14 @@ abstract class GenericEventProtocolCoder { while (toolsetsIter.hasNext()) { Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolset = toolsetsIter.next(); if (toolset.first().getControllerId().equals(key)) { - logger.info("REMOVED CODER FROM REVERSE MAPPING of TOOLSET: " + reverseKey + " : " + toolset + " FROM " + - reverseCoders); + logger.info("{}: removed coder from toolset for {} from reverse mapping {}: ", + this, reverseKey); toolsetsIter.remove(); } } if (this.reverseCoders.get(reverseKey).isEmpty()) { - logger.info("REMOVE FULL REVERSE MAPPING of TOOLSET: " + reverseKey + " FROM " + - reverseCoders); + logger.info("{}: removing reverse mapping for {}: ", this, reverseKey); this.reverseCoders.remove(reverseKey); } } @@ -916,16 +898,14 @@ abstract class GenericEventProtocolCoder { */ public boolean isCodingSupported(String groupId, String artifactId, String topic) { - if (groupId == null || groupId.isEmpty()) { + if (groupId == null || groupId.isEmpty()) throw new IllegalArgumentException("Invalid group id"); - } - if (artifactId == null || artifactId.isEmpty()) { + if (artifactId == null || artifactId.isEmpty()) throw new IllegalArgumentException("Invalid artifact id"); - } if (topic == null || topic.isEmpty()) - return false; + throw new IllegalArgumentException("Invalid Topic"); String key = this.codersKey(groupId, artifactId, topic); synchronized(this) { @@ -947,9 +927,8 @@ abstract class GenericEventProtocolCoder { public Object decode(String groupId, String artifactId, String topic, String json) throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { - if (!isCodingSupported(groupId, artifactId, topic)) { + if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic) + " for encoding"); - } String key = this.codersKey(groupId, artifactId, topic); Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key); @@ -958,8 +937,7 @@ abstract class GenericEventProtocolCoder { if (event != null) return event; } catch (Exception e) { - // TODO Auto-generated catch block - logger.warn("Can't decode @ " + this); + logger.info("{}, cannot decode {}", this, json, e); } if (multipleToolsetRetries) { @@ -977,10 +955,8 @@ abstract class GenericEventProtocolCoder { return event; } - } catch (Exception e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); - throw new UnsupportedOperationException(e2); + } catch (Exception e) { + throw new UnsupportedOperationException(e); } } @@ -1001,14 +977,12 @@ abstract class GenericEventProtocolCoder { public String encode(String groupId, String artifactId, String topic, Object event) throws IllegalArgumentException, UnsupportedOperationException { - if (!isCodingSupported(groupId, artifactId, topic)) { + if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException ("Unsupported:" + codersKey(groupId, artifactId, topic)); - } - if (event == null) { + if (event == null) throw new IllegalArgumentException("Unsupported topic:" + topic); - } // reuse the decoder set, since there must be affinity in the model String key = this.codersKey(groupId, artifactId, topic); @@ -1027,7 +1001,7 @@ abstract class GenericEventProtocolCoder { protected String encodeInternal(String key, Object event) throws IllegalArgumentException, UnsupportedOperationException { - logger.debug("ENCODE: " + key + ":" + event + this); + logger.debug("{}: encode for {}: {}", this, key, event); Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key); try { @@ -1035,8 +1009,7 @@ abstract class GenericEventProtocolCoder { if (json != null && !json.isEmpty()) return json; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "FIRST-ENCODE-INTERNAL: " + - key + ":" + event, this.toString()); + logger.warn("{}: cannot encode (first) for {}: {}", this, key, event, e); } if (multipleToolsetRetries) { @@ -1054,11 +1027,9 @@ abstract class GenericEventProtocolCoder { return json; } - } catch (Exception e2) { - // TODO Auto-generated catch block - logger.error(MessageCodes.EXCEPTION_ERROR, e2, "SECOND-ENCODE-INTERNAL: " + - key + ":" + event, this.toString()); - throw new UnsupportedOperationException(e2); + } catch (Exception e) { + logger.error("{}: cannot encode (second) for {}: {}", this, key, event, e); + throw new UnsupportedOperationException(e); } } @@ -1069,46 +1040,33 @@ abstract class GenericEventProtocolCoder { * encode an object into a json string * * @param topic topic - * @param encodedClass object to convert to string + * @param event object to convert to string * @return the json string * @throws IllegalArgumentException if invalid argument is provided * @throws UnsupportedOperationException if the operation cannot be performed */ - public String encode(String topic, Object encodedClass) + public String encode(String topic, Object event) throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { - if (encodedClass == null) { + if (event == null) throw new IllegalArgumentException("Invalid encoded class"); - } - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Invalid topic"); - } - - logger.info("ENCODE: " + topic + ":" + - encodedClass.getClass().getCanonicalName() + ":" + - encodedClass); - List<DroolsController> droolsControllers = droolsCreators(topic, encodedClass); + List<DroolsController> droolsControllers = droolsCreators(topic, event); - if (droolsControllers.isEmpty()) { - if (logger.isWarnEnabled()) - logger.warn("No Drool Controllers for: " + topic + ":" + - encodedClass.getClass().getCanonicalName() + ":" + - droolsControllers + " IN " + this); - throw new IllegalArgumentException("Invalid Topic: " + topic); - } + if (droolsControllers.isEmpty()) + throw new IllegalArgumentException("no drools controller has been found"); if (droolsControllers.size() > 1) { - if (logger.isWarnEnabled()) - logger.warn("MULTIPLE DROOLS CONTROLLERS FOUND for: " + topic + ":" + - encodedClass.getClass().getCanonicalName() + ":" + - droolsControllers + " IN " + this); + logger.warn("{}: multiple drools-controller {} for {}:{} ", this, topic, + droolsControllers, event.getClass().getCanonicalName()); // continue } String key = codersKey(droolsControllers.get(0).getGroupId(), droolsControllers.get(0).getArtifactId(), topic); - return this.encodeInternal(key, encodedClass); + return this.encodeInternal(key, event); } /** @@ -1123,17 +1081,11 @@ abstract class GenericEventProtocolCoder { public String encode(String topic, Object encodedClass, DroolsController droolsController) throws IllegalArgumentException, IllegalArgumentException, UnsupportedOperationException { - if (encodedClass == null) { + if (encodedClass == null) throw new IllegalArgumentException("Invalid encoded class"); - } - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Invalid topic"); - } - - logger.info("ENCODE: " + topic + ":" + - encodedClass.getClass().getCanonicalName() + ":" + - encodedClass + ":" + droolsController); String key = codersKey(droolsController.getGroupId(), droolsController.getArtifactId(), topic); return this.encodeInternal(key, encodedClass); @@ -1154,9 +1106,7 @@ abstract class GenericEventProtocolCoder { String reverseKey = this.reverseCodersKey(topic, encodedClass.getClass().getCanonicalName()); if (!this.reverseCoders.containsKey(reverseKey)) { - logger.warn("NO MAPPING for REVERSE KEY: " + topic + ":" + - encodedClass.getClass().getCanonicalName() + ":" + - encodedClass + ":" + reverseKey + " : " + this); + logger.warn("{}: no reverse mapping for {}", this, reverseKey); return droolsControllers; } @@ -1169,13 +1119,9 @@ abstract class GenericEventProtocolCoder { // but there should be no side-effects. Ownership is crosscheck against classname and // classloader reference. - if (toolsets == null || toolsets.isEmpty()) { - logger.warn("ENCODE: " + topic + ":" + - encodedClass.getClass().getCanonicalName() + ":" + - encodedClass + " ENCODER NOT FOUND"); + if (toolsets == null || toolsets.isEmpty()) throw new IllegalStateException("No Encoders toolsets available for topic "+ topic + " encoder " + encodedClass.getClass().getCanonicalName()); - } for (Pair<ProtocolCoderToolset, ProtocolCoderToolset> encoderSet : toolsets) { // figure out the right toolset @@ -1193,10 +1139,10 @@ abstract class GenericEventProtocolCoder { } } - if (droolsControllers.isEmpty()) { - throw new IllegalStateException("No Encoders toolsets available for topic "+ topic + - " : encoder " + encodedClass.getClass().getCanonicalName()); - } + if (droolsControllers.isEmpty()) + throw new IllegalStateException("No Encoders toolsets available for "+ topic + + ":" + encodedClass.getClass().getCanonicalName()); + return droolsControllers; } @@ -1213,9 +1159,8 @@ abstract class GenericEventProtocolCoder { public List<CoderFilters> getFilters(String groupId, String artifactId, String topic) throws IllegalArgumentException { - if (!isCodingSupported(groupId, artifactId, topic)) { + if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); - } String key = this.codersKey(groupId, artifactId, topic); Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key); @@ -1234,9 +1179,8 @@ abstract class GenericEventProtocolCoder { public Pair<ProtocolCoderToolset,ProtocolCoderToolset> getCoders(String groupId, String artifactId, String topic) throws IllegalArgumentException { - if (!isCodingSupported(groupId, artifactId, topic)) { + if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); - } String key = this.codersKey(groupId, artifactId, topic); Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key); @@ -1254,13 +1198,11 @@ abstract class GenericEventProtocolCoder { public List<CoderFilters> getFilters(String groupId, String artifactId) throws IllegalArgumentException { - if (groupId == null || groupId.isEmpty()) { + if (groupId == null || groupId.isEmpty()) throw new IllegalArgumentException("Invalid group id"); - } - if (artifactId == null || artifactId.isEmpty()) { + if (artifactId == null || artifactId.isEmpty()) throw new IllegalArgumentException("Invalid artifact id"); - } String key = this.codersKey(groupId, artifactId, ""); @@ -1285,13 +1227,11 @@ abstract class GenericEventProtocolCoder { public List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> getCoders(String groupId, String artifactId) throws IllegalArgumentException { - if (groupId == null || groupId.isEmpty()) { + if (groupId == null || groupId.isEmpty()) throw new IllegalArgumentException("Invalid group id"); - } - if (artifactId == null || artifactId.isEmpty()) { + if (artifactId == null || artifactId.isEmpty()) throw new IllegalArgumentException("Invalid artifact id"); - } String key = this.codersKey(groupId, artifactId, ""); @@ -1319,13 +1259,11 @@ abstract class GenericEventProtocolCoder { public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) throws IllegalArgumentException { - if (!isCodingSupported(groupId, artifactId, topic)) { + if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); - } - if (classname == null || classname.isEmpty()) { + if (classname == null || classname.isEmpty()) throw new IllegalArgumentException("classname must be provided"); - } String key = this.codersKey(groupId, artifactId, topic); Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key); @@ -1343,13 +1281,11 @@ abstract class GenericEventProtocolCoder { public List<CoderFilters> getReverseFilters(String topic, String codedClass) throws IllegalArgumentException { - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Unsupported"); - } - if (codedClass == null) { + if (codedClass == null) throw new IllegalArgumentException("class must be provided"); - } String key = this.reverseCodersKey(topic, codedClass); List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> toolsets = this.reverseCoders.get(key); @@ -1376,28 +1312,20 @@ abstract class GenericEventProtocolCoder { DroolsController getDroolsController(String topic, Object fact) throws IllegalArgumentException { - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Unsupported"); - } - if (fact == null) { + if (fact == null) throw new IllegalArgumentException("class must be provided"); - } List<DroolsController> droolsControllers = droolsCreators(topic, fact); - if (droolsControllers.isEmpty()) { - if (logger.isWarnEnabled()) - logger.warn("No Drool Controllers for: " + topic + ":" + - fact.getClass().getCanonicalName() + ":" + - droolsControllers + " IN " + this); + if (droolsControllers.isEmpty()) throw new IllegalArgumentException("Invalid Topic: " + topic); - } if (droolsControllers.size() > 1) { - logger.warn("MULTIPLE DROOLS CONTROLLERS FOUND for: " + topic + ":" + - fact.getClass().getCanonicalName() + ":" + - droolsControllers + " IN " + this); + logger.warn("{}: multiple drools-controller {} for {}:{} ", this, + droolsControllers, topic, fact.getClass().getCanonicalName()); // continue } return droolsControllers.get(0); @@ -1414,20 +1342,17 @@ abstract class GenericEventProtocolCoder { List<DroolsController> getDroolsControllers(String topic, Object fact) throws IllegalArgumentException { - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Unsupported"); - } - if (fact == null) { + if (fact == null) throw new IllegalArgumentException("class must be provided"); - } List<DroolsController> droolsControllers = droolsCreators(topic, fact); if (droolsControllers.size() > 1) { // unexpected - logger.warn("MULTIPLE DROOLS CONTROLLERS FOUND for: " + topic + ":" + - fact.getClass().getCanonicalName() + ":" + - droolsControllers + " IN " + this); + logger.warn("{}: multiple drools-controller {} for {}:{} ", this, + droolsControllers, topic, fact.getClass().getCanonicalName()); // continue } return droolsControllers; diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java index a2ce3123..d6146a30 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; import org.openecomp.policy.drools.utils.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -36,6 +38,11 @@ import com.google.gson.JsonParser; public class JsonProtocolFilter { /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(JsonProtocolFilter.class); + + /** * Helper class to collect Filter information */ public static class FilterRule { @@ -130,7 +137,6 @@ public class JsonProtocolFilter { List<FilterRule> filters = new ArrayList<FilterRule>(); for (Pair<String, String> filterPair: rawFilters) { if (filterPair.first() == null || filterPair.first().isEmpty()) { - // TODO: warn continue; } @@ -211,8 +217,6 @@ public class JsonProtocolFilter { } return true; } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); throw new IllegalArgumentException(e); } } @@ -244,8 +248,8 @@ public class JsonProtocolFilter { } catch (IllegalArgumentException ile) { throw ile; } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.info("{}: cannot accept {} because of {}", + this, json, e.getMessage(), e); throw new IllegalArgumentException(e); } } diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java index 2d24d7a6..fb3f95d3 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java @@ -21,7 +21,6 @@ package org.openecomp.policy.drools.protocol.coders; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.time.Instant; @@ -31,14 +30,13 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.openecomp.policy.common.logging.eelf.MessageCodes; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.drools.controller.DroolsController; import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder; import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonProcessingException; @@ -62,6 +60,11 @@ import com.google.gson.JsonSerializer; public abstract class ProtocolCoderToolset { /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(ProtocolCoderToolset.class); + + /** * topic */ protected final String topic; @@ -274,8 +277,6 @@ public abstract class ProtocolCoderToolset { try { event = this.filteringParser.parse(json); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); throw new UnsupportedOperationException(e); } @@ -286,8 +287,9 @@ public abstract class ProtocolCoderToolset { return decoder; } } catch (Exception e) { - // TODO: handle exception - e.printStackTrace(); + logger.info("{}: unexpected failure accepting {} because of {}", + this, event, e.getMessage(), e); + // continue } } @@ -331,7 +333,7 @@ public abstract class ProtocolCoderToolset { * Tools used for encoding/decoding using Jackson */ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { - private static Logger logger = FlexLogger.getLogger(JacksonProtocolCoderToolset.class); + private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class); /** * decoder */ @@ -396,16 +398,14 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { DroolsController droolsController = DroolsController.factory.get(groupId, artifactId, ""); if (droolsController == null) { - String error = "NO-DROOLS-CONTROLLER for: " + json + " IN " + this; - logger.warn(error); - throw new IllegalStateException(error); + logger.warn("{}: no drools-controller to process {}", this, json); + throw new IllegalStateException("no drools-controller to process event"); } CoderFilters decoderFilter = filter(json); if (decoderFilter == null) { - String error = "NO-DECODER for: " + json + " IN " + this; - logger.warn(error); - throw new UnsupportedOperationException(error); + logger.debug("{}: no decoder to process {}", this, json); + throw new UnsupportedOperationException("no decoder to process event"); } Class<?> decoderClass; @@ -413,14 +413,13 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); if (decoderClass == null) { - String error = "DECODE-ERROR FETCHING MODEL CLASS: " + ":" + json + ":" + this; - logger.error(error); - throw new IllegalStateException(error); + logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass()); + throw new IllegalStateException("cannot fetch application class " + decoderFilter.getCodedClass()); } } catch (Exception e) { - String error = "DECODE-ERROR FETCHING MODEL CLASS: "+ e.getMessage() + ":" + json + ":" + this; - logger.warn(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + logger.warn("{}: cannot fetch application class {} because of {}", this, + decoderFilter.getCodedClass(), e.getMessage()); + throw new UnsupportedOperationException("cannot fetch application class " + decoderFilter.getCodedClass(), e); } @@ -428,9 +427,9 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { Object fact = this.decoder.readValue(json, decoderClass); return fact; } catch (Exception e) { - String error = "DECODE-ERROR FROM PDP-D FRAMEWORK: "+ json + ":" + e.getMessage() + ":" + this; - logger.error(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + logger.warn("{} cannot decode {} into {} because of {}", + this, json, decoderClass.getName(), e.getMessage(), e); + throw new UnsupportedOperationException("cannont decode into " + decoderFilter.getCodedClass(), e); } } @@ -452,9 +451,8 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { String encodedEvent = this.encoder.writeValueAsString(event); return encodedEvent; } catch (JsonProcessingException e) { - String error = "ENCODE-ERROR: "+ event + " IN " + this; - logger.error(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e); + throw new UnsupportedOperationException("event cannot be encoded"); } } @@ -472,7 +470,11 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { */ class GsonProtocolCoderToolset extends ProtocolCoderToolset { - private static Logger logger = FlexLogger.getLogger(GsonProtocolCoderToolset.class); + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class); + /** * Formatter for JSON encoding/decoding */ @@ -493,7 +495,8 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { try { return ZonedDateTime.parse(element.getAsString(), format); } catch (Exception e) { - System.err.println(e); + logger.info("GsonUTCAdapter: cannot parse {} because of {}", + element, e.getMessage(), e); } return null; } @@ -577,16 +580,14 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { DroolsController droolsController = DroolsController.factory.get(groupId, artifactId, ""); if (droolsController == null) { - String error = "NO-DROOLS-CONTROLLER for: " + json + " IN " + this; - logger.warn(error); - throw new IllegalStateException(error); + logger.warn("{}: no drools-controller to process {}", this, json); + throw new IllegalStateException("no drools-controller to process event"); } CoderFilters decoderFilter = filter(json); if (decoderFilter == null) { - String error = "NO-DECODER for: " + json + " IN " + this; - logger.warn(error); - throw new UnsupportedOperationException(error); + logger.debug("{}: no decoder to process {}", this, json); + throw new UnsupportedOperationException("no decoder to process event"); } Class<?> decoderClass; @@ -594,14 +595,13 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); if (decoderClass == null) { - String error = "DECODE-ERROR FETCHING MODEL CLASS: " + ":" + json + ":" + this; - logger.error(error); - throw new IllegalStateException(error); + logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass()); + throw new IllegalStateException("cannot fetch application class " + decoderFilter.getCodedClass()); } } catch (Exception e) { - String error = "DECODE-ERROR FETCHING MODEL CLASS: "+ e.getMessage() + ":" + json + ":" + this; - logger.warn(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + logger.warn("{}: cannot fetch application class {} because of {}", this, + decoderFilter.getCodedClass(), e.getMessage()); + throw new UnsupportedOperationException("cannot fetch application class " + decoderFilter.getCodedClass(), e); } if (this.customCoder != null) { @@ -615,20 +615,19 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { ("fromJson", new Class[]{String.class, Class.class}); Object fact = fromJsonMethod.invoke(gsonObject, json, decoderClass); return fact; - } catch (NoSuchFieldException | SecurityException | IllegalAccessException | - NoSuchMethodException | InvocationTargetException e) { - String error = "DECODE-ERROR-FROM-CUSTOM-CODER: " + e.getMessage() + ":" + json + ":" + this; - logger.error(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + } catch (Exception e) { + logger.warn("{}: cannot fetch application class {} because of {}", this, + decoderFilter.getCodedClass(), e.getMessage()); + throw new UnsupportedOperationException("cannot fetch application class " + decoderFilter.getCodedClass(), e); } } else { try { Object fact = this.decoder.fromJson(json, decoderClass); return fact; } catch (Exception e) { - String error = "DECODE-ERROR FROM PDP-D FRAMEWORK: "+ json + ":" + e.getMessage() + ":" + this; - logger.error(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + logger.warn("{} cannot decode {} into {} because of {}", + this, json, decoderClass.getName(), e.getMessage(), e); + throw new UnsupportedOperationException("cannont decode into " + decoderFilter.getCodedClass(), e); } } } @@ -645,9 +644,11 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { DroolsController droolsController = DroolsController.factory.get(groupId, artifactId, ""); if (droolsController == null) { - String error = "NO-DROOLS-CONTROLLER for: " + event + " IN " + this; - logger.warn(error); - throw new IllegalStateException(error); + logger.info("{}: no drools-controller to process {} (continue)", this, event); + if (this.customCoder != null) { + logger.warn("{}: no drools-controller to process {}", this, event); + throw new IllegalStateException("custom-coder but no drools-controller"); + } } if (this.customCoder != null) { @@ -661,20 +662,17 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { ("toJson", new Class[]{Object.class}); String encodedJson = (String) toJsonMethod.invoke(gsonObject, event); return encodedJson; - } catch (NoSuchFieldException | SecurityException | IllegalAccessException | - NoSuchMethodException | InvocationTargetException e) { - String error = "DECODE-ERROR-FROM-CUSTOM-CODER: " + e.getMessage() + ":" + event + ":" + this; - logger.error(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + } catch (Exception e) { + logger.warn("{} cannot custom-encode {} because of {}", this, event, e.getMessage(), e); + throw new UnsupportedOperationException("event cannot be encoded", e); } } else { try { String encodedEvent = this.encoder.toJson(event); return encodedEvent; } catch (Exception e) { - String error = "ENCODE-ERROR: "+ event + " IN " + this; - logger.error(MessageCodes.EXCEPTION_ERROR, e, error); - throw new UnsupportedOperationException(error, e); + logger.warn("{} cannot encode {} because of {}", this, event, e.getMessage(), e); + throw new UnsupportedOperationException("event cannot be encoded", e); } } } diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java index de666165..be6c4962 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java @@ -20,6 +20,7 @@ package org.openecomp.policy.drools.server.restful; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -42,9 +43,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.openecomp.policy.common.logging.eelf.MessageCodes; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.drools.controller.DroolsController; import org.openecomp.policy.drools.event.comm.TopicEndpoint; import org.openecomp.policy.drools.event.comm.TopicSink; @@ -65,7 +63,10 @@ import org.openecomp.policy.drools.protocol.configuration.ControllerConfiguratio import org.openecomp.policy.drools.protocol.configuration.PdpdConfiguration; import org.openecomp.policy.drools.system.PolicyController; import org.openecomp.policy.drools.system.PolicyEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ch.qos.logback.classic.LoggerContext; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -101,7 +102,7 @@ public class RestManager { /** * Logger */ - private static Logger logger = FlexLogger.getLogger(RestManager.class); + private static Logger logger = LoggerFactory.getLogger(RestManager.class); @GET @Path("engine") @@ -125,8 +126,7 @@ public class RestManager { try { PolicyEngine.manager.shutdown(); } catch (IllegalStateException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - "shutdown: " + PolicyEngine.manager); + logger.error("{}: cannot shutdown {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST). entity(PolicyEngine.manager). build(); @@ -211,8 +211,7 @@ public class RestManager { success = PolicyEngine.manager.configure(configuration); } catch (Exception e) { success = false; - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - "PolicyEngine", this.toString()); + logger.info("{}: cannot configure {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); } if (!success) @@ -260,8 +259,7 @@ public class RestManager { PolicyEngine.manager.activate(); } catch (Exception e) { success = false; - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - "PolicyEngine", this.toString()); + logger.info("{}: cannot activate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); } if (!success) @@ -285,8 +283,7 @@ public class RestManager { PolicyEngine.manager.deactivate(); } catch (Exception e) { success = false; - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - "PolicyEngine", this.toString()); + logger.info("{}: cannot deactivate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); } if (!success) @@ -406,8 +403,7 @@ public class RestManager { } catch (IllegalArgumentException e) { // This is OK } catch (IllegalStateException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, this.toString()); + logger.info("{}: cannot get policy-controller because of {}", this, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not found")).build(); } @@ -416,8 +412,7 @@ public class RestManager { controller = PolicyEngine.manager.createPolicyController (config.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME), config); } catch (IllegalArgumentException | IllegalStateException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, this.toString()); + logger.warn("{}: cannot create policy-controller because of {}", this, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST). entity(new Error(e.getMessage())). build(); @@ -426,13 +421,12 @@ public class RestManager { try { boolean success = controller.start(); if (!success) { - logger.warn("Can't start " + controllerName + ": " + controller.toString()); + logger.info("{}: cannot start {}", this, controller); return Response.status(Response.Status.PARTIAL_CONTENT). entity(new Error(controllerName + " can't be started")).build(); } } catch (IllegalStateException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, this.toString()); + logger.info("{}: cannot start {} because of {}", this, controller, e.getMessage(), e);; return Response.status(Response.Status.PARTIAL_CONTENT). entity(controller).build(); } @@ -547,14 +541,12 @@ public class RestManager { entity(new Error(controllerName + " does not exist")). build(); } catch (IllegalArgumentException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, this.toString()); + logger.info("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST). entity(new Error(controllerName + " not found: " + e.getMessage())). build(); } catch (IllegalStateException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, this.toString()); + logger.info("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")).build(); } @@ -562,8 +554,7 @@ public class RestManager { try { PolicyEngine.manager.removePolicyController(controllerName); } catch (IllegalArgumentException | IllegalStateException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName + controller); + logger.info("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -647,14 +638,12 @@ public class RestManager { entity(new Error(controllerName + " does not exist")). build(); } catch (IllegalArgumentException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, this.toString()); + logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST). entity(new Error(controllerName + " not found: " + e.getMessage())). build(); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - controllerName, this.toString()); + logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")).build(); } @@ -2182,6 +2171,91 @@ public class RestManager { build(); } + @GET + @Path("engine/tools/loggers") + @ApiOperation( + value="all active loggers", + responseContainer="List" + ) + @ApiResponses(value = { + @ApiResponse(code=500, message="logging misconfiguration") + }) + public Response loggers() { + List<String> names = new ArrayList<String>(); + if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) { + logger.warn("The SLF4J logger factory is not configured for logback"); + return Response.status(Status.INTERNAL_SERVER_ERROR). + entity(names).build(); + } + + LoggerContext context = + (LoggerContext) LoggerFactory.getILoggerFactory(); + for (Logger logger: context.getLoggerList()) { + names.add(logger.getName()); + } + + return Response.status(Status.OK). + entity(names). + build(); + } + + @GET + @Path("engine/tools/loggers/{logger}") + @ApiOperation( + value="logging level of a logger" + ) + @ApiResponses(value = { + @ApiResponse(code=500, message="logging misconfiguration"), + @ApiResponse(code=404, message="logger not found") + }) + public Response loggerName(@ApiParam(value="Logger Name", required=true) + @PathParam("logger") String loggerName) { + if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) { + logger.warn("The SLF4J logger factory is not configured for logback"); + return Response.status(Status.INTERNAL_SERVER_ERROR).build(); + } + + LoggerContext context = + (LoggerContext) LoggerFactory.getILoggerFactory(); + ch.qos.logback.classic.Logger logger = context.getLogger(loggerName); + if (logger == null) { + return Response.status(Status.NOT_FOUND).build(); + } + + String loggerLevel = (logger.getLevel() != null) ? logger.getLevel().toString() : ""; + return Response.status(Status.OK).entity(loggerLevel).build(); + } + + @PUT + @Path("engine/tools/loggers/{logger}/{level}") + @ApiOperation( + value="sets the logger level", + notes="Please use the SLF4J logger levels" + ) + @ApiResponses(value = { + @ApiResponse(code=500, message="logging misconfiguration"), + @ApiResponse(code=404, message="logger not found") + }) + public Response loggerName(@ApiParam(value="Logger Name", required=true) + @PathParam("logger") String loggerName, + @ApiParam(value="Logger Level", required=true) + @PathParam("level") String loggerLevel) { + if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) { + logger.warn("The SLF4J logger factory is not configured for logback"); + return Response.status(Status.INTERNAL_SERVER_ERROR).build(); + } + + LoggerContext context = + (LoggerContext) LoggerFactory.getILoggerFactory(); + ch.qos.logback.classic.Logger logger = context.getLogger(loggerName); + if (logger == null) { + return Response.status(Status.NOT_FOUND).build(); + } + + logger.setLevel(ch.qos.logback.classic.Level.toLevel(loggerLevel)); + return Response.status(Status.OK).entity(logger.getLevel().toString()).build(); + } + /** * gets the underlying drools controller from the named policy controller * @param controllerName the policy controller name @@ -2204,6 +2278,13 @@ public class RestManager { * Helper classes for aggregation of results */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("rest-telemetry-api []"); + return builder.toString(); + } + /** * Coding/Encoding Results Aggregation Helper class */ diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java index 108600b2..3b12514c 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java @@ -25,8 +25,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.core.PolicyContainer; import org.openecomp.policy.drools.persistence.SystemPersistence; import org.openecomp.policy.drools.utils.PropertyUtil; @@ -35,14 +35,58 @@ import org.openecomp.policy.drools.utils.PropertyUtil; * Programmatic entry point to the management layer */ public class Main { + + /** + * logback configuration file system property + */ + public static final String LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY = "logback.configurationFile"; + + /** + * logback configuration file system property + */ + public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "config/logback.xml"; + + /** + * EELF logback configuration path system property + */ + public static final String EELF_LOGBACK_PATH_SYSTEM_PROPERTY = "com.att.eelf.logging.file"; + + /** + * EELF logback configuration path value + */ + public static final String EELF_LOGBACK_PATH_DEFAULT = "config"; /** - * logger + * EELF logback configuration file system property */ - private static Logger logger = FlexLogger.getLogger(Main.class, true); + public static final String EELF_LOGBACK_FILE_SYSTEM_PROPERTY = "com.att.eelf.logging.path"; + /** + * EELF logback configuration file default value + */ + public static final String EELF_LOGBACK_FILE_DEFAULT = "logback.xml"; + + + /** + * main + * + * @param args program arguments + */ public static void main(String args[]) { + /* logging defaults */ + + if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) + System.setProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, LOGBACK_CONFIGURATION_FILE_DEFAULT); + + if (System.getProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY) == null) + System.setProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY, EELF_LOGBACK_PATH_DEFAULT); + + if (System.getProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY) == null) + System.setProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY, EELF_LOGBACK_FILE_DEFAULT); + + Logger logger = LoggerFactory.getLogger(Main.class); + File configDir = new File(SystemPersistence.CONFIG_DIR_NAME); if (!configDir.isDirectory()) { @@ -57,9 +101,7 @@ public class Main { try { PolicyContainer.globalInit(args); } catch (Exception e) { - System.out.println("policy-core startup failed"); - logger.warn("policy-core startup failed"); - e.printStackTrace(); + logger.warn("Main: cannot init policy-container because of {}", e.getMessage(), e); } /* 1. Configure the Engine */ @@ -69,9 +111,7 @@ public class Main { Properties properties = PropertyUtil.getProperties(policyEnginePath.toFile()); PolicyEngine.manager.configure(properties); } catch (Exception e) { - String msg = "Policy Engine cannot be configured with properties: " + e.getMessage() + " : " + PolicyEngine.manager; - System.out.println(msg); - logger.warn(msg); + logger.warn("Main: cannot initialize {} because of {}", PolicyEngine.manager, e.getMessage(), e); } /* 2. Start the Engine with the basic services only (no Policy Controllers) */ @@ -79,17 +119,12 @@ public class Main { try { boolean success = PolicyEngine.manager.start(); if (!success) { - System.out.println("Policy Engine found some problems starting some components: " + PolicyEngine.manager); - logger.warn("Policy Engine is in an invalid state: " + PolicyEngine.manager); + logger.warn("Main: {} has been partially started", PolicyEngine.manager); } } catch (IllegalStateException e) { - String msg = "Policy Engine is starting in an unexpected state: " + e.getMessage() + " : " + PolicyEngine.manager; - System.out.println(msg); - logger.warn(msg); + logger.warn("Main: cannot start {} (bad state) because of {}", PolicyEngine.manager, e.getMessage(), e); } catch (Exception e) { - String msg = "Unexpected Situation. Policy Engine cannot be started: " + e.getMessage() + " : " + PolicyEngine.manager; - System.out.println(msg); - e.printStackTrace(); + logger.warn("Main: cannot start {} because of {}", PolicyEngine.manager, e.getMessage(), e); System.exit(1); } @@ -117,13 +152,10 @@ public class Main { PolicyController controller = PolicyEngine.manager.createPolicyController(name, properties); controller.start(); } catch (Exception e) { - System.out.println("can't instantiate Policy Controller based on properties file: " + - config + " with message " + e.getMessage()); - e.printStackTrace(); - } catch (LinkageError le) { - System.out.println("can't instantiate Policy Controller based on properties file: " + - config + ". A Linkage Error has been encountered: " + le.getMessage()); - le.printStackTrace(); + logger.error("Main: cannot instantiate policy-controller {} because of {}", name, e.getMessage(), e); + } catch (LinkageError e) { + logger.warn("Main: cannot instantiate policy-controller {} (linkage) because of {}", + name, e.getMessage(), e); } } } diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java index c6020ea6..12a8acdc 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java @@ -25,8 +25,8 @@ import java.util.HashMap; import java.util.List; import java.util.Properties; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.controller.DroolsController; import org.openecomp.policy.drools.features.PolicyControllerFeatureAPI; import org.openecomp.policy.drools.protocol.configuration.DroolsConfiguration; @@ -184,7 +184,7 @@ public interface PolicyControllerFactory { */ class IndexedPolicyControllerFactory implements PolicyControllerFactory { // get an instance of logger - private static Logger logger = FlexLogger.getLogger(PolicyControllerFactory.class); + private static Logger logger = LoggerFactory.getLogger(PolicyControllerFactory.class); /** * Policy Controller Name Index diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java index f18aa78e..974a7260 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java @@ -24,9 +24,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.openecomp.policy.common.logging.eelf.MessageCodes; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.controller.DroolsController; import org.openecomp.policy.drools.core.jmx.PdpJmxListener; import org.openecomp.policy.drools.event.comm.Topic; @@ -319,7 +318,7 @@ class PolicyEngineManager implements PolicyEngine { /** * logger */ - private static Logger logger = FlexLogger.getLogger(PolicyEngineManager.class); + private static Logger logger = LoggerFactory.getLogger(PolicyEngineManager.class); /** * Is the Policy Engine running? @@ -373,8 +372,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeConfigure(this, properties)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-configure failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -386,19 +385,19 @@ class PolicyEngineManager implements PolicyEngine { source.register(this); } } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "configure"); + logger.error("{}: add-sources failed", this, e); } try { this.sinks = TopicEndpoint.manager.addTopicSinks(properties); } catch (IllegalArgumentException e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "configure"); + logger.error("{}: add-sinks failed", this, e); } try { this.httpServers = HttpServletServer.factory.build(properties); } catch (IllegalArgumentException e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "configure"); + logger.error("{}: add-http-servers failed", this, e); } /* policy-engine dispatch post configure hook */ @@ -407,8 +406,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterConfigure(this)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-configure failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -442,8 +441,8 @@ class PolicyEngineManager implements PolicyEngine { if (controller != null) return controller; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + controllerFeature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-controller-create failure because of {}", + this, controllerFeature.getClass().getName(), e.getMessage(), e); } } @@ -457,8 +456,8 @@ class PolicyEngineManager implements PolicyEngine { if (controllerFeature.afterCreate(controller)) return controller; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + controllerFeature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-controller-create failure because of {}", + this, controllerFeature.getClass().getName(), e.getMessage(), e); } } @@ -519,7 +518,7 @@ class PolicyEngineManager implements PolicyEngine { PolicyController policyController = this.updatePolicyController(configController); policyControllers.add(policyController); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "updatePolicyControllers"); + logger.error("{}: cannot update-policy-controllers because of {}", this, e.getMessage(), e); } } @@ -620,10 +619,10 @@ class PolicyEngineManager implements PolicyEngine { return policyController; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "updatePolicyController " + e.getMessage()); + logger.error("{}: cannot update-policy-controller because of {}", this, e.getMessage(), e); throw e; } catch (LinkageError e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "updatePolicyController " + e.getMessage()); + logger.error("{}: cannot update-policy-controllers (rules) because of {}", this, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -640,8 +639,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeStart(this)) return true; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-start failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -658,7 +657,8 @@ class PolicyEngineManager implements PolicyEngine { if (!httpServer.start()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, httpServer.toString(), this.toString()); + logger.error("{}: cannot start http-server {} because of {}", this, + httpServer, e.getMessage(), e); } } @@ -669,7 +669,8 @@ class PolicyEngineManager implements PolicyEngine { if (!source.start()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, source.toString(), this.toString()); + logger.error("{}: cannot start topic-source {} because of {}", this, + source, e.getMessage(), e); } } @@ -680,7 +681,8 @@ class PolicyEngineManager implements PolicyEngine { if (!sink.start()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, sink.toString(), this.toString()); + logger.error("{}: cannot start topic-sink {} because of {}", this, + sink, e.getMessage(), e); } } @@ -692,7 +694,8 @@ class PolicyEngineManager implements PolicyEngine { if (!controller.start()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + logger.error("{}: cannot start policy-controller {} because of {}", this, + controller, e.getMessage(), e); success = false; } } @@ -703,8 +706,7 @@ class PolicyEngineManager implements PolicyEngine { if (!TopicEndpoint.manager.start()) success = false; } catch (IllegalStateException e) { - String msg = "Topic Endpoint Manager is in an invalid state: " + e.getMessage() + " : " + this; - logger.warn(msg); + logger.warn("{}: Topic Endpoint Manager is in an invalid state because of {}", this, e.getMessage(), e); } @@ -718,8 +720,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterStart(this)) return success; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-start failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -738,8 +740,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeStop(this)) return true; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-stop failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -757,7 +759,8 @@ class PolicyEngineManager implements PolicyEngine { if (!controller.stop()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + logger.error("{}: cannot stop policy-controller {} because of {}", this, + controller, e.getMessage(), e); success = false; } } @@ -768,7 +771,8 @@ class PolicyEngineManager implements PolicyEngine { if (!source.stop()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, source.toString(), this.toString()); + logger.error("{}: cannot start topic-source {} because of {}", this, + source, e.getMessage(), e); } } @@ -778,7 +782,8 @@ class PolicyEngineManager implements PolicyEngine { if (!sink.stop()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, sink.toString(), this.toString()); + logger.error("{}: cannot start topic-sink {} because of {}", this, + sink, e.getMessage(), e); } } @@ -792,7 +797,8 @@ class PolicyEngineManager implements PolicyEngine { if (!httpServer.stop()) success = false; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, httpServer.toString(), this.toString()); + logger.error("{}: cannot start http-server {} because of {}", this, + httpServer, e.getMessage(), e); } } @@ -802,8 +808,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterStop(this)) return success; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-stop failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -822,8 +828,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeShutdown(this)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-shutdown failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -834,7 +840,8 @@ class PolicyEngineManager implements PolicyEngine { try { source.shutdown(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, source.toString(), this.toString()); + logger.error("{}: cannot shutdown topic-source {} because of {}", this, + source, e.getMessage(), e); } } @@ -843,7 +850,8 @@ class PolicyEngineManager implements PolicyEngine { try { sink.shutdown(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, sink.toString(), this.toString()); + logger.error("{}: cannot shutdown topic-sink {} because of {}", this, + sink, e.getMessage(), e); } } @@ -862,8 +870,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterShutdown(this)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-shutdown failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -874,7 +882,7 @@ class PolicyEngineManager implements PolicyEngine { try { Thread.sleep(5000L); } catch (InterruptedException e) { - logger.warn("InterruptedException while shutting down management server: " + this.toString()); + logger.warn("{}: interrupted-exception while shutting down management server: ", this); } /* shutdown all unmanaged http servers */ @@ -882,14 +890,15 @@ class PolicyEngineManager implements PolicyEngine { try { httpServer.shutdown(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, httpServer.toString(), this.toString()); + logger.error("{}: cannot shutdown http-server {} because of {}", this, + httpServer, e.getMessage(), e); } } try { Thread.sleep(5000L); } catch (InterruptedException e) { - logger.warn("InterruptedException while shutting down management server: " + this.toString()); + logger.warn("{}: interrupted-exception while shutting down management server: ", this); } System.exit(0); @@ -917,8 +926,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeLock(this)) return true; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-lock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -933,7 +942,8 @@ class PolicyEngineManager implements PolicyEngine { try { success = controller.lock() && success; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + logger.error("{}: cannot lock policy-controller {} because of {}", this, + controller, e.getMessage(), e); success = false; } } @@ -946,8 +956,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterLock(this)) return success; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-lock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -966,8 +976,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeUnlock(this)) return true; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-unlock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -982,7 +992,8 @@ class PolicyEngineManager implements PolicyEngine { try { success = controller.unlock() && success; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + logger.error("{}: cannot unlock policy-controller {} because of {}", this, + controller, e.getMessage(), e); success = false; } } @@ -995,8 +1006,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterUnlock(this)) return success; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-unlock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -1133,7 +1144,8 @@ class PolicyEngineManager implements PolicyEngine { PdpdConfiguration configuration = this.decoder.fromJson(event, PdpdConfiguration.class); this.configure(configuration); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "CONFIGURATION ERROR IN PDP-D POLICY ENGINE: "+ event + ":" + e.getMessage() + ":" + this); + logger.error("{}: configuration-error due to {} because of {}", + this, event, e.getMessage(), e); } } @@ -1248,8 +1260,9 @@ class PolicyEngineManager implements PolicyEngine { if (controller != null) return controller.deliver(busType, topic, event); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - busType + ":" + topic + " :" + event, this.toString()); + logger.warn("{}: cannot find policy-controller to deliver {} over {}:{} because of {}", + this, event, busType, topic, e.getMessage(), e); + /* continue (try without routing through the controller) */ } @@ -1262,8 +1275,8 @@ class PolicyEngineManager implements PolicyEngine { return this.deliver(busType, topic, json); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - busType + ":" + topic + " :" + event, this.toString()); + logger.warn("{}: cannot deliver {} over {}:{} because of {}", + this, event, busType, topic, e.getMessage(), e); throw e; } } @@ -1300,8 +1313,8 @@ class PolicyEngineManager implements PolicyEngine { return sink.send(event); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - busType + ":" + topic + " :" + event, this.toString()); + logger.warn("{}: cannot deliver {} over {}:{} because of {}", + this, event, busType, topic, e.getMessage(), e); throw e; } } @@ -1318,8 +1331,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeActivate(this)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-activate failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -1329,11 +1342,11 @@ class PolicyEngineManager implements PolicyEngine { policyController.unlock(); policyController.start(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.activate: cannot start " + - policyController + " because of " + e.getMessage()); + logger.error("{}: cannot activate of policy-controller {} because of {}", + this, policyController,e.getMessage(), e); } catch (LinkageError e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.activate: cannot start " + - policyController + " because of " + e.getMessage()); + logger.error("{}: cannot activate (rules compilation) of policy-controller {} because of {}", + this, policyController,e.getMessage(), e); } } @@ -1345,8 +1358,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterActivate(this)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-activate failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } } @@ -1363,8 +1376,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.beforeDeactivate(this)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} before-deactivate failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -1374,11 +1387,11 @@ class PolicyEngineManager implements PolicyEngine { try { policyController.stop(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.deactivate: cannot stop " + - policyController + " because of " + e.getMessage()); + logger.error("{}: cannot deactivate (stop) policy-controller {} because of {}", + this, policyController, e.getMessage(), e); } catch (LinkageError e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.deactivate: cannot start " + - policyController + " because of " + e.getMessage()); + logger.error("{}: cannot deactivate (stop) policy-controller {} because of {}", + this, policyController, e.getMessage(), e); } } @@ -1388,8 +1401,8 @@ class PolicyEngineManager implements PolicyEngine { if (feature.afterDeactivate(this)) return; } catch (Exception e) { - System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); - e.printStackTrace(); + logger.error("{}: feature {} after-deactivate failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } } diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java index 36a58512..f0491624 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java @@ -24,8 +24,8 @@ import java.util.HashMap; import java.util.List; import java.util.Properties; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.controller.DroolsController; import org.openecomp.policy.drools.event.comm.Topic; import org.openecomp.policy.drools.event.comm.TopicEndpoint; @@ -50,7 +50,7 @@ public class AggregatedPolicyController implements PolicyController, /** * Logger */ - private static Logger logger = FlexLogger.getLogger(AggregatedPolicyController.class); + private static Logger logger = LoggerFactory.getLogger(AggregatedPolicyController.class); /** * identifier for this policy controller @@ -144,10 +144,7 @@ public class AggregatedPolicyController implements PolicyController, // Register with drools infrastructure this.droolsController = DroolsController.factory.build(properties, sources, sinks); } catch (Exception | LinkageError e) { - logger.error("BUILD-INIT-DROOLS: " + e.getMessage()); - e.printStackTrace(); - - // throw back exception as input properties cause problems + logger.error("{}: cannot init-drools because of {}", this, e.getMessage(), e); throw new IllegalArgumentException(e); } } @@ -177,8 +174,8 @@ public class AggregatedPolicyController implements PolicyController, if (oldDroolsConfiguration.getGroupId().equalsIgnoreCase(newDroolsConfiguration.getGroupId()) && oldDroolsConfiguration.getArtifactId().equalsIgnoreCase(newDroolsConfiguration.getArtifactId()) && oldDroolsConfiguration.getVersion().equalsIgnoreCase(newDroolsConfiguration.getVersion())) { - logger.warn("UPDATE-DROOLS: nothing to do: identical configuration: " + oldDroolsConfiguration + - " <=> " + newDroolsConfiguration); + logger.warn("{}: cannot update-drools: identical configuration {} vs {}", + this, oldDroolsConfiguration, newDroolsConfiguration); return true; } @@ -208,8 +205,7 @@ public class AggregatedPolicyController implements PolicyController, this.droolsController.stop(); } catch (IllegalArgumentException e) { - logger.warn("INIT-DROOLS: " + e.getMessage()); - e.printStackTrace(); + logger.error("{}: cannot update-drools because of {}", this, e.getMessage(), e); return false; } @@ -228,17 +224,16 @@ public class AggregatedPolicyController implements PolicyController, * {@inheritDoc} */ @Override - public boolean start() throws IllegalStateException { - - if (logger.isInfoEnabled()) - logger.info("START: " + this); + public boolean start() throws IllegalStateException { + logger.info("{}: start", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeStart(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-start failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -264,8 +259,8 @@ public class AggregatedPolicyController implements PolicyController, try { sink.start(); } catch (Exception e) { - logger.warn("can't start sink: " + sink + " because of " + e.getMessage()); - e.printStackTrace(); + logger.error("{}: cannot start {} because of {}", + this, sink, e.getMessage(), e); } } @@ -274,7 +269,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterStart(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-start failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -286,16 +282,15 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public boolean stop() { - - if (logger.isInfoEnabled()) - logger.info("STOP: " + this); + logger.info("{}: stop", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeStop(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-stop failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -321,7 +316,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterStop(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-stop failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -333,15 +329,15 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public void shutdown() throws IllegalStateException { - if (logger.isInfoEnabled()) - logger.info("SHUTDOWN: " + this); + logger.info("{}: shutdown", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeShutdown(this)) return; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-shutdown failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -354,7 +350,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterShutdown(this)) return; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-shutdown failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } } @@ -364,15 +361,15 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public void halt() throws IllegalStateException { - if (logger.isInfoEnabled()) - logger.info("HALT: " + this); + logger.info("{}: halt", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeHalt(this)) return; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-halt failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -385,7 +382,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterHalt(this)) return; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-halt failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } } @@ -398,14 +396,15 @@ public class AggregatedPolicyController implements PolicyController, String topic, String event) { if (logger.isDebugEnabled()) - logger.debug("EVENT NOTIFICATION: " + commType + ":" + topic + ":" + event + " INTO " + this); + logger.debug("{}: event offered from {}:{}: {}", this, commType, topic, event); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeOffer(this, commType, topic, event)) return; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-offer failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -422,7 +421,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterOffer(this, commType, topic, event, success)) return; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-offer failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } } @@ -437,14 +437,15 @@ public class AggregatedPolicyController implements PolicyController, UnsupportedOperationException { if (logger.isDebugEnabled()) - logger.debug("DELIVER: " + commType + ":" + topic + ":" + event + " FROM " + this); + logger.debug("{}: deliver event to {}:{}: {}", this, commType, topic, event); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeDeliver(this, commType, topic, event)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-deliver failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -461,9 +462,9 @@ public class AggregatedPolicyController implements PolicyController, throw new IllegalStateException("Policy Engine is locked"); if (!this.topic2Sinks.containsKey(topic)) { - logger.error("UNDELIVERED: " + commType + ":" + topic + ":" + event + " FROM " + this); - throw new IllegalArgumentException - ("Unsuported topic " + topic + " for delivery"); + logger.warn("{}: cannot deliver event because the sink {}:{} is not registered: {}", + this, commType, topic, event); + throw new IllegalArgumentException("Unsuported topic " + topic + " for delivery"); } boolean success = this.droolsController.deliver(this.topic2Sinks.get(topic), event); @@ -473,7 +474,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterDeliver(this, commType, topic, event, success)) return success; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-deliver failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -493,15 +495,15 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public boolean lock() { - if (logger.isInfoEnabled()) - logger.info("LOCK: " + this); + logger.info("{}: lock", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeLock(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-lock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -522,7 +524,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterLock(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-lock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -535,15 +538,15 @@ public class AggregatedPolicyController implements PolicyController, @Override public boolean unlock() { - if (logger.isInfoEnabled()) - logger.info("UNLOCK: " + this); + logger.info("{}: unlock", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { try { if (feature.beforeUnlock(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} before-unlock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } @@ -561,7 +564,8 @@ public class AggregatedPolicyController implements PolicyController, if (feature.afterUnlock(this)) return true; } catch (Exception e) { - logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + logger.error("{}: feature {} after-unlock failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); } } |