aboutsummaryrefslogtreecommitdiffstats
path: root/policy-core/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-08-05 15:27:16 -0400
committerJim Hahn <jrh3@att.com>2019-08-13 15:58:15 -0400
commita156cf3cbad6512510ae9a02a13c0408f901c734 (patch)
tree0a69bffb2a6c9f961bda1408153cf44f360c6a17 /policy-core/src/main
parent62d1ff054b0ec6348ab6f7415063fdaa3f425215 (diff)
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 <jrh3@att.com>
Diffstat (limited to 'policy-core/src/main')
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java36
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java2
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java7
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java38
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java8
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiConstants.java39
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java26
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/properties/DroolsPropertyConstants.java (renamed from policy-core/src/main/java/org/onap/policy/drools/properties/DroolsProperties.java)24
8 files changed, 123 insertions, 57 deletions
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
index 3b5c360f..584b3845 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
@@ -8,9 +8,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -169,7 +169,7 @@ public class PolicyContainer implements Startable {
/**
* Get name.
- *
+ *
* @return the name of the container, which is the String equivalent of the 'ReleaseId'. It has
* the form:
*
@@ -184,7 +184,7 @@ public class PolicyContainer implements Startable {
/**
* Get kie container.
- *
+ *
* @return the associated 'KieContainer' instance
*/
public KieContainer getKieContainer() {
@@ -193,7 +193,7 @@ public class PolicyContainer implements Startable {
/**
* Get class loader.
- *
+ *
* @return the 'ClassLoader' associated with the 'KieContainer' instance
*/
public ClassLoader getClassLoader() {
@@ -202,7 +202,7 @@ public class PolicyContainer implements Startable {
/**
* Get group Id.
- *
+ *
* @return the Maven GroupId of the top-level artifact wrapped by the container.
*/
public String getGroupId() {
@@ -211,7 +211,7 @@ public class PolicyContainer implements Startable {
/**
* Get artifact id.
- *
+ *
* @return the Maven ArtifactId of the top-level artifact wrapped by the container.
*/
public String getArtifactId() {
@@ -220,7 +220,7 @@ public class PolicyContainer implements Startable {
/**
* Get version.
- *
+ *
* @return the version of the top-level artifact wrapped by the container (this may change as
* updates occur)
*/
@@ -258,7 +258,7 @@ public class PolicyContainer implements Startable {
// loop through all of the features, and give each one
// a chance to create the 'KieSession'
- for (PolicySessionFeatureApi feature : PolicySessionFeatureApi.impl.getList()) {
+ for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
if ((kieSession = feature.activatePolicySession(this, name, kieBaseName)) != null) {
break;
@@ -280,7 +280,7 @@ public class PolicyContainer implements Startable {
sessions.put(name, session);
// notify features
- for (PolicySessionFeatureApi feature : PolicySessionFeatureApi.impl.getList()) {
+ for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
feature.newPolicySession(session);
} catch (Exception e) {
@@ -289,7 +289,7 @@ public class PolicyContainer implements Startable {
}
logger.info("activatePolicySession:new session was added in sessions with name {}", name);
}
- logger.info("activatePolicySession:session - {} is returned.",
+ logger.info("activatePolicySession:session - {} is returned.",
session == null ? "null" : session.getFullName());
return session;
}
@@ -350,7 +350,7 @@ public class PolicyContainer implements Startable {
sessions.put(name, policySession);
// notify features
- for (PolicySessionFeatureApi feature : PolicySessionFeatureApi.impl.getList()) {
+ for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
feature.newPolicySession(policySession);
} catch (Exception e) {
@@ -412,7 +412,7 @@ public class PolicyContainer implements Startable {
/**
* Get policy containers.
- *
+ *
* @return all existing 'PolicyContainer' instances
*/
public static Collection<PolicyContainer> getPolicyContainers() {
@@ -423,14 +423,14 @@ public class PolicyContainer implements Startable {
/**
* Get policy sessions.
- *
+ *
* @return all of the 'PolicySession' instances
*/
public Collection<PolicySession> getPolicySessions() {
// KLUDGE WARNING: this is a temporary workaround -- if there are
// no features, we don't have persistence, and 'activate' is never
// called. In this case, make sure the container is started.
- if (PolicySessionFeatureApi.impl.getList().isEmpty()) {
+ if (PolicySessionFeatureApiConstants.getImpl().getList().isEmpty()) {
start();
}
@@ -562,7 +562,7 @@ public class PolicyContainer implements Startable {
session.getKieSession().dispose();
// notify features
- for (PolicySessionFeatureApi feature : PolicySessionFeatureApi.impl.getList()) {
+ for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
feature.disposeKieSession(session);
} catch (Exception e) {
@@ -625,7 +625,7 @@ public class PolicyContainer implements Startable {
session.getKieSession().destroy();
// notify features
- for (PolicySessionFeatureApi feature : PolicySessionFeatureApi.impl.getList()) {
+ for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
feature.destroyKieSession(session);
} catch (Exception e) {
@@ -685,7 +685,7 @@ public class PolicyContainer implements Startable {
logger.info("PolicyContainer.main: configDir={}", configDir);
// invoke 'globalInit' on all of the features
- for (PolicySessionFeatureApi feature : PolicySessionFeatureApi.impl.getList()) {
+ for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
feature.globalInit(args, configDir);
} catch (Exception e) {
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
index f27bb4ab..6352eaa2 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
@@ -143,7 +143,7 @@ public class PolicySession
// loop through all of the features, and give each one
// a chance to create the 'ThreadModel'
for (PolicySessionFeatureApi feature :
- PolicySessionFeatureApi.impl.getList()) {
+ PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
if ((threadModel = feature.selectThreadModel(this)) != null) {
break;
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java
index 3d259954..dd9ec154 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java
@@ -22,7 +22,6 @@ package org.onap.policy.drools.core;
import org.kie.api.runtime.KieSession;
import org.onap.policy.common.utils.services.OrderedService;
-import org.onap.policy.common.utils.services.OrderedServiceImpl;
/**
* This interface provides a way to invoke optional features at various
@@ -33,12 +32,6 @@ import org.onap.policy.common.utils.services.OrderedServiceImpl;
* may
*/
public interface PolicySessionFeatureApi extends OrderedService {
- /**
- * 'FeatureAPI.impl.getList()' returns an ordered list of objects
- * implementing the 'FeatureAPI' interface.
- */
- public static OrderedServiceImpl<PolicySessionFeatureApi> impl =
- new OrderedServiceImpl<>(PolicySessionFeatureApi.class);
/**
* This method is called during initialization at a point right after
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java
new file mode 100644
index 00000000..174ac794
--- /dev/null
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-core
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.core;
+
+import lombok.Getter;
+import org.onap.policy.common.utils.services.OrderedServiceImpl;
+
+public class PolicySessionFeatureApiConstants {
+ /**
+ * 'FeatureAPI.impl.getList()' returns an ordered list of objects
+ * implementing the 'FeatureAPI' interface.
+ */
+ @Getter
+ private static final OrderedServiceImpl<PolicySessionFeatureApi> impl =
+ new OrderedServiceImpl<>(PolicySessionFeatureApi.class);
+
+ private PolicySessionFeatureApiConstants() {
+ // do nothing
+ }
+}
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java
index ff7de049..b7968486 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java
@@ -21,7 +21,6 @@
package org.onap.policy.drools.core.lock;
import org.onap.policy.common.utils.services.OrderedService;
-import org.onap.policy.common.utils.services.OrderedServiceImpl;
/**
* Resource locks. Each lock has an "owner", which is intended to be unique across a
@@ -38,13 +37,6 @@ import org.onap.policy.common.utils.services.OrderedServiceImpl;
public interface PolicyResourceLockFeatureApi extends OrderedService {
/**
- * 'FeatureAPI.impl.getList()' returns an ordered list of objects implementing the
- * 'FeatureAPI' interface.
- */
- public static OrderedServiceImpl<PolicyResourceLockFeatureApi> impl =
- new OrderedServiceImpl<>(PolicyResourceLockFeatureApi.class);
-
- /**
* Result of a requested operation.
*/
public enum OperResult {
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiConstants.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiConstants.java
new file mode 100644
index 00000000..8510e3d9
--- /dev/null
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiConstants.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * api-resource-locks
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.core.lock;
+
+import lombok.Getter;
+import org.onap.policy.common.utils.services.OrderedServiceImpl;
+
+public class PolicyResourceLockFeatureApiConstants {
+
+ /**
+ * 'FeatureAPI.impl.getList()' returns an ordered list of objects implementing the
+ * 'FeatureAPI' interface.
+ */
+ @Getter
+ private static final OrderedServiceImpl<PolicyResourceLockFeatureApi> impl =
+ new OrderedServiceImpl<>(PolicyResourceLockFeatureApi.class);
+
+ private PolicyResourceLockFeatureApiConstants() {
+ // do nothing
+ }
+}
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java
index 487814cb..0e73eac1 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -43,7 +43,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
/**
* Get instance.
- *
+ *
* @return the manager singleton
*/
public static PolicyResourceLockManager getInstance() {
@@ -118,7 +118,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
/**
* Is locked.
- *
+ *
* @throws IllegalArgumentException if the resourceId is {@code null}
*/
@Override
@@ -128,7 +128,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
}
- return doBoolIntercept(impl -> impl.beforeIsLocked(resourceId), () ->
+ return doBoolIntercept(impl -> impl.beforeIsLocked(resourceId), () ->
// implementer didn't do the work - defer to the superclass
super.isLocked(resourceId)
@@ -137,7 +137,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
/**
* Is locked by.
- *
+ *
* @throws IllegalArgumentException if the resourceId or owner is {@code null}
*/
@Override
@@ -150,7 +150,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
throw makeNullArgException(MSG_NULL_OWNER);
}
- return doBoolIntercept(impl -> impl.beforeIsLockedBy(resourceId, owner), () ->
+ return doBoolIntercept(impl -> impl.beforeIsLockedBy(resourceId, owner), () ->
// implementer didn't do the work - defer to the superclass
super.isLockedBy(resourceId, owner)
@@ -161,7 +161,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
* Applies a function to each implementer of the lock feature. Returns as soon as one
* of them returns a result other than <b>OPER_UNHANDLED</b>. If they all return
* <b>OPER_UNHANDLED</b>, then it returns the result of applying the default function.
- *
+ *
* @param interceptFunc intercept function
* @param defaultFunc default function
* @return {@code true} if success, {@code false} otherwise
@@ -180,7 +180,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
/**
* Applies a function to each implementer of the lock feature. Returns as soon as one
* of them returns a non-null value.
- *
+ *
* @param continueValue if the implementer returns this value, then it continues to
* check addition implementers
* @param func function to be applied to the implementers
@@ -208,11 +208,11 @@ public class PolicyResourceLockManager extends SimpleLockManager {
/**
* Get implementers.
- *
+ *
* @return the list of feature implementers
*/
protected List<PolicyResourceLockFeatureApi> getImplementers() {
- return PolicyResourceLockFeatureApi.impl.getList();
+ return PolicyResourceLockFeatureApiConstants.getImpl().getList();
}
/**
@@ -221,7 +221,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
private static class Singleton {
private static final PolicyResourceLockManager instance = new PolicyResourceLockManager();
-
+
/**
* Not invoked.
*/
diff --git a/policy-core/src/main/java/org/onap/policy/drools/properties/DroolsProperties.java b/policy-core/src/main/java/org/onap/policy/drools/properties/DroolsPropertyConstants.java
index 0b7a6503..f14486bc 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/properties/DroolsProperties.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/properties/DroolsPropertyConstants.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,18 +20,22 @@
package org.onap.policy.drools.properties;
-public interface DroolsProperties {
+public class DroolsPropertyConstants {
/* Controller Properties */
- String PROPERTY_CONTROLLER_NAME = "controller.name";
+ public static final String PROPERTY_CONTROLLER_NAME = "controller.name";
- String DEFAULT_CONTROLLER_POLICY_TYPE_VERSION = "1.0.0";
- String PROPERTY_CONTROLLER_POLICY_TYPES = "controller.policy.types";
+ public static final String DEFAULT_CONTROLLER_POLICY_TYPE_VERSION = "1.0.0";
+ public static final String PROPERTY_CONTROLLER_POLICY_TYPES = "controller.policy.types";
/* Drools Properties */
- String RULES_GROUPID = "rules.groupId";
- String RULES_ARTIFACTID = "rules.artifactId";
- String RULES_VERSION = "rules.version";
+ public static final String RULES_GROUPID = "rules.groupId";
+ public static final String RULES_ARTIFACTID = "rules.artifactId";
+ public static final String RULES_VERSION = "rules.version";
+
+ private DroolsPropertyConstants() {
+ // do nothing
+ }
}