diff options
Diffstat (limited to 'policy-management/src')
9 files changed, 77 insertions, 410 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java index 6dcae635..24fc6de9 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,6 @@ import org.onap.policy.drools.properties.DroolsProperties; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; -import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter; import org.onap.policy.drools.utils.Pair; import org.slf4j.Logger; @@ -311,19 +310,6 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } } - String customJackson = properties.getProperty(propertyTopicEntityPrefix + firstTopic - + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_JACKSON_SUFFIX); - - CustomJacksonCoder customJacksonCoder = null; - if (customJackson != null && !customJackson.isEmpty()) { - try { - customJacksonCoder = new CustomJacksonCoder(customJackson); - } catch (IllegalArgumentException e) { - logger.warn("{}: cannot create custom-jackson-coder {} because of {}", this, customJackson, - e.getMessage(), e); - } - } - // 3. second the list of classes associated with each topic String eventClasses = properties @@ -395,7 +381,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } TopicCoderFilterConfiguration topic2Classes2Filters = - new TopicCoderFilterConfiguration(firstTopic, classes2Filters, customGsonCoder, customJacksonCoder); + new TopicCoderFilterConfiguration(firstTopic, classes2Filters, customGsonCoder); topics2DecodedClasses2Filters.add(topic2Classes2Filters); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java index 6e9f04ed..55352fe2 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java @@ -46,7 +46,6 @@ import org.onap.policy.drools.protocol.coders.EventProtocolParams; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; -import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter; import org.onap.policy.drools.utils.ReflectionUtil; import org.slf4j.Logger; @@ -270,22 +269,6 @@ public class MavenDroolsController implements DroolsController { } } - CustomJacksonCoder customJacksonCoder = coderConfig.getCustomJacksonCoder(); - if (coderConfig.getCustomJacksonCoder() != null - && coderConfig.getCustomJacksonCoder().getClassContainer() != null - && !coderConfig.getCustomJacksonCoder().getClassContainer().isEmpty()) { - - String customJacksonCoderClass = coderConfig.getCustomJacksonCoder().getClassContainer(); - if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), - customJacksonCoderClass)) { - throw makeRetrieveEx(customJacksonCoderClass); - } else { - if (logger.isInfoEnabled()) { - logClassFetched(customJacksonCoderClass); - } - } - } - List<PotentialCoderFilter> coderFilters = coderConfig.getCoderFilters(); if (coderFilters == null || coderFilters.isEmpty()) { continue; @@ -312,14 +295,13 @@ public class MavenDroolsController implements DroolsController { .eventClass(potentialCodedClass) .protocolFilter(protocolFilter) .customGsonCoder(customGsonCoder) - .customJacksonCoder(customJacksonCoder) .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode())); } else { EventProtocolCoder.manager.addEncoder( EventProtocolParams.builder().groupId(this.getGroupId()) .artifactId(this.getArtifactId()).topic(topic) .eventClass(potentialCodedClass).protocolFilter(protocolFilter) - .customGsonCoder(customGsonCoder).customJacksonCoder(customJacksonCoder) + .customGsonCoder(customGsonCoder) .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode())); } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java index 6d16c601..56eadad3 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright(C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,10 +26,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; - import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; -import org.onap.policy.drools.utils.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -379,7 +377,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public void addDecoder(EventProtocolParams eventProtocolParams) { logger.info( - "{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", + "{}: add-decoder {}:{}:{}:{}:{}:{}:{}", this, eventProtocolParams.getGroupId(), eventProtocolParams.getArtifactId(), @@ -387,7 +385,6 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { eventProtocolParams.getEventClass(), eventProtocolParams.getProtocolFilter(), eventProtocolParams.getCustomGsonCoder(), - eventProtocolParams.getCustomJacksonCoder(), eventProtocolParams.getModelClassLoaderHash()); this.decoders.add(eventProtocolParams); } @@ -400,7 +397,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public void addEncoder(EventProtocolParams eventProtocolParams) { logger.info( - "{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", + "{}: add-decoder {}:{}:{}:{}:{}:{}:{}", this, eventProtocolParams.getGroupId(), eventProtocolParams.getArtifactId(), @@ -408,7 +405,6 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { eventProtocolParams.getEventClass(), eventProtocolParams.getProtocolFilter(), eventProtocolParams.getCustomGsonCoder(), - eventProtocolParams.getCustomJacksonCoder(), eventProtocolParams.getModelClassLoaderHash()); this.encoders.add(eventProtocolParams); } @@ -513,14 +509,14 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { */ @Override public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) { - Pair<ProtocolCoderToolset, ProtocolCoderToolset> decoderToolsets = + ProtocolCoderToolset decoderToolsets = this.decoders.getCoders(groupId, artifactId, topic); if (decoderToolsets == null) { throw new IllegalArgumentException( "Decoders not found for " + groupId + ":" + artifactId + ":" + topic); } - return decoderToolsets.first(); + return decoderToolsets; } /** @@ -534,18 +530,13 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { @Override public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId) { - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> decoderToolsets = + List<ProtocolCoderToolset> decoderToolsets = this.decoders.getCoders(groupId, artifactId); if (decoderToolsets == null) { throw new IllegalArgumentException("Decoders not found for " + groupId + ":" + artifactId); } - List<ProtocolCoderToolset> parser1CoderToolset = new ArrayList<>(); - for (Pair<ProtocolCoderToolset, ProtocolCoderToolset> coderToolsetPair : decoderToolsets) { - parser1CoderToolset.add(coderToolsetPair.first()); - } - - return parser1CoderToolset; + return new ArrayList<>(decoderToolsets); } /** @@ -629,24 +620,20 @@ abstract class GenericEventProtocolCoder { private static Logger logger = LoggerFactory.getLogger(GenericEventProtocolCoder.class); /** - * Mapping topic:controller-id -> /<protocol-decoder-toolset-pair/> where protocol-coder-toolset-pair contains both - * a jackson-protocol-coder-toolset and a gson-protocol-coder-toolset. The first value of the pair will the protocol - * coder toolset most likely to be successful with the encoding or decoding, and consequently the second value will - * be the less likely. + * Mapping topic:controller-id -> /<protocol-decoder-toolset/> where protocol-coder-toolset contains + * a gson-protocol-coder-toolset. */ - protected final HashMap<String, Pair<ProtocolCoderToolset, ProtocolCoderToolset>> coders = + protected final HashMap<String, ProtocolCoderToolset> coders = new HashMap<>(); /** * Mapping topic + classname -> Protocol Set. */ - protected final HashMap<String, List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>>> + protected final HashMap<String, List<ProtocolCoderToolset>> reverseCoders = new HashMap<>(); - protected boolean multipleToolsetRetries = false; - - GenericEventProtocolCoder(boolean multipleToolsetRetries) { - this.multipleToolsetRetries = multipleToolsetRetries; + GenericEventProtocolCoder() { + super(); } /** @@ -678,18 +665,11 @@ abstract class GenericEventProtocolCoder { synchronized (this) { if (coders.containsKey(key)) { - Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolsets = coders.get(key); + ProtocolCoderToolset toolset = coders.get(key); - logger.info("{}: adding coders for existing {}: {}", this, key, toolsets.first()); + logger.info("{}: adding coders for existing {}: {}", this, key, toolset); - toolsets - .first() - .addCoder( - eventProtocolParams.getEventClass(), - eventProtocolParams.getProtocolFilter(), - eventProtocolParams.getModelClassLoaderHash()); - toolsets - .second() + toolset .addCoder( eventProtocolParams.getEventClass(), eventProtocolParams.getProtocolFilter(), @@ -701,34 +681,20 @@ abstract class GenericEventProtocolCoder { this, reverseKey, key, - toolsets.first()); + toolset); - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> reverseMappings = + List<ProtocolCoderToolset> reverseMappings = new ArrayList<>(); - reverseMappings.add(toolsets); + reverseMappings.add(toolset); reverseCoders.put(reverseKey, reverseMappings); } return; } - GsonProtocolCoderToolset gsonCoderTools = + GsonProtocolCoderToolset coderTools = new GsonProtocolCoderToolset(eventProtocolParams, key); - JacksonProtocolCoderToolset jacksonCoderTools = - new JacksonProtocolCoderToolset(eventProtocolParams, key); - - // Use Gson as the first priority encoding/decoding toolset, and Jackson - // as second. This is because it has been observed that they can diverge - // somewhat in the encoding/decoding data types, which can produce json - // that may result incompatible with what some network elements are - // expecting. As decoding takes place, this element will reconfigure - // itself to set the jackson one as the favoured one first, if errors - // are detected in the gson encoding - - Pair<ProtocolCoderToolset, ProtocolCoderToolset> coderTools = - new Pair<>(gsonCoderTools, jacksonCoderTools); - - logger.info("{}: adding coders for new {}: {}", this, key, coderTools.first()); + logger.info("{}: adding coders for new {}: {}", this, key, coderTools); coders.put(key, coderTools); @@ -736,12 +702,12 @@ abstract class GenericEventProtocolCoder { // There is another controller (different group id/artifact id/topic) // that shares the class and the topic. - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> toolsets = + List<ProtocolCoderToolset> toolsets = reverseCoders.get(reverseKey); boolean present = false; - for (Pair<ProtocolCoderToolset, ProtocolCoderToolset> parserSet : toolsets) { + for (ProtocolCoderToolset parserSet : toolsets) { // just doublecheck - present = parserSet.first().getControllerId().equals(key); + present = parserSet.getControllerId().equals(key); if (present) { /* anomaly */ logger.error( @@ -749,18 +715,18 @@ abstract class GenericEventProtocolCoder { this, reverseKey, key, - parserSet.first()); + parserSet); } } if (present) { return; } else { - logger.info("{}: adding coder set for {}: {} ", this, reverseKey, coderTools.getFirst()); + logger.info("{}: adding coder set for {}: {} ", this, reverseKey, coderTools); toolsets.add(coderTools); } } else { - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> toolsets = new ArrayList<>(); + List<ProtocolCoderToolset> toolsets = new ArrayList<>(); toolsets.add(coderTools); logger.info("{}: adding toolset for reverse key {}: {}", this, reverseKey, toolsets); @@ -818,21 +784,21 @@ abstract class GenericEventProtocolCoder { synchronized (this) { if (coders.containsKey(key)) { - Pair<ProtocolCoderToolset, ProtocolCoderToolset> pair = coders.remove(key); + ProtocolCoderToolset coderToolset = coders.remove(key); - logger.info("{}: removed toolset for {}: {}", this, key, pair.getFirst()); + logger.info("{}: removed toolset for {}: {}", this, key, coderToolset); - for (CoderFilters codeFilter : pair.first().getCoders()) { + for (CoderFilters codeFilter : coderToolset.getCoders()) { String className = codeFilter.getCodedClass(); String reverseKey = this.reverseCodersKey(topic, className); if (this.reverseCoders.containsKey(reverseKey)) { - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> toolsets = + List<ProtocolCoderToolset> toolsets = this.reverseCoders.get(reverseKey); - Iterator<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> toolsetsIter = + Iterator<ProtocolCoderToolset> toolsetsIter = toolsets.iterator(); while (toolsetsIter.hasNext()) { - Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolset = toolsetsIter.next(); - if (toolset.first().getControllerId().equals(key)) { + ProtocolCoderToolset toolset = toolsetsIter.next(); + if (toolset.getControllerId().equals(key)) { logger.info( "{}: removed coder from toolset for {} from reverse mapping", this, reverseKey); toolsetsIter.remove(); @@ -896,9 +862,9 @@ abstract class GenericEventProtocolCoder { } String key = this.codersKey(groupId, artifactId, topic); - Pair<ProtocolCoderToolset, ProtocolCoderToolset> coderTools = coders.get(key); + ProtocolCoderToolset coderTools = coders.get(key); try { - Object event = coderTools.first().decode(json); + Object event = coderTools.decode(json); if (event != null) { return event; } @@ -906,27 +872,7 @@ abstract class GenericEventProtocolCoder { logger.debug("{}, cannot decode {}", this, json, e); } - if (multipleToolsetRetries) { - // try the less favored toolset - try { - Object event = coderTools.second().decode(json); - if (event != null) { - // change the priority of the toolset - synchronized (this) { - ProtocolCoderToolset first = coderTools.first(); - ProtocolCoderToolset second = coderTools.second(); - coderTools.first(second); - coderTools.second(first); - } - - return event; - } - } catch (Exception e) { - throw new UnsupportedOperationException(e); - } - } - - throw new UnsupportedOperationException("Cannot decode neither with gson or jackson"); + throw new UnsupportedOperationException("Cannot decode with gson"); } /** @@ -979,12 +925,12 @@ abstract class GenericEventProtocolCoder { throw new IllegalArgumentException("no reverse coder has been found"); } - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> toolsets = + List<ProtocolCoderToolset> toolsets = this.reverseCoders.get(reverseKey); String key = codersKey( - toolsets.get(0).first().getGroupId(), toolsets.get(0).first().getArtifactId(), topic); + toolsets.get(0).getGroupId(), toolsets.get(0).getArtifactId(), topic); return this.encodeInternal(key, event); } @@ -1024,9 +970,9 @@ abstract class GenericEventProtocolCoder { logger.debug("{}: encode for {}: {}", this, key, event); - Pair<ProtocolCoderToolset, ProtocolCoderToolset> coderTools = coders.get(key); + ProtocolCoderToolset coderTools = coders.get(key); try { - String json = coderTools.first().encode(event); + String json = coderTools.encode(event); if (json != null && !json.isEmpty()) { return json; } @@ -1034,28 +980,7 @@ abstract class GenericEventProtocolCoder { logger.warn("{}: cannot encode (first) for {}: {}", this, key, event, e); } - if (multipleToolsetRetries) { - // try the less favored toolset - try { - String json = coderTools.second().encode(event); - if (json != null) { - // change the priority of the toolset - synchronized (this) { - ProtocolCoderToolset first = coderTools.first(); - ProtocolCoderToolset second = coderTools.second(); - coderTools.first(second); - coderTools.second(first); - } - - return json; - } - } catch (Exception e) { - logger.error("{}: cannot encode (second) for {}: {}", this, key, event, e); - throw new UnsupportedOperationException(e); - } - } - - throw new UnsupportedOperationException("Cannot decode neither with gson or jackson"); + throw new UnsupportedOperationException("Cannot decode with gson"); } /** @@ -1077,10 +1002,10 @@ abstract class GenericEventProtocolCoder { return droolsControllers; } - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> toolsets = + List<ProtocolCoderToolset> toolsets = this.reverseCoders.get(reverseKey); - // There must be multiple toolset pairs associated with <topic,classname> reverseKey + // There must be multiple toolsets associated with <topic,classname> reverseKey // case 2 different controllers use the same models and register the same encoder for // the same topic. This is assumed not to occur often but for the purpose of encoding // but there should be no side-effects. Ownership is crosscheck against classname and @@ -1094,11 +1019,11 @@ abstract class GenericEventProtocolCoder { + encodedClass.getClass().getCanonicalName()); } - for (Pair<ProtocolCoderToolset, ProtocolCoderToolset> encoderSet : toolsets) { + for (ProtocolCoderToolset encoderSet : toolsets) { // figure out the right toolset - String groupId = encoderSet.first().getGroupId(); - String artifactId = encoderSet.first().getArtifactId(); - List<CoderFilters> coderFilters = encoderSet.first().getCoders(); + String groupId = encoderSet.getGroupId(); + String artifactId = encoderSet.getArtifactId(); + List<CoderFilters> coderFilters = encoderSet.getCoders(); for (CoderFilters coder : coderFilters) { if (coder.getCodedClass().equals(encodedClass.getClass().getCanonicalName())) { DroolsController droolsController = DroolsController.factory.get(groupId, artifactId, ""); @@ -1137,8 +1062,8 @@ abstract class GenericEventProtocolCoder { } String key = this.codersKey(groupId, artifactId, topic); - Pair<ProtocolCoderToolset, ProtocolCoderToolset> coderTools = coders.get(key); - return coderTools.first().getCoders(); + ProtocolCoderToolset coderTools = coders.get(key); + return coderTools.getCoders(); } /** @@ -1162,10 +1087,10 @@ abstract class GenericEventProtocolCoder { String key = this.codersKey(groupId, artifactId, ""); List<CoderFilters> codersFilters = new ArrayList<>(); - for (Map.Entry<String, Pair<ProtocolCoderToolset, ProtocolCoderToolset>> entry : + for (Map.Entry<String, ProtocolCoderToolset> entry : coders.entrySet()) { if (entry.getKey().startsWith(key)) { - codersFilters.addAll(entry.getValue().first().getCoders()); + codersFilters.addAll(entry.getValue().getCoders()); } } @@ -1194,8 +1119,8 @@ abstract class GenericEventProtocolCoder { } String key = this.codersKey(groupId, artifactId, topic); - Pair<ProtocolCoderToolset, ProtocolCoderToolset> coderTools = coders.get(key); - return coderTools.first().getCoder(classname); + ProtocolCoderToolset coderTools = coders.get(key); + return coderTools.getCoder(classname); } /** @@ -1207,7 +1132,7 @@ abstract class GenericEventProtocolCoder { * @return list of coders * @throws IllegalArgumentException if invalid input */ - public Pair<ProtocolCoderToolset, ProtocolCoderToolset> getCoders( + public ProtocolCoderToolset getCoders( String groupId, String artifactId, String topic) { if (!isCodingSupported(groupId, artifactId, topic)) { @@ -1226,7 +1151,7 @@ abstract class GenericEventProtocolCoder { * @return list of coders * @throws IllegalArgumentException if invalid input */ - public List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> getCoders( + public List<ProtocolCoderToolset> getCoders( String groupId, String artifactId) { if (groupId == null || groupId.isEmpty()) { @@ -1239,8 +1164,8 @@ abstract class GenericEventProtocolCoder { String key = this.codersKey(groupId, artifactId, ""); - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> coderToolset = new ArrayList<>(); - for (Map.Entry<String, Pair<ProtocolCoderToolset, ProtocolCoderToolset>> entry : + List<ProtocolCoderToolset> coderToolset = new ArrayList<>(); + for (Map.Entry<String, ProtocolCoderToolset> entry : coders.entrySet()) { if (entry.getKey().startsWith(key)) { coderToolset.add(entry.getValue()); @@ -1268,14 +1193,14 @@ abstract class GenericEventProtocolCoder { } String key = this.reverseCodersKey(topic, codedClass); - List<Pair<ProtocolCoderToolset, ProtocolCoderToolset>> toolsets = this.reverseCoders.get(key); + List<ProtocolCoderToolset> toolsets = this.reverseCoders.get(key); if (toolsets == null) { throw new IllegalArgumentException("No Coder found for " + key); } List<CoderFilters> coderFilters = new ArrayList<>(); - for (Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolset : toolsets) { - coderFilters.addAll(toolset.first().getCoders()); + for (ProtocolCoderToolset toolset : toolsets) { + coderFilters.addAll(toolset.getCoders()); } return coderFilters; @@ -1360,7 +1285,7 @@ abstract class GenericEventProtocolCoder { class EventProtocolDecoder extends GenericEventProtocolCoder { public EventProtocolDecoder() { - super(false); + super(); } @Override @@ -1372,7 +1297,7 @@ class EventProtocolDecoder extends GenericEventProtocolCoder { class EventProtocolEncoder extends GenericEventProtocolCoder { public EventProtocolEncoder() { - super(false); + super(); } @Override diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java index e8a140e0..810562cd 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +30,6 @@ public class EventProtocolParams { private String eventClass; private JsonProtocolFilter protocolFilter; private TopicCoderFilterConfiguration.CustomGsonCoder customGsonCoder; - private TopicCoderFilterConfiguration.CustomJacksonCoder customJacksonCoder; private int modelClassLoaderHash; public String getGroupId() { @@ -56,10 +56,6 @@ public class EventProtocolParams { return customGsonCoder; } - public TopicCoderFilterConfiguration.CustomJacksonCoder getCustomJacksonCoder() { - return customJacksonCoder; - } - public int getModelClassLoaderHash() { return modelClassLoaderHash; } @@ -138,18 +134,6 @@ public class EventProtocolParams { /** * Setter method. - * - * @param customJacksonCoder custom Jackson coder - * @return EventProtocolParams - */ - public EventProtocolParams customJacksonCoder( - TopicCoderFilterConfiguration.CustomJacksonCoder customJacksonCoder) { - this.customJacksonCoder = customJacksonCoder; - return this; - } - - /** - * Setter method. * @param modelClassLoaderHash integer representing model hash * @return EventProtocolParams */ @@ -159,6 +143,6 @@ public class EventProtocolParams { } public CustomCoder getCustomCoder() { - return this.customGsonCoder != null ? this.customGsonCoder : this.customJacksonCoder; + return this.customGsonCoder; } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java index bc4fe142..97598df4 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,6 @@ package org.onap.policy.drools.protocol.coders; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -330,146 +326,9 @@ public abstract class ProtocolCoderToolset { } -/** - * Tools used for encoding/decoding using Jackson. - */ -class JacksonProtocolCoderToolset extends ProtocolCoderToolset { - private static final String WARN_FETCH_FAILED = "{}: cannot fetch application class {}"; - private static final String WARN_FETCH_FAILED_BECAUSE = "{}: cannot fetch application class {} because of {}"; - private static final String FETCH_FAILED = "cannot fetch application class "; - private static final String ENCODE_FAILED = "event cannot be encoded"; - private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class); - - /** - * decoder. - */ - @JsonIgnore - protected final ObjectMapper decoder = new ObjectMapper(); - - /** - * encoder. - */ - @JsonIgnore - protected final ObjectMapper encoder = new ObjectMapper(); - - /** - * Toolset to encode/decode tools associated with a topic. - * - * @param eventProtocolParams parameter object for event encoder - * @param controllerId controller id - */ - public JacksonProtocolCoderToolset(EventProtocolParams eventProtocolParams, String controllerId) { - super(eventProtocolParams, controllerId); - this.decoder.registerModule(new JavaTimeModule()); - this.decoder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - } - - /** - * gets the Jackson decoder. - * - * @return the Jackson decoder - */ - @JsonIgnore - protected ObjectMapper getDecoder() { - return this.decoder; - } - - /** - * gets the Jackson encoder. - * - * @return the Jackson encoder - */ - @JsonIgnore - protected ObjectMapper getEncoder() { - return this.encoder; - } - - /** - * {@inheritDoc}. - */ - @Override - public Object decode(String json) { - - // 0. Use custom coder if available - - if (this.customCoder != null) { - throw new UnsupportedOperationException( - "Jackon Custom Decoder is not supported at this time"); - } - - final DroolsController droolsController = - DroolsController.factory.get(this.groupId, this.artifactId, ""); - if (droolsController == null) { - logger.warn("{}: no drools-controller to process {}", this, json); - throw new IllegalStateException("no drools-controller to process event"); - } - - final CoderFilters decoderFilter = this.filter(json); - if (decoderFilter == null) { - logger.debug("{}: no decoder to process {}", this, json); - throw new UnsupportedOperationException("no decoder to process event"); - } - - Class<?> decoderClass; - try { - decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); - if (decoderClass == null) { - logger.warn(WARN_FETCH_FAILED, this, decoderFilter.getCodedClass()); - throw new IllegalStateException( - FETCH_FAILED + decoderFilter.getCodedClass()); - } - } catch (final Exception e) { - logger.warn(WARN_FETCH_FAILED_BECAUSE, this, - decoderFilter.getCodedClass(), e.getMessage()); - throw new UnsupportedOperationException( - FETCH_FAILED + decoderFilter.getCodedClass(), e); - } - - - try { - return this.decoder.readValue(json, decoderClass); - } catch (final Exception e) { - logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(), - e.getMessage(), e); - throw new UnsupportedOperationException( - "cannont decode into " + decoderFilter.getCodedClass(), e); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public String encode(Object event) { - - // 0. Use custom coder if available - - if (this.customCoder != null) { - throw new UnsupportedOperationException( - "Jackon Custom Encoder is not supported at this time"); - } - - try { - return this.encoder.writeValueAsString(event); - } catch (final JsonProcessingException e) { - logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e); - throw new UnsupportedOperationException(ENCODE_FAILED); - } - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("JacksonProtocolCoderToolset [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } - -} - - /** - * Tools used for encoding/decoding using Jackson. + * Tools used for encoding/decoding using GSON. */ class GsonProtocolCoderToolset extends ProtocolCoderToolset { /** diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java index f7fc4d21..35a49a1d 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -145,24 +145,6 @@ public class TopicCoderFilterConfiguration { } } - public static class CustomJacksonCoder extends CustomCoder { - - public CustomJacksonCoder(String className, String staticCoderField) { - super(className, staticCoderField); - } - - public CustomJacksonCoder(String customJackson) { - super(customJackson); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } - } - /** * Coder/Decoder class and Filter container. The decoder class is potential, in order to be * operational needs to be fetched from an available class loader. @@ -243,24 +225,20 @@ public class TopicCoderFilterConfiguration { /* custom gson coder that this controller prefers to use instead of the framework ones */ protected CustomGsonCoder customGsonCoder; - /* custom jackson coder that this controller prefers to use instead of the framework ones */ - protected CustomJacksonCoder customJacksonCoder; - /** * Constructor. * - * @param decoderFilters list of decoders and associated filters * @param topic the topic + * @param decoderFilters list of decoders and associated filters + * @param customGsonCoder GSON coder */ public TopicCoderFilterConfiguration( String topic, List<PotentialCoderFilter> decoderFilters, - CustomGsonCoder customGsonCoder, - CustomJacksonCoder customJacksonCoder) { + CustomGsonCoder customGsonCoder) { this.coderFilters = decoderFilters; this.topic = topic; this.customGsonCoder = customGsonCoder; - this.customJacksonCoder = customJacksonCoder; } /** @@ -297,22 +275,6 @@ public class TopicCoderFilterConfiguration { this.customGsonCoder = customGsonCoder; } - /** Get custom jackson coder. - * - * @return the customJacksonCoder - **/ - public CustomJacksonCoder getCustomJacksonCoder() { - return customJacksonCoder; - } - - /** - * Set custom Jackson coder. - * @param customJacksonCoder the customJacksonCoder to set - **/ - public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) { - this.customJacksonCoder = customJacksonCoder; - } - @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -323,8 +285,6 @@ public class TopicCoderFilterConfiguration { .append(coderFilters) .append(", customGsonCoder=") .append(customGsonCoder) - .append(", customJacksonCoder=") - .append(customJacksonCoder) .append("]"); return builder.toString(); } diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java index ec1b9994..682d2805 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,7 +88,6 @@ public class EventProtocolCoderTest { EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT) .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName()) .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null) - .customJacksonCoder(null) .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode())); final String json = EventProtocolCoder.manager.encode(NOOP_TOPIC, diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java index d28f1e52..da491261 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,18 +20,14 @@ package org.onap.policy.drools.protocol.coders; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.PropertyAccessor; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Properties; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -96,7 +92,6 @@ public class ProtocolCoderToolsetTest { public void testToolsets() { createController(); testGsonToolset(createFilterSet()); - testJacksonToolset(createFilterSet()); } /** @@ -129,28 +124,6 @@ public class ProtocolCoderToolsetTest { return new Triple<>("v1", "v2", "v3"); } - /** - * Test Jackson toolset. - * - * @param protocolFilter protocol filter - */ - public void testJacksonToolset(JsonProtocolFilter protocolFilter) { - JacksonProtocolCoderToolset jacksonToolset = new JacksonProtocolCoderToolset( - EventProtocolParams.builder() - .topic(JUNIT_PROTOCOL_CODER_TOPIC) - .groupId(this.releaseId.getGroupId()) - .artifactId(this.releaseId.getArtifactId()) - .eventClass(Triple.class.getCanonicalName()) - .protocolFilter(protocolFilter) - .customJacksonCoder(null) - .modelClassLoaderHash(12345678), CONTROLLER_ID); - - jacksonToolset.getEncoder().setVisibility(PropertyAccessor.FIELD, Visibility.ANY); - jacksonToolset.getDecoder().setVisibility(PropertyAccessor.FIELD, Visibility.ANY); - - testToolset(protocolFilter, jacksonToolset); - } - private void testToolset(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset) { validateInitialization(protocolFilter, coderToolset); diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java index 4a2767a8..dae409ee 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java @@ -208,7 +208,6 @@ public class PolicyEngineTest { EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT) .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName()) .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null) - .customJacksonCoder(null) .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode())); assertTrue(PolicyEngine.manager.deliver(NOOP_TOPIC, |