From a156cf3cbad6512510ae9a02a13c0408f901c734 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 5 Aug 2019 15:27:16 -0400 Subject: Fix sonar issues in drools-pdp Address sonar issue, "Move constants to a class or enum", by moving them from interfaces to classes: ActiveStandbyFeatureApi StateManagementFeatureApi PolicyResourceLockFeatureApi PolicySessionFeatureApi DroolsController DroolsControllerFeatureApi PolicyControllerFeatureApi PolicyEngineFeatureApi HealthCheck SystemPersistence EventProtocolCoder PolicyController PolicyEngine TestTransaction MdcTransaction Address sonar issue, "Move constants to a class or enum", by change the interface to a class: DroolsProperties Address sonar issue, "Override the "equals" method in this class", by adding equals & hashCode to: DroolsPdpEntity DroolsPdpImpl Use lombok for a number of getters & setters. Address sonar issue, "Define a constant instead of duplicating this literal" in: DroolsPdpsElectionHandler JpaDroolsPdpsConnector MavenDroolsController GenericEventProtocolCoder GsonProtocolCoderToolset RestManager Address sonar issue, "Remove the parentheses around the parameter" in: MavenDroolsController Address sonar issue, "Replace this lambda with a method reference" in: LifecycleFsm Address sonar issue, "Move this constructor to comply with Java Code Conventions" in: LifecycleStateRunning Address sonar issue, "Replace this 'switch' statement by 'if' statements to increase readability", as specified in: PolicyEngineManager Address sonar issue, "Rename field to prevent any misunderstanding/clash with field" in: MdcTransactionImpl Address sonar issue, "Either log or rethrow this exception", in: RestManager Address sonar issue, "Rename this constant name to" uppercase, by replacing enums with static lists in: RestManager Addressed review comments: Fixed license dates. Renamed getSiteName/setSiteName methods to getSite/setSite in the interface to match the field names in the implementation classes. Renamed *Instance classes to *Constants. Next round of review comments. Change-Id: I1c26af9f194833dd773f2b25dc5f60cde163201c Issue-ID: POLICY-1968 Signed-off-by: Jim Hahn --- .../onap/policy/drools/lifecycle/LifecycleFsm.java | 9 +++++---- .../drools/lifecycle/LifecycleStateRunning.java | 8 ++++---- .../policy/drools/lifecycle/ControllerSupport.java | 21 +++++++++++---------- .../drools/lifecycle/LifecycleStateRunningTest.java | 8 ++++---- .../lifecycle/LifecycleStateTerminatedTest.java | 6 +++--- .../lifecycle/LifecycleStateUnsupportedTest.java | 6 +++--- .../server/restful/RestLifecycleManagerTest.java | 4 ++-- 7 files changed, 32 insertions(+), 30 deletions(-) (limited to 'feature-lifecycle') diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java index 67f5467b..36d2a545 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java @@ -45,7 +45,8 @@ import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.drools.controller.DroolsController; -import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.controller.DroolsControllerConstants; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; import org.onap.policy.drools.system.PolicyController; import org.onap.policy.models.pdp.concepts.PdpResponseDetails; import org.onap.policy.models.pdp.concepts.PdpStateChange; @@ -116,7 +117,7 @@ public class LifecycleFsm implements Startable { * Constructor. */ public LifecycleFsm() { - this.properties = SystemPersistence.manager.getProperties(CONFIGURATION_PROPERTIES_NAME); + this.properties = SystemPersistenceConstants.getManager().getProperties(CONFIGURATION_PROPERTIES_NAME); scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); @@ -305,7 +306,7 @@ public class LifecycleFsm implements Startable { private boolean startTimers() { statusTask = - this.scheduler.scheduleAtFixedRate(() -> status(), 0, statusTimerSeconds, TimeUnit.SECONDS); + this.scheduler.scheduleAtFixedRate(this::status, 0, statusTimerSeconds, TimeUnit.SECONDS); return !statusTask.isCancelled() && !statusTask.isDone(); } @@ -381,7 +382,7 @@ public class LifecycleFsm implements Startable { private List getCapabilities() { List capabilities = new ArrayList<>(); - for (DroolsController dc : DroolsController.factory.inventory()) { + for (DroolsController dc : DroolsControllerConstants.getFactory().inventory()) { if (!dc.isBrained()) { continue; } diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java index d5820d08..c5ea44b2 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java @@ -42,6 +42,10 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { private static final Logger logger = LoggerFactory.getLogger(LifecycleStateRunning.class); + protected LifecycleStateRunning(LifecycleFsm manager) { + super(manager); + } + protected abstract boolean stateChangeToPassive(@NonNull PdpStateChange change); protected abstract boolean stateChangeToActive(@NonNull PdpStateChange change); @@ -50,10 +54,6 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { protected abstract boolean undeployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy); - protected LifecycleStateRunning(LifecycleFsm manager) { - super(manager); - } - @Override public boolean start() { logger.warn("{}: start", this); diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java index 3a3434ac..e82eb42b 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java @@ -27,8 +27,9 @@ import java.util.Properties; import lombok.Getter; import lombok.NonNull; import org.kie.api.builder.ReleaseId; -import org.onap.policy.drools.properties.DroolsProperties; +import org.onap.policy.drools.properties.DroolsPropertyConstants; import org.onap.policy.drools.system.PolicyController; +import org.onap.policy.drools.system.PolicyControllerConstants; import org.onap.policy.drools.util.KieUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @@ -75,27 +76,27 @@ public class ControllerSupport { Properties controllerProps = new Properties(); - controllerProps.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, name); - controllerProps.put(DroolsProperties.PROPERTY_CONTROLLER_POLICY_TYPES, getPolicyType()); - controllerProps.put(DroolsProperties.RULES_GROUPID, coordinates.getGroupId()); - controllerProps.put(DroolsProperties.RULES_ARTIFACTID, coordinates.getArtifactId()); - controllerProps.put(DroolsProperties.RULES_VERSION, coordinates.getVersion()); + controllerProps.put(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, name); + controllerProps.put(DroolsPropertyConstants.PROPERTY_CONTROLLER_POLICY_TYPES, getPolicyType()); + controllerProps.put(DroolsPropertyConstants.RULES_GROUPID, coordinates.getGroupId()); + controllerProps.put(DroolsPropertyConstants.RULES_ARTIFACTID, coordinates.getArtifactId()); + controllerProps.put(DroolsPropertyConstants.RULES_VERSION, coordinates.getVersion()); - return PolicyController.factory.build(name, controllerProps); + return PolicyControllerConstants.getFactory().build(name, controllerProps); } /** * Destroy the echo controller. */ public void destroyController() { - PolicyController.factory.destroy(name); + PolicyControllerConstants.getFactory().destroy(name); } /** * Get controller. */ public PolicyController getController() { - return PolicyController.factory.get(name); + return PolicyControllerConstants.getFactory().get(name); } /** @@ -109,7 +110,7 @@ public class ControllerSupport { * Get facts. */ public List getFacts(Class clazz) { - return PolicyController.factory.get(name) + return PolicyControllerConstants.getFactory().get(name) .getDrools() .facts(SESSION_NAME, clazz); } diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java index 25cce3a9..8ac47e55 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java @@ -25,7 +25,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; import org.onap.policy.drools.utils.logging.LoggerUtil; public abstract class LifecycleStateRunningTest { @@ -42,7 +42,7 @@ public abstract class LifecycleStateRunningTest { LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO"); LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN"); LoggerUtil.setLevel("org.onap.policy.drools", "INFO"); - SystemPersistence.manager.setConfigurationDir("target/test-classes"); + SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes"); controllerSupport.createController(); } @@ -52,11 +52,11 @@ public abstract class LifecycleStateRunningTest { @AfterClass public static void tearDown() { try { - Files.deleteIfExists(Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), + Files.deleteIfExists(Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), CONTROLLER_NAME + "-controller.properties.bak")); } catch (IOException e) { ; } - SystemPersistence.manager.setConfigurationDir(null); + SystemPersistenceConstants.getManager().setConfigurationDir(null); } } diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java index 50c4f1a7..353525d6 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java @@ -33,7 +33,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.utils.network.NetworkUtil; -import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; @@ -47,13 +47,13 @@ public class LifecycleStateTerminatedTest { @BeforeClass public static void setUp() { - SystemPersistence.manager.setConfigurationDir("src/test/resources"); + SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources"); LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN"); } @AfterClass public static void tearDown() { - SystemPersistence.manager.setConfigurationDir(null); + SystemPersistenceConstants.getManager().setConfigurationDir(null); } @Test diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupportedTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupportedTest.java index 01efca32..14da6ab0 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupportedTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupportedTest.java @@ -26,7 +26,7 @@ import static org.assertj.core.api.Java6Assertions.assertThatThrownBy; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; @@ -39,12 +39,12 @@ public abstract class LifecycleStateUnsupportedTest { @BeforeClass public static void setUp() { - SystemPersistence.manager.setConfigurationDir("src/test/resources"); + SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources"); } @AfterClass public static void tearDown() { - SystemPersistence.manager.setConfigurationDir(null); + SystemPersistenceConstants.getManager().setConfigurationDir(null); } public LifecycleStateUnsupportedTest(LifecycleState state) { diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java index 92269167..da7435f3 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java @@ -33,7 +33,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.network.NetworkUtil; -import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.persistence.SystemPersistenceConstants; import org.onap.policy.models.pdp.enums.PdpState; /** @@ -49,7 +49,7 @@ public class RestLifecycleManagerTest { HttpServletServerFactoryInstance.getServerFactory().destroy(); HttpClientFactoryInstance.getClientFactory().destroy(); - SystemPersistence.manager.setConfigurationDir("target/test-classes"); + SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes"); HttpClientFactoryInstance.getClientFactory().build( BusTopicParams.builder() -- cgit 1.2.3-korg