diff options
Diffstat (limited to 'policy-management')
22 files changed, 439 insertions, 476 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java index f531c441..bdb95e77 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -51,6 +51,12 @@ public interface DroolsController extends Startable, Lockable { public static final String NO_VERSION = "NO-VERSION"; /** + * Factory to track and manage drools controllers + */ + public static final DroolsControllerFactory factory = + new IndexedDroolsControllerFactory(); + + /** * get group id * @return group id */ @@ -106,9 +112,7 @@ public interface DroolsController extends Startable, Lockable { * to the functionality missing (ie. communication infrastructure * not supported. */ - public boolean deliver(TopicSink sink, Object event) - throws IllegalArgumentException, IllegalStateException, - UnsupportedOperationException; + public boolean deliver(TopicSink sink, Object event); /** * @@ -133,7 +137,7 @@ public interface DroolsController extends Startable, Lockable { * @param encodedObject * @return */ - public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) throws IllegalStateException; + public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash); /** * fetches a class from the model @@ -141,7 +145,7 @@ public interface DroolsController extends Startable, Lockable { * @param className the class to fetch * @return the actual class object, or null if not found */ - public Class<?> fetchModelClass(String className) throws IllegalArgumentException; + public Class<?> fetchModelClass(String className); /** * is this controller Smart? @@ -164,14 +168,14 @@ public interface DroolsController extends Startable, Lockable { public void updateToVersion(String newGroupId, String newArtifactId, String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations, List<TopicCoderFilterConfiguration> encoderConfigurations) - throws IllegalArgumentException, LinkageError; + throws LinkageError; /** * gets the classnames of facts as well as the current count * @param sessionName the session name * @return map of class to count */ - public Map<String,Integer> factClassNames(String sessionName) throws IllegalArgumentException; + public Map<String,Integer> factClassNames(String sessionName); /** * gets the count of facts for a given session @@ -179,7 +183,7 @@ public interface DroolsController extends Startable, Lockable { * @return the fact count * @throws IllegalArgumentException */ - public long factCount(String sessionName) throws IllegalArgumentException; + public long factCount(String sessionName); /** * gets all the facts of a given class for a given session @@ -208,11 +212,5 @@ public interface DroolsController extends Startable, Lockable { * halts and permanently releases all resources * @throws IllegalStateException */ - public void halt() throws IllegalStateException; - - /** - * Factory to track and manage drools controllers - */ - public static final DroolsControllerFactory factory = - new IndexedDroolsControllerFactory(); + public void halt(); } 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 0b9f9887..65c9f334 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -207,7 +207,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { protected List<TopicCoderFilterConfiguration> codersAndFilters (Properties properties, List<? extends Topic> topicEntities) { - String PROPERTY_TOPIC_ENTITY_PREFIX; + String propertyTopicEntityPrefix; List<TopicCoderFilterConfiguration> topics2DecodedClasses2Filters = new ArrayList<>(); @@ -222,19 +222,19 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { CommInfrastructure commInfra = topic.getTopicCommInfrastructure(); if (commInfra == CommInfrastructure.UEB) { if (isSource) { - PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + "."; + propertyTopicEntityPrefix = PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + "."; } else { - PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "."; + propertyTopicEntityPrefix = PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "."; } } else if (commInfra == CommInfrastructure.DMAAP) { if (isSource) { - PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "."; + propertyTopicEntityPrefix = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "."; } else { - PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + "."; + propertyTopicEntityPrefix = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + "."; } } else if (commInfra == CommInfrastructure.NOOP) { if (!isSource) - PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_NOOP_SINK_TOPICS + "."; + propertyTopicEntityPrefix = PolicyProperties.PROPERTY_NOOP_SINK_TOPICS + "."; else continue; } else { @@ -249,7 +249,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { // instead of the ones provided in the platform String customGson = properties.getProperty - (PROPERTY_TOPIC_ENTITY_PREFIX + + (propertyTopicEntityPrefix + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_GSON_SUFFIX); @@ -264,7 +264,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } String customJackson = properties.getProperty - (PROPERTY_TOPIC_ENTITY_PREFIX + + (propertyTopicEntityPrefix + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_JACKSON_SUFFIX); @@ -281,7 +281,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { // 3. second the list of classes associated with each topic String eventClasses = - properties.getProperty(PROPERTY_TOPIC_ENTITY_PREFIX + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX); + properties.getProperty(propertyTopicEntityPrefix + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX); if (eventClasses == null || eventClasses.isEmpty()) { // TODO warn @@ -299,7 +299,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { // 4. third, for each coder class, get the list of field filters String filter = properties.getProperty - (PROPERTY_TOPIC_ENTITY_PREFIX + + (propertyTopicEntityPrefix + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX + "." + aClass + @@ -509,9 +509,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { @Override public List<DroolsController> inventory() { - List<DroolsController> controllers = - new ArrayList<>(this.droolsControllers.values()); - return controllers; + return new ArrayList<>(this.droolsControllers.values()); } @Override 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 8a0073c0..1901526c 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -251,11 +251,10 @@ public class MavenDroolsController implements DroolsController { String customGsonCoderClass = coderConfig.getCustomGsonCoder().getClassContainer(); if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), customGsonCoderClass)) { - logger.error(customGsonCoderClass + " cannot be retrieved"); - throw new IllegalArgumentException(customGsonCoderClass + " cannot be retrieved"); + throw makeRetrieveEx(customGsonCoderClass); } else { if (logger.isInfoEnabled()) - logger.info("CLASS FETCHED " + customGsonCoderClass); + logClassFetched(customGsonCoderClass); } } @@ -267,11 +266,10 @@ public class MavenDroolsController implements DroolsController { String customJacksonCoderClass = coderConfig.getCustomJacksonCoder().getClassContainer(); if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), customJacksonCoderClass)) { - logger.error(customJacksonCoderClass + " cannot be retrieved"); - throw new IllegalArgumentException(customJacksonCoderClass + " cannot be retrieved"); + throw makeRetrieveEx(customJacksonCoderClass); } else { if (logger.isInfoEnabled()) - logger.info("CLASS FETCHED " + customJacksonCoderClass); + logClassFetched(customJacksonCoderClass); } } @@ -286,11 +284,10 @@ public class MavenDroolsController implements DroolsController { if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), potentialCodedClass)) { - logger.error(potentialCodedClass + " cannot be retrieved"); - throw new IllegalArgumentException(potentialCodedClass + " cannot be retrieved"); + throw makeRetrieveEx(potentialCodedClass); } else { if (logger.isInfoEnabled()) - logger.info("CLASS FETCHED " + potentialCodedClass); + logClassFetched(potentialCodedClass); } if (decoder) @@ -309,6 +306,24 @@ public class MavenDroolsController implements DroolsController { } } + /** + * Logs an error and makes an exception for an item that cannot be retrieved. + * @param itemName + * @return a new exception + */ + private IllegalArgumentException makeRetrieveEx(String itemName) { + logger.error(itemName + " cannot be retrieved"); + return new IllegalArgumentException(itemName + " cannot be retrieved"); + } + + /** + * Logs the name of the class that was fetched. + * @param className + */ + private void logClassFetched(String className) { + logger.info("CLASS FETCHED " + className); + } + /** * remove decoders. @@ -521,8 +536,7 @@ public class MavenDroolsController implements DroolsController { } @Override - public boolean deliver(TopicSink sink, Object event) - throws UnsupportedOperationException { + public boolean deliver(TopicSink sink, Object event) { if (logger.isInfoEnabled()) logger.info(this + "DELIVER: " + event + " FROM " + this + " TO " + sink); @@ -665,13 +679,17 @@ public class MavenDroolsController implements DroolsController { return session; } - throw new IllegalArgumentException("Invalid Session Name: " + sessionName); + throw invalidSessNameEx(sessionName); + } + + private IllegalArgumentException invalidSessNameEx(String sessionName) { + return new IllegalArgumentException("Invalid Session Name: " + sessionName); } @Override public Map<String,Integer> factClassNames(String sessionName) { if (sessionName == null || sessionName.isEmpty()) - throw new IllegalArgumentException("Invalid Session Name: " + sessionName); + throw invalidSessNameEx(sessionName); Map<String,Integer> classNames = new HashMap<>(); @@ -697,7 +715,7 @@ public class MavenDroolsController implements DroolsController { @Override public long factCount(String sessionName) { if (sessionName == null || sessionName.isEmpty()) - throw new IllegalArgumentException("Invalid Session Name: " + sessionName); + throw invalidSessNameEx(sessionName); PolicySession session = getSession(sessionName); return session.getKieSession().getFactCount(); @@ -706,7 +724,7 @@ public class MavenDroolsController implements DroolsController { @Override public List<Object> facts(String sessionName, String className, boolean delete) { if (sessionName == null || sessionName.isEmpty()) - throw new IllegalArgumentException("Invalid Session Name: " + sessionName); + throw invalidSessNameEx(sessionName); if (className == null || className.isEmpty()) throw new IllegalArgumentException("Invalid Class Name: " + className); @@ -738,7 +756,7 @@ public class MavenDroolsController implements DroolsController { @Override public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, boolean delete, Object... queryParams) { if (sessionName == null || sessionName.isEmpty()) - throw new IllegalArgumentException("Invalid Session Name: " + sessionName); + throw invalidSessNameEx(sessionName); if (queryName == null || queryName.isEmpty()) throw new IllegalArgumentException("Invalid Query Name: " + queryName); @@ -779,9 +797,7 @@ public class MavenDroolsController implements DroolsController { @Override public Class<?> fetchModelClass(String className) { - Class<?> modelClass = - ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className); - return modelClass; + return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className); } /** diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java index 6dd542c3..245b0b58 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -106,8 +106,8 @@ public class NullDroolsController implements DroolsController { } @Override - public boolean deliver(TopicSink sink, Object event) throws UnsupportedOperationException { - throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked"); + public boolean deliver(TopicSink sink, Object event) { + throw new IllegalStateException(makeInvokeMsg()); } @Override @@ -127,12 +127,12 @@ public class NullDroolsController implements DroolsController { @Override public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) { - throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked"); + throw new IllegalStateException(makeInvokeMsg()); } @Override public Class<?> fetchModelClass(String className) { - throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); + throw new IllegalArgumentException(makeInvokeMsg()); } @Override @@ -151,13 +151,12 @@ public class NullDroolsController implements DroolsController { public void updateToVersion(String newGroupId, String newArtifactId, String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations, List<TopicCoderFilterConfiguration> encoderConfigurations) - throws IllegalArgumentException, LinkageError { - throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); + throws LinkageError { + throw new IllegalArgumentException(makeInvokeMsg()); } @Override - public Map<String, Integer> factClassNames(String sessionName) - throws IllegalArgumentException { + public Map<String, Integer> factClassNames(String sessionName) { return new HashMap<>(); } @@ -177,4 +176,8 @@ public class NullDroolsController implements DroolsController { boolean delete, Object... queryParams) { return new ArrayList<>(); } + + private String makeInvokeMsg() { + return this.getClass().getCanonicalName() + " invoked"; + } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java index 9d166f58..d4ebc232 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java +++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -28,6 +28,12 @@ import org.onap.policy.drools.utils.OrderedService; import org.onap.policy.drools.utils.OrderedServiceImpl; public interface PolicyControllerFeatureAPI extends OrderedService { + + /** + * Feature providers implementing this interface + */ + public static final OrderedServiceImpl<PolicyControllerFeatureAPI> providers = + new OrderedServiceImpl<PolicyControllerFeatureAPI>(PolicyControllerFeatureAPI.class); /** * called before creating a controller with name 'name' and @@ -212,11 +218,4 @@ public interface PolicyControllerFeatureAPI extends OrderedService { String topic, Object event, boolean success) {return false;} - - - /** - * Feature providers implementing this interface - */ - public static final OrderedServiceImpl<PolicyControllerFeatureAPI> providers = - new OrderedServiceImpl<PolicyControllerFeatureAPI>(PolicyControllerFeatureAPI.class); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java index eb65c706..956401ad 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java +++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-engine * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -30,7 +30,12 @@ import org.onap.policy.drools.utils.OrderedServiceImpl; * Policy Engine Feature API. * Provides Interception Points during the Policy Engine lifecycle. */ -public interface PolicyEngineFeatureAPI extends OrderedService { +public interface PolicyEngineFeatureAPI extends OrderedService { + /** + * Feature providers implementing this interface + */ + public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers = + new OrderedServiceImpl<>(PolicyEngineFeatureAPI.class); /** * intercept before the Policy Engine is commanded to boot. @@ -39,7 +44,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public default boolean beforeBoot(PolicyEngine engine, String cliArgs[]) {return false;}; + public default boolean beforeBoot(PolicyEngine engine, String[] cliArgs) {return false;}; /** * intercept after the Policy Engine is booted. @@ -193,10 +198,4 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * lower priority features. False, otherwise. */ public default boolean afterShutdown(PolicyEngine engine) {return false;}; - - /** - * Feature providers implementing this interface - */ - public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers = - new OrderedServiceImpl<>(PolicyEngineFeatureAPI.class); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java index b436ef97..45c5c428 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java +++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -43,29 +43,29 @@ public class FileSystemPersistence implements SystemPersistence { /** * policy controllers suffix */ - public final static String CONTROLLER_SUFFIX_IDENTIFIER = "-controller"; + public static final String CONTROLLER_SUFFIX_IDENTIFIER = "-controller"; /** * policy controller properties file suffix */ - public final static String PROPERTIES_FILE_CONTROLLER_SUFFIX = + public static final String PROPERTIES_FILE_CONTROLLER_SUFFIX = CONTROLLER_SUFFIX_IDENTIFIER + ".properties"; /** * policy controller properties file suffix */ - public final static String PROPERTIES_FILE_CONTROLLER_BACKUP_SUFFIX = + public static final String PROPERTIES_FILE_CONTROLLER_BACKUP_SUFFIX = CONTROLLER_SUFFIX_IDENTIFIER + ".properties.bak"; /** * policy engine properties file name */ - public final static String PROPERTIES_FILE_ENGINE = "policy-engine.properties"; + public static final String PROPERTIES_FILE_ENGINE = "policy-engine.properties"; /** * Installation environment suffix for files */ - public final static String ENV_SUFFIX = ".environment"; + public static final String ENV_SUFFIX = ".environment"; /** * configuration directory diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java index eb1521ba..0d0a33ce 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java +++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -34,6 +34,12 @@ public interface SystemPersistence { public static final String DEFAULT_CONFIGURATION_DIR = "config"; /** + * Persistence Manager. For now it is a file-based properties management, In the future, it will + * probably be DB based, so manager implementation will change. + */ + public static final SystemPersistence manager = new FileSystemPersistence(); + + /** * sets a configuration directory and ensures it exists * * @param configDir configuration directory or null to use the default one @@ -123,10 +129,4 @@ public interface SystemPersistence { * @throws IllegalArgumentException if the name does not lead to a properties configuration */ public Properties getProperties(String name); - - /** - * Persistence Manager. For now it is a file-based properties management, In the future, it will - * probably be DB based, so manager implementation will change. - */ - public static final SystemPersistence manager = new FileSystemPersistence(); } 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 54466775..d0008f08 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * ONAP * ================================================================================ @@ -39,6 +39,11 @@ import org.slf4j.LoggerFactory; */ public interface EventProtocolCoder { + /** + * singleton reference to the global event protocol coder + */ + public static EventProtocolCoder manager = new MultiplexorEventProtocolCoder(); + public static class CoderFilters { /** @@ -133,8 +138,7 @@ public interface EventProtocolCoder { JsonProtocolFilter protocolFilter, CustomGsonCoder customGsonCoder, CustomJacksonCoder customJacksonCoder, - int modelClassLoaderHash) - throws IllegalArgumentException; + int modelClassLoaderHash); /** * removes all decoders associated with the controller id @@ -144,7 +148,7 @@ public interface EventProtocolCoder { * * @throws IllegalArgumentException if invalid arguments have been provided */ - void removeEncoders(String groupId, String artifactId, String topic) throws IllegalArgumentException; + void removeEncoders(String groupId, String artifactId, String topic); /** * removes decoders associated with the controller id and topic @@ -154,7 +158,7 @@ public interface EventProtocolCoder { * * @throws IllegalArgumentException if invalid arguments have been provided */ - public void removeDecoders(String groupId, String artifactId, String topic) throws IllegalArgumentException; + public void removeDecoders(String groupId, String artifactId, String topic); /** * Given a controller id and a topic, it gives back its filters @@ -167,8 +171,7 @@ public interface EventProtocolCoder { * * @throw IllegalArgumentException if an invalid parameter is passed */ - public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic) - throws IllegalArgumentException; + public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic); /** @@ -182,8 +185,7 @@ public interface EventProtocolCoder { * * @throw IllegalArgumentException if an invalid parameter is passed */ - public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) - throws IllegalArgumentException; + public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic); /** * Given a controller id and a topic, it gives back all the decoding configurations @@ -196,8 +198,7 @@ public interface EventProtocolCoder { * * @throw IllegalArgumentException if an invalid parameter is passed */ - public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId) - throws IllegalArgumentException; + public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId); /** @@ -207,7 +208,7 @@ public interface EventProtocolCoder { * * @throws IllegalArgumentException if invalid arguments have been provided */ - public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) throws IllegalArgumentException; + public List<CoderFilters> getDecoderFilters(String groupId, String artifactId); /** @@ -221,8 +222,7 @@ public interface EventProtocolCoder { * * @throw IllegalArgumentException if an invalid parameter is passed */ - public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic) - throws IllegalArgumentException; + public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic); /** * gets all encoders associated with the group and artifact ids @@ -231,7 +231,7 @@ public interface EventProtocolCoder { * * @throws IllegalArgumentException if invalid arguments have been provided */ - public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) throws IllegalArgumentException; + public List<CoderFilters> getEncoderFilters(String groupId, String artifactId); /** * Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding @@ -245,8 +245,7 @@ public interface EventProtocolCoder { * * @throw IllegalArgumentException if an invalid parameter is passed */ - public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) - throws IllegalArgumentException; + public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname); /** * is there a decoder supported for the controller id and topic @@ -275,8 +274,7 @@ public interface EventProtocolCoder { JsonProtocolFilter protocolFilter, CustomGsonCoder customGsonCoder, CustomJacksonCoder customJacksonCoder, - int modelClassLoaderHash) - throws IllegalArgumentException; + int modelClassLoaderHash); /** * is there an encoder supported for the controller id and topic @@ -298,8 +296,7 @@ public interface EventProtocolCoder { * @return * @throws IllegalArgumentException invalid arguments passed in */ - public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) - throws IllegalArgumentException; + public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname); /** * get encoder based on topic and encoded class @@ -309,8 +306,7 @@ public interface EventProtocolCoder { * @return * @throws IllegalArgumentException invalid arguments passed in */ - public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass) - throws IllegalArgumentException; + public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass); /** * gets the identifier of the creator of the encoder @@ -320,8 +316,7 @@ public interface EventProtocolCoder { * @return a drools controller * @throws IllegalArgumentException invalid arguments passed in */ - public DroolsController getDroolsController(String topic, Object encodedClass) - throws IllegalArgumentException; + public DroolsController getDroolsController(String topic, Object encodedClass); /** * gets the identifier of the creator of the encoder @@ -331,8 +326,7 @@ public interface EventProtocolCoder { * @return list of drools controllers * @throws IllegalArgumentException invalid arguments passed in */ - public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) - throws IllegalArgumentException; + public List<DroolsController> getDroolsControllers(String topic, Object encodedClass); /** * decode topic's stringified event (json) to corresponding Event Object. @@ -346,8 +340,7 @@ public interface EventProtocolCoder { * @throws UnsupportedOperationException if the operation is not supported * @throws IllegalStateException if the system is in an illegal state */ - public Object decode(String groupId, String artifactId, String topic, String json) - throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException; + public Object decode(String groupId, String artifactId, String topic, String json); /** * encodes topic's stringified event (json) to corresponding Event Object. @@ -359,8 +352,7 @@ public interface EventProtocolCoder { * * @throws IllegalArgumentException invalid arguments passed in */ - public String encode(String groupId, String artifactId, String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + public String encode(String groupId, String artifactId, String topic, Object event); /** * encodes topic's stringified event (json) to corresponding Event Object. @@ -371,8 +363,7 @@ public interface EventProtocolCoder { * @throws IllegalArgumentException invalid arguments passed in * @throws UnsupportedOperationException operation cannot be performed */ - public String encode(String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + public String encode(String topic, Object event); /** * encodes topic's stringified event (json) to corresponding Event Object. @@ -384,13 +375,7 @@ public interface EventProtocolCoder { * @throws IllegalArgumentException invalid arguments passed in * @throws UnsupportedOperationException operation cannot be performed */ - public String encode(String topic, Object event, DroolsController droolsController) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; - - /** - * singleton reference to the global event protocol coder - */ - public static EventProtocolCoder manager = new MultiplexorEventProtocolCoder(); + public String encode(String topic, Object event, DroolsController droolsController); } /** @@ -423,8 +408,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { JsonProtocolFilter protocolFilter, CustomGsonCoder customGsonCoder, CustomJacksonCoder customJacksonCoder, - int modelClassLoaderHash) - throws IllegalArgumentException { + int modelClassLoaderHash) { logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this, groupId, artifactId, topic, eventClass, protocolFilter, customGsonCoder, customJacksonCoder, @@ -442,8 +426,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { JsonProtocolFilter protocolFilter, CustomGsonCoder customGsonCoder, CustomJacksonCoder customJacksonCoder, - int modelClassLoaderHash) - throws IllegalArgumentException { + int modelClassLoaderHash) { logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this, groupId, artifactId, topic, eventClass, protocolFilter, customGsonCoder, customJacksonCoder, @@ -456,8 +439,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public void removeDecoders(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public void removeDecoders(String groupId, String artifactId, String topic) { logger.info("{}: remove-decoder {}:{}:{}", this, groupId, artifactId, topic); this.decoders.remove(groupId, artifactId, topic); } @@ -466,8 +448,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public void removeEncoders(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public void removeEncoders(String groupId, String artifactId, String topic) { logger.info("{}: remove-encoder {}:{}:{}", this, groupId, artifactId, topic); this.encoders.remove(groupId, artifactId, topic); } @@ -492,8 +473,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public Object decode(String groupId, String artifactId, String topic, String json) - throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + public Object decode(String groupId, String artifactId, String topic, String json) { logger.debug("{}: decode {}:{}:{}:{}", this, groupId, artifactId, topic, json); return this.decoders.decode(groupId, artifactId, topic, json); } @@ -502,8 +482,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public String encode(String groupId, String artifactId, String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public String encode(String groupId, String artifactId, String topic, Object event) { logger.debug("{}: encode {}:{}:{}:{}", this, groupId, artifactId, topic, event); return this.encoders.encode(groupId, artifactId, topic, event); } @@ -512,8 +491,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public String encode(String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public String encode(String topic, Object event) { logger.debug("{}: encode {}:{}", this, topic, event); return this.encoders.encode(topic, event); } @@ -522,8 +500,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public String encode(String topic, Object event, DroolsController droolsController) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public String encode(String topic, Object event, DroolsController droolsController) { logger.debug("{}: encode {}:{}:{}", this, topic, event, droolsController); return this.encoders.encode(topic, event, droolsController); } @@ -532,8 +509,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic) { return this.decoders.getFilters(groupId, artifactId, topic); } @@ -541,8 +517,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) { Pair<ProtocolCoderToolset,ProtocolCoderToolset> decoderToolsets = this.decoders.getCoders(groupId, artifactId, topic); if (decoderToolsets == null) throw new IllegalArgumentException("Decoders not found for " + groupId + ":" + artifactId + ":" + topic); @@ -554,8 +529,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic) { return this.encoders.getFilters(groupId, artifactId, topic); } @@ -563,8 +537,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) - throws IllegalArgumentException { + public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) { return this.decoders.getFilters(groupId, artifactId, topic, classname); } @@ -572,8 +545,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) - throws IllegalArgumentException { + public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) { return this.encoders.getFilters(groupId, artifactId, topic, classname); } @@ -581,7 +553,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass) throws IllegalArgumentException { + public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass) { return this.encoders.getReverseFilters(topic, encodedClass); } @@ -595,8 +567,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * @throws IllegalArgumentException if invalid input */ @Override - public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId) - throws IllegalArgumentException { + public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId) { List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> decoderToolsets = this.decoders.getCoders(groupId, artifactId); if (decoderToolsets == null) @@ -614,7 +585,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) throws IllegalArgumentException { + public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) { return this.decoders.getFilters(groupId, artifactId); } @@ -623,7 +594,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) throws IllegalArgumentException { + public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) { return this.encoders.getFilters(groupId, artifactId); } @@ -631,7 +602,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public DroolsController getDroolsController(String topic, Object encodedClass) throws IllegalArgumentException { + public DroolsController getDroolsController(String topic, Object encodedClass) { return this.encoders.getDroolsController(topic, encodedClass); } @@ -639,7 +610,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * {@inheritDoc} */ @Override - public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) throws IllegalArgumentException { + public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) { return this.encoders.getDroolsControllers(topic, encodedClass); } @@ -660,6 +631,16 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { * class and best fitted json parsing tools. */ abstract class GenericEventProtocolCoder { + private static final String INVALID_ARTIFACT_ID_MSG = "Invalid artifact id"; + + private static final String INVALID_GROUP_ID_MSG = "Invalid group id"; + + private static final String INVALID_TOPIC_MSG = "Invalid Topic"; + + private static final String UNSUPPORTED_MSG = "Unsupported"; + + private static final String MISSING_CLASS = "class must be provided"; + private static Logger logger = LoggerFactory.getLogger(GenericEventProtocolCoder.class); /** @@ -702,17 +683,16 @@ abstract class GenericEventProtocolCoder { JsonProtocolFilter protocolFilter, CustomGsonCoder customGsonCoder, CustomJacksonCoder customJacksonCoder, - int modelClassLoaderHash) - throws IllegalArgumentException { + int modelClassLoaderHash) { if (groupId == null || groupId.isEmpty()) { - throw new IllegalArgumentException("Invalid group id"); + throw new IllegalArgumentException(INVALID_GROUP_ID_MSG); } if (artifactId == null || artifactId.isEmpty()) - throw new IllegalArgumentException("Invalid artifact id"); + throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG); if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Invalid Topic"); + throw new IllegalArgumentException(INVALID_TOPIC_MSG); if (eventClass == null) { throw new IllegalArgumentException("Invalid Event Class"); @@ -841,17 +821,16 @@ abstract class GenericEventProtocolCoder { * @param topic topic * @throws IllegalArgumentException if invalid input */ - public void remove(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public void remove(String groupId, String artifactId, String topic) { if (groupId == null || groupId.isEmpty()) - throw new IllegalArgumentException("Invalid group id"); + throw new IllegalArgumentException(INVALID_GROUP_ID_MSG); if (artifactId == null || artifactId.isEmpty()) - throw new IllegalArgumentException("Invalid artifact id"); + throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG); if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Invalid Topic"); + throw new IllegalArgumentException(INVALID_TOPIC_MSG); String key = this.codersKey(groupId, artifactId, topic); @@ -899,13 +878,13 @@ abstract class GenericEventProtocolCoder { public boolean isCodingSupported(String groupId, String artifactId, String topic) { if (groupId == null || groupId.isEmpty()) - throw new IllegalArgumentException("Invalid group id"); + throw new IllegalArgumentException(INVALID_GROUP_ID_MSG); if (artifactId == null || artifactId.isEmpty()) - throw new IllegalArgumentException("Invalid artifact id"); + throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG); if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Invalid Topic"); + throw new IllegalArgumentException(INVALID_TOPIC_MSG); String key = this.codersKey(groupId, artifactId, topic); synchronized(this) { @@ -924,8 +903,7 @@ abstract class GenericEventProtocolCoder { * @throws IllegalArgumentException if invalid argument is provided * @throws UnsupportedOperationException if the operation cannot be performed */ - public Object decode(String groupId, String artifactId, String topic, String json) - throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + public Object decode(String groupId, String artifactId, String topic, String json) { if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic) + " for encoding"); @@ -974,8 +952,7 @@ abstract class GenericEventProtocolCoder { * @throws IllegalArgumentException if invalid argument is provided * @throws UnsupportedOperationException if the operation cannot be performed */ - public String encode(String groupId, String artifactId, String topic, Object event) - throws IllegalArgumentException, UnsupportedOperationException { + public String encode(String groupId, String artifactId, String topic, Object event) { if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException @@ -998,8 +975,7 @@ abstract class GenericEventProtocolCoder { * @throws IllegalArgumentException if invalid argument is provided * @throws UnsupportedOperationException if the operation cannot be performed */ - protected String encodeInternal(String key, Object event) - throws IllegalArgumentException, UnsupportedOperationException { + protected String encodeInternal(String key, Object event) { logger.debug("{}: encode for {}: {}", this, key, event); @@ -1045,8 +1021,7 @@ abstract class GenericEventProtocolCoder { * @throws IllegalArgumentException if invalid argument is provided * @throws UnsupportedOperationException if the operation cannot be performed */ - public String encode(String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public String encode(String topic, Object event) { if (event == null) throw new IllegalArgumentException("Invalid encoded class"); @@ -1074,8 +1049,7 @@ abstract class GenericEventProtocolCoder { * @throws IllegalArgumentException if invalid argument is provided * @throws UnsupportedOperationException if the operation cannot be performed */ - public String encode(String topic, Object encodedClass, DroolsController droolsController) - throws IllegalArgumentException, IllegalArgumentException, UnsupportedOperationException { + public String encode(String topic, Object encodedClass, DroolsController droolsController) { if (encodedClass == null) throw new IllegalArgumentException("Invalid encoded class"); @@ -1095,8 +1069,7 @@ abstract class GenericEventProtocolCoder { * @throws IllegalStateException * @throws IllegalArgumentException */ - protected List<DroolsController> droolsCreators(String topic, Object encodedClass) - throws IllegalStateException, IllegalArgumentException { + protected List<DroolsController> droolsCreators(String topic, Object encodedClass) { List<DroolsController> droolsControllers = new ArrayList<>(); @@ -1152,8 +1125,7 @@ abstract class GenericEventProtocolCoder { * @return list of coders * @throws IllegalArgumentException if invalid input */ - public List<CoderFilters> getFilters(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public List<CoderFilters> getFilters(String groupId, String artifactId, String topic) { if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); @@ -1172,15 +1144,13 @@ abstract class GenericEventProtocolCoder { * @return list of coders * @throws IllegalArgumentException if invalid input */ - public Pair<ProtocolCoderToolset,ProtocolCoderToolset> getCoders(String groupId, String artifactId, String topic) - throws IllegalArgumentException { + public Pair<ProtocolCoderToolset,ProtocolCoderToolset> getCoders(String groupId, String artifactId, String 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); - return coderTools; + return coders.get(key); } /** @@ -1191,14 +1161,13 @@ abstract class GenericEventProtocolCoder { * @return list of coders * @throws IllegalArgumentException if invalid input */ - public List<CoderFilters> getFilters(String groupId, String artifactId) - throws IllegalArgumentException { + public List<CoderFilters> getFilters(String groupId, String artifactId) { if (groupId == null || groupId.isEmpty()) - throw new IllegalArgumentException("Invalid group id"); + throw new IllegalArgumentException(INVALID_GROUP_ID_MSG); if (artifactId == null || artifactId.isEmpty()) - throw new IllegalArgumentException("Invalid artifact id"); + throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG); String key = this.codersKey(groupId, artifactId, ""); @@ -1220,14 +1189,13 @@ abstract class GenericEventProtocolCoder { * @return list of coders * @throws IllegalArgumentException if invalid input */ - public List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> getCoders(String groupId, String artifactId) - throws IllegalArgumentException { + public List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> getCoders(String groupId, String artifactId) { if (groupId == null || groupId.isEmpty()) - throw new IllegalArgumentException("Invalid group id"); + throw new IllegalArgumentException(INVALID_GROUP_ID_MSG); if (artifactId == null || artifactId.isEmpty()) - throw new IllegalArgumentException("Invalid artifact id"); + throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG); String key = this.codersKey(groupId, artifactId, ""); @@ -1252,8 +1220,7 @@ abstract class GenericEventProtocolCoder { * @return list of coders * @throws IllegalArgumentException if invalid input */ - public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) - throws IllegalArgumentException { + public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) { if (!isCodingSupported(groupId, artifactId, topic)) throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); @@ -1274,14 +1241,13 @@ abstract class GenericEventProtocolCoder { * @return * @throws IllegalArgumentException */ - public List<CoderFilters> getReverseFilters(String topic, String codedClass) - throws IllegalArgumentException { + public List<CoderFilters> getReverseFilters(String topic, String codedClass) { if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Unsupported"); + throw new IllegalArgumentException(UNSUPPORTED_MSG); if (codedClass == null) - throw new IllegalArgumentException("class must be provided"); + throw new IllegalArgumentException(MISSING_CLASS); String key = this.reverseCodersKey(topic, codedClass); List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> toolsets = this.reverseCoders.get(key); @@ -1305,14 +1271,13 @@ abstract class GenericEventProtocolCoder { * @return * @throws IllegalArgumentException */ - DroolsController getDroolsController(String topic, Object fact) - throws IllegalArgumentException { + DroolsController getDroolsController(String topic, Object fact) { if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Unsupported"); + throw new IllegalArgumentException(UNSUPPORTED_MSG); if (fact == null) - throw new IllegalArgumentException("class must be provided"); + throw new IllegalArgumentException(MISSING_CLASS); List<DroolsController> droolsControllers = droolsCreators(topic, fact); @@ -1335,14 +1300,13 @@ abstract class GenericEventProtocolCoder { * @return * @throws IllegalArgumentException */ - List<DroolsController> getDroolsControllers(String topic, Object fact) - throws IllegalArgumentException { + List<DroolsController> getDroolsControllers(String topic, Object fact) { if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Unsupported"); + throw new IllegalArgumentException(UNSUPPORTED_MSG); if (fact == null) - throw new IllegalArgumentException("class must be provided"); + throw new IllegalArgumentException(MISSING_CLASS); List<DroolsController> droolsControllers = droolsCreators(topic, fact); if (droolsControllers.size() > 1) { diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java index c5f82a47..a5902d66 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * ONAP * ================================================================================ @@ -37,6 +37,7 @@ import com.google.gson.JsonParser; */ public class JsonProtocolFilter { + private static final String MISSING_RULE_NAME = "no rule name provided"; /** * Logger */ @@ -128,35 +129,11 @@ public class JsonProtocolFilter { protected List<FilterRule> rules = new CopyOnWriteArrayList<>(); /** - * - * @param rawFilters raw filter initialization - * - * @throws IllegalArgumentException an invalid input has been provided - */ - public static JsonProtocolFilter fromRawFilters(List<Pair<String, String>> rawFilters) - throws IllegalArgumentException { - - if (rawFilters == null) { - throw new IllegalArgumentException("No raw filters provided"); - } - - List<FilterRule> filters = new ArrayList<>(); - for (Pair<String, String> filterPair: rawFilters) { - if (filterPair.first() == null || filterPair.first().isEmpty()) { - continue; - } - - filters.add(new FilterRule(filterPair.first(), filterPair.second())); - } - return new JsonProtocolFilter(filters); - } - - /** * Create a Protocol Filter * * @throws IllegalArgumentException an invalid input has been provided */ - public JsonProtocolFilter() throws IllegalArgumentException {} + public JsonProtocolFilter() {} /** * @@ -164,7 +141,7 @@ public class JsonProtocolFilter { * * @throws IllegalArgumentException an invalid input has been provided */ - public JsonProtocolFilter(List<FilterRule> filters) throws IllegalArgumentException { + public JsonProtocolFilter(List<FilterRule> filters) { List<FilterRule> temp = new ArrayList<>(); for (FilterRule rule : filters) { if (rule.getName() == null || rule.getName().isEmpty()) { @@ -180,6 +157,29 @@ public class JsonProtocolFilter { this.rules.addAll(temp); } + + /** + * + * @param rawFilters raw filter initialization + * + * @throws IllegalArgumentException an invalid input has been provided + */ + public static JsonProtocolFilter fromRawFilters(List<Pair<String, String>> rawFilters) { + + if (rawFilters == null) { + throw new IllegalArgumentException("No raw filters provided"); + } + + List<FilterRule> filters = new ArrayList<>(); + for (Pair<String, String> filterPair: rawFilters) { + if (filterPair.first() == null || filterPair.first().isEmpty()) { + continue; + } + + filters.add(new FilterRule(filterPair.first(), filterPair.second())); + } + return new JsonProtocolFilter(filters); + } /** * are there any filters? @@ -198,7 +198,7 @@ public class JsonProtocolFilter { * * @throws IllegalArgumentException an invalid input has been provided */ - public boolean accept(JsonElement json) throws IllegalArgumentException { + public boolean accept(JsonElement json) { if (json == null) { throw new IllegalArgumentException("no JSON provided"); } @@ -248,7 +248,7 @@ public class JsonProtocolFilter { * * @throws IllegalArgumentException an invalid input has been provided */ - public boolean accept(String json) throws IllegalArgumentException { + public boolean accept(String json) { if (json == null || json.isEmpty()) { throw new IllegalArgumentException("no JSON provided"); } @@ -279,7 +279,7 @@ public class JsonProtocolFilter { public List<FilterRule> getRules(String name) { if (name == null || name.isEmpty()) - throw new IllegalArgumentException("no rule name provided"); + throw new IllegalArgumentException(MISSING_RULE_NAME); ArrayList<FilterRule> temp = new ArrayList<>(); for (FilterRule rule : this.rules) { @@ -300,7 +300,7 @@ public class JsonProtocolFilter { public void deleteRules(String name) { if (name == null || name.isEmpty()) - throw new IllegalArgumentException("no rule name provided"); + throw new IllegalArgumentException(MISSING_RULE_NAME); List<FilterRule> temp = new ArrayList<>(); for (FilterRule rule : this.rules) { @@ -313,7 +313,7 @@ public class JsonProtocolFilter { public void deleteRule(String name, String regex) { if (name == null || name.isEmpty()) - throw new IllegalArgumentException("no rule name provided"); + throw new IllegalArgumentException(MISSING_RULE_NAME); String nonNullRegex = regex; if (regex == null || regex.isEmpty()) { @@ -332,7 +332,7 @@ public class JsonProtocolFilter { public void addRule(String name, String regex) { if (name == null || name.isEmpty()) - throw new IllegalArgumentException("no rule name provided"); + throw new IllegalArgumentException(MISSING_RULE_NAME); String nonNullRegex = regex; if (regex == null || regex.isEmpty()) { 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 cb039ee5..7ee8b08a 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * ONAP * ================================================================================ @@ -20,21 +20,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; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Type; @@ -44,6 +29,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; + import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder; @@ -52,6 +38,21 @@ import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.Cust import org.slf4j.Logger; import org.slf4j.LoggerFactory; +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; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + /** * Protocol Coding/Decoding Toolset */ @@ -109,7 +110,7 @@ public abstract class ProtocolCoderToolset { */ public ProtocolCoderToolset(String topic, String controllerId, String groupId, String artifactId, String codedClass, JsonProtocolFilter filters, CustomCoder customCoder, - int modelClassLoaderHash) throws IllegalArgumentException { + int modelClassLoaderHash) { if (topic == null || controllerId == null || groupId == null || artifactId == null || codedClass == null || filters == null || topic.isEmpty() || controllerId.isEmpty()) { @@ -243,8 +244,7 @@ public abstract class ProtocolCoderToolset { * @throws UnsupportedOperationException can't filter * @throws IllegalArgumentException invalid input */ - protected CoderFilters filter(String json) - throws UnsupportedOperationException, IllegalArgumentException, IllegalStateException { + protected CoderFilters filter(String json) { // 1. Get list of decoding classes for this controller Id and topic @@ -297,8 +297,7 @@ public abstract class ProtocolCoderToolset { * @throws IllegalArgumentException if an invalid parameter has been received * @throws UnsupportedOperationException if parsing into POJO is not possible */ - public abstract Object decode(String json) - throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException; + public abstract Object decode(String json); /** * Encodes a POJO object into a JSON String @@ -308,8 +307,7 @@ public abstract class ProtocolCoderToolset { * @throws IllegalArgumentException if an invalid parameter has been received * @throws UnsupportedOperationException if parsing into POJO is not possible */ - public abstract String encode(Object event) - throws IllegalArgumentException, UnsupportedOperationException; + public abstract String encode(Object event); @Override public String toString() { @@ -328,7 +326,11 @@ public abstract class ProtocolCoderToolset { * Tools used for encoding/decoding using Jackson */ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { - private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class); + 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 */ @@ -381,8 +383,7 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { * {@inheritDoc} */ @Override - public Object decode(String json) - throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + public Object decode(String json) { // 0. Use custom coder if available @@ -408,21 +409,20 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { try { decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); if (decoderClass == null) { - logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass()); + logger.warn(WARN_FETCH_FAILED, this, decoderFilter.getCodedClass()); throw new IllegalStateException( - "cannot fetch application class " + decoderFilter.getCodedClass()); + FETCH_FAILED + decoderFilter.getCodedClass()); } } catch (final Exception e) { - logger.warn("{}: cannot fetch application class {} because of {}", this, + logger.warn(WARN_FETCH_FAILED_BECAUSE, this, decoderFilter.getCodedClass(), e.getMessage()); throw new UnsupportedOperationException( - "cannot fetch application class " + decoderFilter.getCodedClass(), e); + FETCH_FAILED + decoderFilter.getCodedClass(), e); } try { - final Object fact = this.decoder.readValue(json, decoderClass); - return fact; + return this.decoder.readValue(json, decoderClass); } catch (final Exception e) { logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(), e.getMessage(), e); @@ -435,8 +435,7 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { * {@inheritDoc} */ @Override - public String encode(Object event) - throws IllegalArgumentException, UnsupportedOperationException { + public String encode(Object event) { // 0. Use custom coder if available @@ -446,11 +445,10 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { } try { - final String encodedEvent = this.encoder.writeValueAsString(event); - return encodedEvent; + return this.encoder.writeValueAsString(event); } catch (final JsonProcessingException e) { logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e); - throw new UnsupportedOperationException("event cannot be encoded"); + throw new UnsupportedOperationException(ENCODE_FAILED); } } @@ -491,7 +489,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { @Override public ZonedDateTime deserialize(JsonElement element, Type type, - JsonDeserializationContext context) throws JsonParseException { + JsonDeserializationContext context) { try { return ZonedDateTime.parse(element.getAsString(), format); } catch (final Exception e) { @@ -511,8 +509,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { implements JsonSerializer<Instant>, JsonDeserializer<Instant> { @Override - public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { return Instant.ofEpochMilli(json.getAsLong()); } @@ -578,8 +575,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { * {@inheritDoc} */ @Override - public Object decode(String json) - throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + public Object decode(String json) { final DroolsController droolsController = DroolsController.factory.get(this.groupId, this.artifactId, ""); @@ -617,8 +613,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { final Object gsonObject = gsonField.get(null); final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson", new Class[] {String.class, Class.class}); - final Object fact = fromJsonMethod.invoke(gsonObject, json, decoderClass); - return fact; + return fromJsonMethod.invoke(gsonObject, json, decoderClass); } catch (final Exception e) { logger.warn("{}: cannot fetch application class {} because of {}", this, decoderFilter.getCodedClass(), e.getMessage()); @@ -627,8 +622,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { } } else { try { - final Object fact = this.decoder.fromJson(json, decoderClass); - return fact; + return this.decoder.fromJson(json, decoderClass); } catch (final Exception e) { logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(), e.getMessage(), e); @@ -644,8 +638,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { * {@inheritDoc} */ @Override - public String encode(Object event) - throws IllegalArgumentException, UnsupportedOperationException { + public String encode(Object event) { if (this.customCoder != null) { try { @@ -657,8 +650,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { final Object gsonObject = gsonField.get(null); final Method toJsonMethod = gsonObject.getClass().getDeclaredMethod("toJson", new Class[] {Object.class}); - final String encodedJson = (String) toJsonMethod.invoke(gsonObject, event); - return encodedJson; + return (String) toJsonMethod.invoke(gsonObject, event); } catch (final Exception e) { logger.warn("{} cannot custom-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/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java index 93737267..7c1b128f 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -28,7 +28,7 @@ public class TopicCoderFilterConfiguration { * Custom coder, contains class and static field to access parser that the controller * desires to use instead of the framework provided parser */ - public static abstract class CustomCoder { + public abstract static class CustomCoder { protected String className; protected String staticCoderField; @@ -41,7 +41,7 @@ public class TopicCoderFilterConfiguration { * * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field> */ - public CustomCoder(String rawCustomCoder) throws IllegalArgumentException { + public CustomCoder(String rawCustomCoder) { if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) { this.className = rawCustomCoder.substring(0,rawCustomCoder.indexOf(",")); @@ -62,7 +62,7 @@ public class TopicCoderFilterConfiguration { * @param classContainer * @param staticCoderField */ - public CustomCoder(String className, String staticCoderField) throws IllegalArgumentException { + public CustomCoder(String className, String staticCoderField) { if (className == null || className.isEmpty()) { throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); } @@ -120,7 +120,7 @@ public class TopicCoderFilterConfiguration { super(className, staticCoderField); } - public CustomGsonCoder(String customGson) throws IllegalArgumentException { + public CustomGsonCoder(String customGson) { super(customGson); } @@ -139,7 +139,7 @@ public class TopicCoderFilterConfiguration { super(className, staticCoderField); } - public CustomJacksonCoder(String customJackson) throws IllegalArgumentException { + public CustomJacksonCoder(String customJackson) { super(customJackson); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java index 845c4944..62b66611 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -68,7 +68,7 @@ public class ControllerConfiguration { private DroolsConfiguration drools; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); - protected final static Object NOT_FOUND_VALUE = new Object(); + protected static final Object NOT_FOUND_VALUE = new Object(); /** * No args constructor for use in serialization @@ -259,7 +259,7 @@ public class ControllerConfiguration { if (other == this) { return true; } - if ((other instanceof ControllerConfiguration) == false) { + if (!(other instanceof ControllerConfiguration)) { return false; } ControllerConfiguration rhs = ((ControllerConfiguration) other); diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java index e822d88e..cac4f565 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -64,7 +64,7 @@ public class DroolsConfiguration { private String version; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); - protected final static Object NOT_FOUND_VALUE = new Object(); + protected static final Object NOT_FOUND_VALUE = new Object(); /** * No args constructor for use in serialization @@ -257,7 +257,7 @@ public class DroolsConfiguration { if (other == this) { return true; } - if ((other instanceof DroolsConfiguration) == false) { + if (!(other instanceof DroolsConfiguration)) { return false; } DroolsConfiguration rhs = ((DroolsConfiguration) other); diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java index c7a227b1..29888bbb 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -70,7 +70,7 @@ public class PdpdConfiguration { private List<ControllerConfiguration> controllers = new ArrayList<>(); @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); - protected final static Object NOT_FOUND_VALUE = new Object(); + protected static final Object NOT_FOUND_VALUE = new Object(); /** * No args constructor for use in serialization @@ -197,8 +197,7 @@ public class PdpdConfiguration { return this; } - @SuppressWarnings("unchecked") - protected boolean declaredProperty(String name, Object value) { + protected boolean declaredProperty(String name, Object value) { switch (name) { case "requestID": callSetRequestId(value); @@ -262,7 +261,7 @@ public class PdpdConfiguration { if (other == this) { return true; } - if ((other instanceof PdpdConfiguration) == false) { + if (!(other instanceof PdpdConfiguration)) { return false; } PdpdConfiguration rhs = (PdpdConfiguration) other; @@ -285,7 +284,8 @@ public class PdpdConfiguration { } } - public void callSetControllers(Object value) { + @SuppressWarnings("unchecked") + public void callSetControllers(Object value) { if (value instanceof List) { setControllers((List<ControllerConfiguration> ) value); } else { diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java index 25f378a7..cd1edca5 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -1816,7 +1816,7 @@ public class RestManager { return Response.status(Status.OK).entity(source).build(); else return Response.status(Status.NOT_ACCEPTABLE) - .entity(new Error("cannot perform operation on " + topic)).build(); + .entity(makeTopicOperError(topic)).build(); } @DELETE @@ -1833,7 +1833,11 @@ public class RestManager { return Response.status(Status.OK).entity(source).build(); else return Response.status(Status.NOT_ACCEPTABLE) - .entity(new Error("cannot perform operation on " + topic)).build(); + .entity(makeTopicOperError(topic)).build(); + } + + private Error makeTopicOperError(String topic) { + return new Error("cannot perform operation on " + topic); } @GET @@ -1858,7 +1862,7 @@ public class RestManager { return Response.status(Status.OK).entity(source).build(); else return Response.status(Status.NOT_ACCEPTABLE) - .entity(new Error("cannot perform operation on " + topic)).build(); + .entity(makeTopicOperError(topic)).build(); } @DELETE @@ -1875,7 +1879,7 @@ public class RestManager { return Response.status(Status.OK).entity(source).build(); else return Response.status(Status.SERVICE_UNAVAILABLE) - .entity(new Error("cannot perform operation on " + topic)).build(); + .entity(makeTopicOperError(topic)).build(); } @PUT @@ -1904,23 +1908,25 @@ public class RestManager { return Response.status(Status.NOT_ACCEPTABLE) .entity(new Error("Failure to inject event over " + topic)).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic, - e.getMessage(), e); + logNoUebEncoder(topic, e); return Response.status(Response.Status.NOT_FOUND).entity(new Error(topic + " not found")) .build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic, - e.getMessage(), e); + logNoUebEncoder(topic, e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error(topic + " not acceptable due to current state")).build(); } catch (final Exception e) { - logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic, - e.getMessage(), e); + logNoUebEncoder(topic, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity(new Error(e.getMessage())).build(); } } + private void logNoUebEncoder(String topic, Exception ex) { + logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic, + ex.getMessage(), ex); + } + @PUT @Path("engine/topics/sources/dmaap/{topic}/events") @Consumes(MediaType.TEXT_PLAIN) @@ -1948,23 +1954,25 @@ public class RestManager { return Response.status(Status.NOT_ACCEPTABLE) .entity(new Error("Failure to inject event over " + topic)).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic, - e.getMessage(), e); + logNoDmaapEncoder(topic, e); return Response.status(Response.Status.NOT_FOUND).entity(new Error(topic + " not found")) .build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic, - e.getMessage(), e); + logNoDmaapEncoder(topic, e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error(topic + " not acceptable due to current state")).build(); } catch (final Exception e) { - logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic, - e.getMessage(), e); + logNoDmaapEncoder(topic, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity(new Error(e.getMessage())).build(); } } + private void logNoDmaapEncoder(String topic, Exception ex) { + logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic, + ex.getMessage(), ex); + } + @GET @Path("engine/tools/uuid") @ApiOperation(value = "Produces an UUID", notes = "UUID generation utility") @@ -2122,18 +2130,18 @@ public class RestManager { * Generic Error Reporting class */ public static class Error { - private String error; + private String msg; - public Error(String error) { - this.setError(error); + public Error(String msg) { + this.setError(msg); } public String getError() { - return error; + return msg; } - public void setError(String error) { - this.error = error; + public void setError(String msg) { + this.msg = msg; } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java index 61719312..314bbc04 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java @@ -58,7 +58,7 @@ public class Main { * @param args program arguments * @throws IOException */ - public static void main(String args[]) { + public static void main(String[] args) { /* logging defaults */ diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java index e6e1ca7e..5324937e 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -41,6 +41,12 @@ import org.onap.policy.drools.protocol.configuration.DroolsConfiguration; public interface PolicyController extends Startable, Lockable { /** + * Factory that tracks and manages Policy Controllers + */ + public static PolicyControllerFactory factory = + new IndexedPolicyControllerFactory(); + + /** * name of this Policy Controller */ public String getName(); @@ -91,20 +97,12 @@ public interface PolicyController extends Startable, Lockable { * not supported. */ public boolean deliver(CommInfrastructure busType, String topic, - Object event) - throws IllegalArgumentException, IllegalStateException, - UnsupportedOperationException; + Object event); /** * halts and permanently releases all resources * @throws IllegalStateException */ - public void halt() throws IllegalStateException; - - /** - * Factory that tracks and manages Policy Controllers - */ - public static PolicyControllerFactory factory = - new IndexedPolicyControllerFactory(); + public void halt(); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java index 8c188c0b..c5787dda 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -50,8 +50,7 @@ public interface PolicyControllerFactory { * * @throws IllegalArgumentException invalid values provided in properties */ - public PolicyController build(String name, Properties properties) - throws IllegalArgumentException; + public PolicyController build(String name, Properties properties); /** * patches (updates) a controller from a critical configuration update. @@ -82,8 +81,7 @@ public interface PolicyControllerFactory { * @throws IllegalArgumentException * @throws IllegalStateException */ - public PolicyController get(DroolsController droolsController) - throws IllegalArgumentException, IllegalStateException; + public PolicyController get(DroolsController droolsController); /** * Makes the Policy Controller identified by controllerName not operational, but @@ -92,7 +90,7 @@ public interface PolicyControllerFactory { * @param controllerName name of the policy controller * @throws IllegalArgumentException invalid arguments */ - public void shutdown(String controllerName) throws IllegalArgumentException;; + public void shutdown(String controllerName); /** * Makes the Policy Controller identified by controller not operational, but @@ -101,7 +99,7 @@ public interface PolicyControllerFactory { * @param controller a Policy Controller * @throws IllegalArgumentException invalid arguments */ - public void shutdown(PolicyController controller) throws IllegalArgumentException; + public void shutdown(PolicyController controller); /** * Releases all Policy Controllers from operation @@ -114,7 +112,7 @@ public interface PolicyControllerFactory { * @param controllerName name of the policy controller * @throws IllegalArgumentException invalid arguments */ - public void destroy(String controllerName) throws IllegalArgumentException;; + public void destroy(String controllerName); /** * Destroys this Policy Controller @@ -122,7 +120,7 @@ public interface PolicyControllerFactory { * @param controller a Policy Controller * @throws IllegalArgumentException invalid arguments */ - public void destroy(PolicyController controller) throws IllegalArgumentException; + public void destroy(PolicyController controller); /** * Releases all Policy Controller resources @@ -137,8 +135,7 @@ public interface PolicyControllerFactory { * @throws IllegalArgumentException * @throws IllegalStateException */ - public PolicyController get(String policyControllerName) - throws IllegalArgumentException, IllegalStateException; + public PolicyController get(String policyControllerName); /** * gets the Policy Controller identified by group and artifact ids @@ -149,8 +146,7 @@ public interface PolicyControllerFactory { * @throws IllegalArgumentException * @throws IllegalStateException */ - public PolicyController get(String groupId, String artifactId) - throws IllegalArgumentException, IllegalStateException; + public PolicyController get(String groupId, String artifactId); /** * get features attached to the Policy Controllers @@ -162,8 +158,7 @@ public interface PolicyControllerFactory { * get named feature attached to the Policy Controllers * @return the feature */ - public PolicyControllerFeatureAPI getFeatureProvider(String featureName) - throws IllegalArgumentException; + public PolicyControllerFeatureAPI getFeatureProvider(String featureName); /** * get features attached to the Policy Controllers @@ -213,8 +208,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public synchronized PolicyController build(String name, Properties properties) - throws IllegalArgumentException { + public synchronized PolicyController build(String name, Properties properties) { if (this.policyControllers.containsKey(name)) { return this.policyControllers.get(name); @@ -241,11 +235,10 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig) - throws IllegalArgumentException { + public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig) { if (name == null || name.isEmpty() || !this.policyControllers.containsKey(name)) { - throw new IllegalArgumentException("Invalid " + name); + throw makeArgEx(name); } if (droolsConfig == null) @@ -273,8 +266,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public PolicyController patch(PolicyController controller, DroolsConfiguration droolsConfig) - throws IllegalArgumentException { + public PolicyController patch(PolicyController controller, DroolsConfiguration droolsConfig) { if (controller == null) throw new IllegalArgumentException("Not a valid controller: null"); @@ -300,10 +292,10 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public void shutdown(String controllerName) throws IllegalArgumentException { + public void shutdown(String controllerName) { if (controllerName == null || controllerName.isEmpty()) { - throw new IllegalArgumentException("Invalid " + controllerName); + throw makeArgEx(controllerName); } synchronized(this) { @@ -320,7 +312,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public void shutdown(PolicyController controller) throws IllegalArgumentException { + public void shutdown(PolicyController controller) { this.unmanage(controller); controller.shutdown(); } @@ -348,7 +340,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * @return * @throws IllegalArgumentException */ - protected void unmanage(PolicyController controller) throws IllegalArgumentException { + protected void unmanage(PolicyController controller) { PolicyController tempController = controller; if (tempController == null) { throw new IllegalArgumentException("Invalid Controller"); @@ -370,10 +362,10 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public void destroy(String controllerName) throws IllegalArgumentException { + public void destroy(String controllerName) { if (controllerName == null || controllerName.isEmpty()) { - throw new IllegalArgumentException("Invalid " + controllerName); + throw makeArgEx(controllerName); } synchronized(this) { @@ -390,7 +382,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public void destroy(PolicyController controller) throws IllegalArgumentException { + public void destroy(PolicyController controller) { this.unmanage(controller); controller.halt(); } @@ -415,17 +407,17 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public PolicyController get(String name) throws IllegalArgumentException, IllegalStateException { + public PolicyController get(String name) { if (name == null || name.isEmpty()) { - throw new IllegalArgumentException("Invalid " + name); + throw makeArgEx(name); } synchronized(this) { if (this.policyControllers.containsKey(name)) { return this.policyControllers.get(name); } else { - throw new IllegalArgumentException("Invalid " + name); + throw makeArgEx(name); } } } @@ -434,8 +426,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public PolicyController get(String groupId, String artifactId) - throws IllegalArgumentException, IllegalStateException { + public PolicyController get(String groupId, String artifactId) { if (groupId == null || groupId.isEmpty() || artifactId == null || artifactId.isEmpty()) { @@ -447,7 +438,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { if (this.coordinates2Controller.containsKey(key)) { return this.coordinates2Controller.get(key); } else { - throw new IllegalArgumentException("Invalid " + key); + throw makeArgEx(key); } } } @@ -456,8 +447,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public PolicyController get(DroolsController droolsController) - throws IllegalArgumentException, IllegalStateException { + public PolicyController get(DroolsController droolsController) { if (droolsController == null) { throw new IllegalArgumentException("No Drools Controller provided"); @@ -479,9 +469,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { */ @Override public List<PolicyController> inventory() { - List<PolicyController> controllers = - new ArrayList<>(this.policyControllers.values()); - return controllers; + return new ArrayList<>(this.policyControllers.values()); } /** @@ -509,7 +497,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc} */ @Override - public PolicyControllerFeatureAPI getFeatureProvider(String featureName) throws IllegalArgumentException { + public PolicyControllerFeatureAPI getFeatureProvider(String featureName) { if (featureName == null || featureName.isEmpty()) throw new IllegalArgumentException("A feature name must be provided"); @@ -520,4 +508,8 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { throw new IllegalArgumentException("Invalid Feature Name: " + featureName); } + + private IllegalArgumentException makeArgEx(String argName) { + return new IllegalArgumentException("Invalid " + argName); + } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java index c90d8bea..a1fee763 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -67,6 +67,11 @@ import com.google.gson.GsonBuilder; */ public interface PolicyEngine extends Startable, Lockable, TopicListener { /** + * Policy Engine Manager + */ + public static final PolicyEngine manager = new PolicyEngineManager(); + + /** * Default Telemetry Server Port */ public static final int TELEMETRY_SERVER_DEFAULT_PORT = 9696; @@ -86,7 +91,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * * @param cliArgs command line arguments */ - public void boot(String cliArgs[]); + public void boot(String[] cliArgs); /** * configure the policy engine according to the given properties @@ -246,8 +251,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * * @return the feature */ - public PolicyEngineFeatureAPI getFeatureProvider(String featureName) - throws IllegalArgumentException; + public PolicyEngineFeatureAPI getFeatureProvider(String featureName); /** * get features attached to the Policy Engine @@ -267,8 +271,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws IllegalStateException when the engine is in a state where this operation is not * permitted (ie. locked or stopped). */ - public boolean deliver(String topic, Object event) - throws IllegalArgumentException, IllegalStateException; + public boolean deliver(String topic, Object event); /** * Attempts the dispatching of an "event" object over communication infrastructure "busType" @@ -284,8 +287,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality * missing (ie. communication infrastructure not supported. */ - public boolean deliver(String busType, String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + public boolean deliver(String busType, String topic, Object event); /** * Attempts the dispatching of an "event" object over communication infrastructure "busType" @@ -301,8 +303,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality * missing (ie. communication infrastructure not supported. */ - public boolean deliver(CommInfrastructure busType, String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + public boolean deliver(CommInfrastructure busType, String topic, Object event); /** * Attempts delivering of an String over communication infrastructure "busType" @@ -318,8 +319,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality * missing (ie. communication infrastructure not supported. */ - public boolean deliver(CommInfrastructure busType, String topic, String event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + public boolean deliver(CommInfrastructure busType, String topic, String event); /** * Invoked when the host goes into the active state. @@ -337,11 +337,6 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @return policy engine configuration */ public Properties defaultTelemetryConfig(); - - /** - * Policy Engine Manager - */ - public final static PolicyEngine manager = new PolicyEngineManager(); } @@ -349,7 +344,15 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * Policy Engine Manager Implementation */ class PolicyEngineManager implements PolicyEngine { - /** + private static final String INVALID_TOPIC_MSG = "Invalid Topic"; + +private static final String INVALID_EVENT_MSG = "Invalid Event"; + +private static final String ENGINE_STOPPED_MSG = "Policy Engine is stopped"; + +private static final String ENGINE_LOCKED_MSG = "Policy Engine is locked"; + +/** * logger */ private static final Logger logger = LoggerFactory.getLogger(PolicyEngineManager.class); @@ -396,7 +399,7 @@ class PolicyEngineManager implements PolicyEngine { @Override - public synchronized void boot(String cliArgs[]) { + public synchronized void boot(String[] cliArgs) { for (final PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { try { @@ -531,8 +534,7 @@ class PolicyEngineManager implements PolicyEngine { } @Override - public synchronized PolicyController createPolicyController(String name, Properties properties) - throws IllegalArgumentException, IllegalStateException { + public synchronized PolicyController createPolicyController(String name, Properties properties) { String tempName = name; // check if a PROPERTY_CONTROLLER_NAME property is present @@ -601,8 +603,7 @@ class PolicyEngineManager implements PolicyEngine { @Override public List<PolicyController> updatePolicyControllers( - List<ControllerConfiguration> configControllers) - throws IllegalArgumentException, IllegalStateException { + List<ControllerConfiguration> configControllers) { final List<PolicyController> policyControllers = new ArrayList<>(); if (configControllers == null || configControllers.isEmpty()) { @@ -739,7 +740,7 @@ class PolicyEngineManager implements PolicyEngine { boolean success = true; if (this.locked) - throw new IllegalStateException("Engine is locked"); + throw new IllegalStateException(ENGINE_LOCKED_MSG); this.alive = true; @@ -1199,24 +1200,23 @@ class PolicyEngineManager implements PolicyEngine { } @Override - public boolean deliver(String topic, Object event) - throws IllegalArgumentException, IllegalStateException { + public boolean deliver(String topic, Object event) { /* * Note this entry point is usually from the DRL */ if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Invalid Topic"); + throw new IllegalArgumentException(INVALID_TOPIC_MSG); if (event == null) - throw new IllegalArgumentException("Invalid Event"); + throw new IllegalArgumentException(INVALID_EVENT_MSG); if (!this.isAlive()) - throw new IllegalStateException("Policy Engine is stopped"); + throw new IllegalStateException(ENGINE_STOPPED_MSG); if (this.isLocked()) - throw new IllegalStateException("Policy Engine is locked"); + throw new IllegalStateException(ENGINE_LOCKED_MSG); final List<? extends TopicSink> topicSinks = TopicEndpoint.manager.getTopicSinks(topic); if (topicSinks == null || topicSinks.isEmpty() || topicSinks.size() > 1) @@ -1227,8 +1227,7 @@ class PolicyEngineManager implements PolicyEngine { } @Override - public boolean deliver(String busType, String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public boolean deliver(String busType, String topic, Object event) { /* * Note this entry point is usually from the DRL (one of the reasons busType is String. @@ -1238,10 +1237,10 @@ class PolicyEngineManager implements PolicyEngine { throw new IllegalArgumentException("Invalid Communication Infrastructure"); if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Invalid Topic"); + throw new IllegalArgumentException(INVALID_TOPIC_MSG); if (event == null) - throw new IllegalArgumentException("Invalid Event"); + throw new IllegalArgumentException(INVALID_EVENT_MSG); boolean valid = false; for (final Topic.CommInfrastructure comm : Topic.CommInfrastructure.values()) { @@ -1255,30 +1254,29 @@ class PolicyEngineManager implements PolicyEngine { if (!this.isAlive()) - throw new IllegalStateException("Policy Engine is stopped"); + throw new IllegalStateException(ENGINE_STOPPED_MSG); if (this.isLocked()) - throw new IllegalStateException("Policy Engine is locked"); + throw new IllegalStateException(ENGINE_LOCKED_MSG); return this.deliver(Topic.CommInfrastructure.valueOf(busType), topic, event); } @Override - public boolean deliver(Topic.CommInfrastructure busType, String topic, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public boolean deliver(Topic.CommInfrastructure busType, String topic, Object event) { if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Invalid Topic"); + throw new IllegalArgumentException(INVALID_TOPIC_MSG); if (event == null) - throw new IllegalArgumentException("Invalid Event"); + throw new IllegalArgumentException(INVALID_EVENT_MSG); if (!this.isAlive()) - throw new IllegalStateException("Policy Engine is stopped"); + throw new IllegalStateException(ENGINE_STOPPED_MSG); if (this.isLocked()) - throw new IllegalStateException("Policy Engine is locked"); + throw new IllegalStateException(ENGINE_LOCKED_MSG); /* * Try to send through the controller, this is the preferred way, since it may want to apply @@ -1312,20 +1310,19 @@ class PolicyEngineManager implements PolicyEngine { } @Override - public boolean deliver(Topic.CommInfrastructure busType, String topic, String event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public boolean deliver(Topic.CommInfrastructure busType, String topic, String event) { if (topic == null || topic.isEmpty()) - throw new IllegalArgumentException("Invalid Topic"); + throw new IllegalArgumentException(INVALID_TOPIC_MSG); if (event == null || event.isEmpty()) - throw new IllegalArgumentException("Invalid Event"); + throw new IllegalArgumentException(INVALID_EVENT_MSG); if (!this.isAlive()) - throw new IllegalStateException("Policy Engine is stopped"); + throw new IllegalStateException(ENGINE_STOPPED_MSG); if (this.isLocked()) - throw new IllegalStateException("Policy Engine is locked"); + throw new IllegalStateException(ENGINE_LOCKED_MSG); try { final TopicSink sink = TopicEndpoint.manager.getTopicSink(busType, topic); diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java index 0645bdc5..ea631fae 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -111,8 +111,7 @@ public class AggregatedPolicyController implements PolicyController, * * @throws IllegalArgumentException when invalid arguments are provided */ - public AggregatedPolicyController(String name, Properties properties) - throws IllegalArgumentException { + public AggregatedPolicyController(String name, Properties properties) { this.name = name; @@ -139,7 +138,7 @@ public class AggregatedPolicyController implements PolicyController, * initialize drools layer * @throws IllegalArgumentException if invalid parameters are passed in */ - protected void initDrools(Properties properties) throws IllegalArgumentException { + protected void initDrools(Properties properties) { try { // Register with drools infrastructure this.droolsController = DroolsController.factory.build(properties, sources, sinks); @@ -153,7 +152,7 @@ public class AggregatedPolicyController implements PolicyController, * initialize sinks * @throws IllegalArgumentException if invalid parameters are passed in */ - protected void initSinks() throws IllegalArgumentException { + protected void initSinks() { this.topic2Sinks.clear(); for (TopicSink sink: sinks) { this.topic2Sinks.put(sink.getTopic(), sink); @@ -224,7 +223,7 @@ public class AggregatedPolicyController implements PolicyController, * {@inheritDoc} */ @Override - public boolean start() throws IllegalStateException { + public boolean start() { logger.info("{}: start", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { @@ -328,7 +327,7 @@ public class AggregatedPolicyController implements PolicyController, * {@inheritDoc} */ @Override - public void shutdown() throws IllegalStateException { + public void shutdown() { logger.info("{}: shutdown", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { @@ -360,7 +359,7 @@ public class AggregatedPolicyController implements PolicyController, * {@inheritDoc} */ @Override - public void halt() throws IllegalStateException { + public void halt() { logger.info("{}: halt", this); for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { @@ -432,9 +431,7 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public boolean deliver(Topic.CommInfrastructure commType, - String topic, Object event) - throws IllegalArgumentException, IllegalStateException, - UnsupportedOperationException { + String topic, Object event) { if (logger.isDebugEnabled()) logger.debug("{}: deliver event to {}:{}: {}", this, commType, topic, event); 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 e3dd7c54..c7113cd4 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 @@ -20,16 +20,13 @@ 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; @@ -47,6 +44,11 @@ import org.onap.policy.drools.utils.Triple; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + /** * ProtocolCoder Toolset JUNITs */ @@ -157,7 +159,8 @@ public class ProtocolCoderToolsetTest { decode(protocolFilter, coderToolset, triple, tripleEncoded); } - private void decode(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset, + @SuppressWarnings("unchecked") + private void decode(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset, Triple<String, String, String> triple, String tripleEncoded) { Triple<String, String, String> tripleDecoded = null; @@ -273,9 +276,8 @@ public class ProtocolCoderToolsetTest { droolsControllerConfig.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS + "." + JUNIT_PROTOCOL_CODER_TOPIC + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX, Triple.class.getCanonicalName()); - - DroolsController droolsController = - DroolsController.factory.build(droolsControllerConfig, null, noopTopics); + + DroolsController.factory.build(droolsControllerConfig, null, noopTopics); } private JsonProtocolFilter createFilterSet() { |