diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-09-13 19:35:18 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2018-09-13 20:00:37 -0400 |
commit | c733c08b7201ffdee81c7dab2ed50a1ce8fd5bbb (patch) | |
tree | f2a55827d08f47d86ba1a838a1cd5e129731935e /policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java | |
parent | 69c83ef510fe7e1efda5dd75e7beaa862250ef05 (diff) |
Fix checkstyle in policy-management
The submodule policy-management checkstyle fixes. There may be
one or two sonar fixes in there.
Issue-ID: POLICY-882
Change-Id: I9cb43c573c6811dd058943650ba1ea5f6dc880aa
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java')
-rw-r--r-- | policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java | 182 |
1 files changed, 91 insertions, 91 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 b3aaaa7f..6dcae635 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 @@ -26,13 +26,13 @@ import java.util.HashMap; import java.util.List; import java.util.Properties; -import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; -import org.onap.policy.drools.controller.internal.MavenDroolsController; -import org.onap.policy.drools.controller.internal.NullDroolsController; import org.onap.policy.common.endpoints.event.comm.Topic; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; +import org.onap.policy.drools.controller.internal.MavenDroolsController; +import org.onap.policy.drools.controller.internal.NullDroolsController; import org.onap.policy.drools.properties.DroolsProperties; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration; @@ -45,12 +45,12 @@ import org.slf4j.LoggerFactory; /** * Drools Controller Factory to manage controller creation, destruction, and retrieval for - * management interfaces + * management interfaces. */ public interface DroolsControllerFactory { /** - * Constructs a Drools Controller based on properties + * Constructs a Drools Controller based on properties. * * @param properties properties containing initialization parameters * @param eventSources list of event sources @@ -64,7 +64,7 @@ public interface DroolsControllerFactory { List<? extends TopicSink> eventSinks) throws LinkageError; /** - * Explicit construction of a Drools Controller + * Explicit construction of a Drools Controller. * * @param groupId maven group id of drools artifact * @param artifactId maven artifact id of drools artifact @@ -81,31 +81,31 @@ public interface DroolsControllerFactory { List<TopicCoderFilterConfiguration> encoderConfigurations) throws LinkageError; /** - * Releases the Drools Controller from operation + * Releases the Drools Controller from operation. * * @param controller the Drools Controller to shut down */ public void shutdown(DroolsController controller); /** - * Disables all Drools Controllers from operation + * Disables all Drools Controllers from operation. */ public void shutdown(); /** - * Destroys and releases resources for a Drools Controller + * Destroys and releases resources for a Drools Controller. * * @param controller the Drools Controller to destroy */ public void destroy(DroolsController controller); /** - * Destroys all Drools Controllers + * Destroys all Drools Controllers. */ public void destroy(); /** - * Gets the Drools Controller associated with the maven group and artifact id + * Gets the Drools Controller associated with the maven group and artifact id. * * @param groupId maven group id of drools artifact * @param artifactId maven artifact id of drools artifact @@ -117,7 +117,7 @@ public interface DroolsControllerFactory { public DroolsController get(String groupId, String artifactId, String version); /** - * returns the current inventory of Drools Controllers + * returns the current inventory of Drools Controllers. * * @return a list of Drools Controllers */ @@ -128,22 +128,22 @@ public interface DroolsControllerFactory { /* ---------------- implementation ----------------- */ /** - * Factory of Drools Controllers indexed by the Maven coordinates + * Factory of Drools Controllers indexed by the Maven coordinates. */ class IndexedDroolsControllerFactory implements DroolsControllerFactory { /** - * logger + * logger. */ private static Logger logger = LoggerFactory.getLogger(MavenDroolsController.class); /** - * Policy Controller Name Index + * Policy Controller Name Index. */ protected HashMap<String, DroolsController> droolsControllers = new HashMap<>(); /** - * Null Drools Controller + * Null Drools Controller. */ protected NullDroolsController nullDroolsController = new NullDroolsController(); @@ -186,8 +186,66 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { return this.build(groupId, artifactId, version, topics2DecodedClasses2Filters, topics2EncodedClasses2Filters); } + @Override + public DroolsController build(String newGroupId, String newArtifactId, String newVersion, + List<TopicCoderFilterConfiguration> decoderConfigurations, + List<TopicCoderFilterConfiguration> encoderConfigurations) throws LinkageError { + + if (newGroupId == null || newGroupId.isEmpty()) { + throw new IllegalArgumentException("Missing maven group-id coordinate"); + } + + if (newArtifactId == null || newArtifactId.isEmpty()) { + throw new IllegalArgumentException("Missing maven artifact-id coordinate"); + } + + if (newVersion == null || newVersion.isEmpty()) { + throw new IllegalArgumentException("Missing maven version coordinate"); + } + + String controllerId = newGroupId + ":" + newArtifactId; + DroolsController controllerCopy = null; + synchronized (this) { + /* + * The Null Drools Controller for no maven coordinates is always here so when no + * coordinates present, this is the return point + * + * assert (controllerCopy instanceof NullDroolsController) + */ + if (droolsControllers.containsKey(controllerId)) { + controllerCopy = droolsControllers.get(controllerId); + if (controllerCopy.getVersion().equalsIgnoreCase(newVersion)) { + return controllerCopy; + } + } + } + + if (controllerCopy != null) { + /* + * a controller keyed by group id + artifact id exists but with different version => + * version upgrade/downgrade + */ + + controllerCopy.updateToVersion(newGroupId, newArtifactId, newVersion, decoderConfigurations, + encoderConfigurations); + + return controllerCopy; + } + + /* new drools controller */ + + DroolsController controller = new MavenDroolsController(newGroupId, newArtifactId, newVersion, + decoderConfigurations, encoderConfigurations); + + synchronized (this) { + droolsControllers.put(controllerId, controller); + } + + return controller; + } + /** - * find out decoder classes and filters + * find out decoder classes and filters. * * @param properties properties with information about decoders * @param topicEntities topic sources @@ -235,12 +293,12 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { // 1. first the topic - String aTopic = topic.getTopic(); + String firstTopic = topic.getTopic(); // 2. check if there is a custom decoder for this topic that the user prefers to use // instead of the ones provided in the platform - String customGson = properties.getProperty(propertyTopicEntityPrefix + aTopic + String customGson = properties.getProperty(propertyTopicEntityPrefix + firstTopic + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_GSON_SUFFIX); CustomGsonCoder customGsonCoder = null; @@ -253,7 +311,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } } - String customJackson = properties.getProperty(propertyTopicEntityPrefix + aTopic + String customJackson = properties.getProperty(propertyTopicEntityPrefix + firstTopic + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_JACKSON_SUFFIX); CustomJacksonCoder customJacksonCoder = null; @@ -269,25 +327,27 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { // 3. second the list of classes associated with each topic String eventClasses = properties - .getProperty(propertyTopicEntityPrefix + aTopic + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX); + .getProperty(propertyTopicEntityPrefix + firstTopic + + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX); if (eventClasses == null || eventClasses.isEmpty()) { - // TODO warn + logger.warn("There are no event classes for topic {}", firstTopic); continue; } List<PotentialCoderFilter> classes2Filters = new ArrayList<>(); - List<String> aTopicClasses = new ArrayList<>(Arrays.asList(eventClasses.split("\\s*,\\s*"))); + List<String> topicClasses = new ArrayList<>(Arrays.asList(eventClasses.split("\\s*,\\s*"))); - for (String aClass : aTopicClasses) { + for (String theClass : topicClasses) { // 4. third, for each coder class, get the list of field filters String filter = properties - .getProperty(propertyTopicEntityPrefix + aTopic + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX - + "." + aClass + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX); + .getProperty(propertyTopicEntityPrefix + firstTopic + + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX + + "." + theClass + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX); List<Pair<String, String>> filters = new ArrayList<>(); @@ -295,7 +355,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { // 4. topic -> class -> with no filters JsonProtocolFilter protocolFilter = JsonProtocolFilter.fromRawFilters(filters); - PotentialCoderFilter class2Filters = new PotentialCoderFilter(aClass, protocolFilter); + PotentialCoderFilter class2Filters = new PotentialCoderFilter(theClass, protocolFilter); classes2Filters.add(class2Filters); continue; } @@ -330,12 +390,12 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } JsonProtocolFilter protocolFilter = JsonProtocolFilter.fromRawFilters(filters); - PotentialCoderFilter class2Filters = new PotentialCoderFilter(aClass, protocolFilter); + PotentialCoderFilter class2Filters = new PotentialCoderFilter(theClass, protocolFilter); classes2Filters.add(class2Filters); } TopicCoderFilterConfiguration topic2Classes2Filters = - new TopicCoderFilterConfiguration(aTopic, classes2Filters, customGsonCoder, customJacksonCoder); + new TopicCoderFilterConfiguration(firstTopic, classes2Filters, customGsonCoder, customJacksonCoder); topics2DecodedClasses2Filters.add(topic2Classes2Filters); } @@ -343,64 +403,6 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } @Override - public DroolsController build(String newGroupId, String newArtifactId, String newVersion, - List<TopicCoderFilterConfiguration> decoderConfigurations, - List<TopicCoderFilterConfiguration> encoderConfigurations) throws LinkageError { - - if (newGroupId == null || newGroupId.isEmpty()) { - throw new IllegalArgumentException("Missing maven group-id coordinate"); - } - - if (newArtifactId == null || newArtifactId.isEmpty()) { - throw new IllegalArgumentException("Missing maven artifact-id coordinate"); - } - - if (newVersion == null || newVersion.isEmpty()) { - throw new IllegalArgumentException("Missing maven version coordinate"); - } - - String controllerId = newGroupId + ":" + newArtifactId; - DroolsController controllerCopy = null; - synchronized (this) { - /* - * The Null Drools Controller for no maven coordinates is always here so when no - * coordinates present, this is the return point - * - * assert (controllerCopy instanceof NullDroolsController) - */ - if (droolsControllers.containsKey(controllerId)) { - controllerCopy = droolsControllers.get(controllerId); - if (controllerCopy.getVersion().equalsIgnoreCase(newVersion)) { - return controllerCopy; - } - } - } - - if (controllerCopy != null) { - /* - * a controller keyed by group id + artifact id exists but with different version => - * version upgrade/downgrade - */ - - controllerCopy.updateToVersion(newGroupId, newArtifactId, newVersion, decoderConfigurations, - encoderConfigurations); - - return controllerCopy; - } - - /* new drools controller */ - - DroolsController controller = new MavenDroolsController(newGroupId, newArtifactId, newVersion, - decoderConfigurations, encoderConfigurations); - - synchronized (this) { - droolsControllers.put(controllerId, controller); - } - - return controller; - } - - @Override public void destroy(DroolsController controller) { unmanage(controller); controller.halt(); @@ -419,11 +421,9 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } /** - * unmanage the drools controller + * unmanage the drools controller. * - * @param controller - * @return - * @throws IllegalArgumentException + * @param controller the controller */ protected void unmanage(DroolsController controller) { if (controller == null) { |