diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-31 08:22:13 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-08-31 10:15:07 -0400 |
commit | d5c365f60e492e37a361654974eba1719146bdc2 (patch) | |
tree | f717c2198c1aebe0cc03a5d3e9aec653d0d73807 /policy-management/src | |
parent | 7dc71c3d0aedb322aff0cdaaa84340354c41b089 (diff) |
Fix more sonars in drools-pdp
Fixed more sonars in drools-pdp:
- remove commented code
- don't throw generic Exception
- unused field (made it protected instead of private)
- log conditionally
- cognitive complexity
- too many break/continue
- return empty list instead of null
- Random() is not secure
Fixed more eclipse warnings:
- parameterize generic types
Issue-ID: POLICY-2616-sonars3
Change-Id: Ia5ad769b2ea763568cfae3d81807926d89153b09
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-management/src')
-rw-r--r-- | policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java | 47 | ||||
-rw-r--r-- | policy-management/src/main/java/org/onap/policy/drools/system/Main.java | 4 |
2 files changed, 30 insertions, 21 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java index e8234a46..d2196680 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java @@ -31,6 +31,7 @@ import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; +import org.onap.policy.common.utils.services.FeatureApiUtils; import org.onap.policy.drools.controller.internal.MavenDroolsController; import org.onap.policy.drools.controller.internal.NullDroolsController; import org.onap.policy.drools.features.DroolsControllerFeatureApi; @@ -152,24 +153,8 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { /* new drools controller */ - DroolsController controller = null; - for (DroolsControllerFeatureApi feature: getProviders()) { - try { - controller = feature.beforeInstance(properties, - newGroupId, newArtifactId, newVersion, + DroolsController controller = applyBeforeInstance(properties, newGroupId, newArtifactId, newVersion, decoderConfigurations, encoderConfigurations); - if (controller != null) { - logger.info("feature {} ({}) beforeInstance() has intercepted drools controller {}:{}:{}", - feature.getName(), feature.getSequenceNumber(), - newGroupId, newArtifactId, newVersion); - break; - } - } catch (RuntimeException r) { - logger.error("feature {} ({}) beforeInstance() of drools controller {}:{}:{} failed", - feature.getName(), feature.getSequenceNumber(), - newGroupId, newArtifactId, newVersion, r); - } - } if (controller == null) { controller = new MavenDroolsController(newGroupId, newArtifactId, newVersion, decoderConfigurations, @@ -180,16 +165,38 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { droolsControllers.put(controllerId, controller); } + final DroolsController controllerFinal = controller; + + FeatureApiUtils.apply(getProviders(), + feature -> feature.afterInstance(controllerFinal, properties), + (feature, ex) -> logger.error("feature {} ({}) afterInstance() of drools controller {}:{}:{} failed", + feature.getName(), feature.getSequenceNumber(), + newGroupId, newArtifactId, newVersion, ex)); + + return controller; + } + + private DroolsController applyBeforeInstance(Properties properties, String newGroupId, String newArtifactId, + String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations, + List<TopicCoderFilterConfiguration> encoderConfigurations) { + DroolsController controller = null; for (DroolsControllerFeatureApi feature: getProviders()) { try { - feature.afterInstance(controller, properties); + controller = feature.beforeInstance(properties, + newGroupId, newArtifactId, newVersion, + decoderConfigurations, encoderConfigurations); + if (controller != null) { + logger.info("feature {} ({}) beforeInstance() has intercepted drools controller {}:{}:{}", + feature.getName(), feature.getSequenceNumber(), + newGroupId, newArtifactId, newVersion); + break; + } } catch (RuntimeException r) { - logger.error("feature {} ({}) afterInstance() of drools controller {}:{}:{} failed", + logger.error("feature {} ({}) beforeInstance() of drools controller {}:{}:{} failed", feature.getName(), feature.getSequenceNumber(), newGroupId, newArtifactId, newVersion, r); } } - return controller; } 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 9e6d0432..be0cb820 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 @@ -106,7 +106,9 @@ public class Main { /* 5. Open the engine for dynamic configuration */ PolicyEngineConstants.getManager().open(); - logger.info(String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_DROOLS_PDP)); + if (logger.isInfoEnabled()) { + logger.info(String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_DROOLS_PDP)); + } } private static void setSystemProperties() { |