summaryrefslogtreecommitdiffstats
path: root/controlloop/common/controller-tdjam/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-09-30 12:52:25 -0400
committerJim Hahn <jrh3@att.com>2020-09-30 14:59:39 -0400
commitfb9bd637567096f6174bbc2e52a5e149a4eed882 (patch)
tree7b0d2df1aefbb3635788af501be1157fbe05d798 /controlloop/common/controller-tdjam/src/main
parente8e477ab80c6762fb05aebfe9becc630d2d51e39 (diff)
Fix new sonars in drools-apps
Addressed the following sonars: - too many assertions in test method - rename test class - use static method to modify static field - use already defined constant - code always returns the same value - use assertNotSame - use appropriate class name to access static method - define a constant - extract nested try block - don't always return the same value - use remove() instead of set(null) for thread-local-storage - add @Override Issue-ID: POLICY-2852 Change-Id: Icc62acd4ad57afa2d44ed4cdca504a3ac0810228 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/controller-tdjam/src/main')
-rw-r--r--controlloop/common/controller-tdjam/src/main/java/org/onap/policy/controlloop/tdjam/TdjamController.java28
-rw-r--r--controlloop/common/controller-tdjam/src/main/java/org/onap/policy/extension/system/NonDroolsPolicyController.java9
2 files changed, 17 insertions, 20 deletions
diff --git a/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/controlloop/tdjam/TdjamController.java b/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/controlloop/tdjam/TdjamController.java
index 0b17f196f..3b3655122 100644
--- a/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/controlloop/tdjam/TdjamController.java
+++ b/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/controlloop/tdjam/TdjamController.java
@@ -24,6 +24,7 @@ import static org.onap.policy.drools.properties.DroolsPropertyConstants.PROPERTY
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -72,6 +73,9 @@ public class TdjamController extends NonDroolsPolicyController {
// the 'controller.type' property is set to this value
private static final String TDJAM_CONTROLLER_BUILDER_TAG = "tdjam";
+ // topic on which to publish event notifications
+ private static final String POLICY_CL_MGT = "POLICY-CL-MGT";
+
// additional data associated with session
private final String groupId;
private final String artifactId;
@@ -352,7 +356,9 @@ public class TdjamController extends NonDroolsPolicyController {
cp.getClosedLoopControlName());
}
- logger.debug(new String(bos.toByteArray()));
+ if (logger.isDebugEnabled()) {
+ logger.debug(new String(bos.toByteArray(), StandardCharsets.UTF_8));
+ }
}
/**
@@ -454,7 +460,7 @@ public class TdjamController extends NonDroolsPolicyController {
// Generate notification
//
try {
- PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver(POLICY_CL_MGT, notification);
} catch (RuntimeException e) {
logger.warn("{}: {}.{}: event={} exception generating notification",
@@ -609,18 +615,14 @@ public class TdjamController extends NonDroolsPolicyController {
// we create the ControlLoopEventManager. The ControlLoopEventManager
// will do extra syntax checking as well as check if the closed loop is disabled.
//
- try {
- start();
- } catch (Exception e) {
- eventManagers.remove(requestId, this);
- onsetToEventManager.remove(event, this);
- throw e;
- }
+ start();
notification = makeNotification();
notification.setNotification(ControlLoopNotificationType.ACTIVE);
notification.setPolicyName(params.getPolicyName() + "." + ruleName);
} catch (Exception e) {
logger.warn("{}: {}.{}", clName, params.getPolicyName(), ruleName, e);
+ eventManagers.remove(requestId, this);
+ onsetToEventManager.remove(event, this);
notification = new VirtualControlLoopNotification(event);
notification.setNotification(ControlLoopNotificationType.REJECTED);
notification.setMessage("Exception occurred: " + e.getMessage());
@@ -632,7 +634,7 @@ public class TdjamController extends NonDroolsPolicyController {
// Generate notification
//
try {
- PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver(POLICY_CL_MGT, notification);
} catch (RuntimeException e) {
logger.warn("{}: {}.{}: event={} exception generating notification",
@@ -719,7 +721,7 @@ public class TdjamController extends NonDroolsPolicyController {
//
try {
notification.setPolicyName(getPolicyName() + "." + ruleName);
- PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver(POLICY_CL_MGT, notification);
} catch (RuntimeException e) {
logger.warn("{}: {}.{}: manager={} exception generating notification",
@@ -766,7 +768,7 @@ public class TdjamController extends NonDroolsPolicyController {
//
try {
notification.setPolicyName(getPolicyName() + "." + ruleName);
- PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver(POLICY_CL_MGT, notification);
} catch (RuntimeException e) {
logger.warn("{}: {}.{}: manager={} exception generating notification",
getClosedLoopControlName(), getPolicyName(), ruleName,
@@ -825,7 +827,7 @@ public class TdjamController extends NonDroolsPolicyController {
List<TopicCoderFilterConfiguration> encoderConfigurations) throws LinkageError {
if (TDJAM_CONTROLLER_BUILDER_TAG.equals(properties.getProperty(PROPERTY_CONTROLLER_TYPE))) {
- return TdjamController.getBuildInProgress();
+ return NonDroolsPolicyController.getBuildInProgress();
}
return null;
}
diff --git a/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/extension/system/NonDroolsPolicyController.java b/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/extension/system/NonDroolsPolicyController.java
index d876bee96..97eb6a04d 100644
--- a/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/extension/system/NonDroolsPolicyController.java
+++ b/controlloop/common/controller-tdjam/src/main/java/org/onap/policy/extension/system/NonDroolsPolicyController.java
@@ -143,12 +143,13 @@ public class NonDroolsPolicyController extends AggregatedPolicyController implem
return buildInProgress.get();
}
+ @Override
protected void initDrools(Properties properties) {
try {
// Register with drools factory
buildInProgress.set(this);
this.droolsController.set(getDroolsFactory().build(properties, sources, sinks));
- buildInProgress.set(null);
+ buildInProgress.remove();
} catch (Exception | LinkageError e) {
logger.error("{}: cannot init-drools", this);
throw new IllegalArgumentException(e);
@@ -198,9 +199,6 @@ public class NonDroolsPolicyController extends AggregatedPolicyController implem
logger.info("START: {}", this);
synchronized (this) {
- if (this.alive) {
- return true;
- }
this.alive = true;
}
@@ -213,9 +211,6 @@ public class NonDroolsPolicyController extends AggregatedPolicyController implem
logger.info("STOP: {}", this);
synchronized (this) {
- if (!this.alive) {
- return true;
- }
this.alive = false;
}