aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management
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-management
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-management')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java64
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerConstants.java51
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java14
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java27
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java15
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApi.java7
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApiConstants.java38
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApi.java7
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApiConstants.java38
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApi.java6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApiConstants.java37
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java18
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java10
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistenceConstants.java41
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java5
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderConstants.java37
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java20
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java13
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java481
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafBase.java6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java3
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/Main.java34
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java17
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerConstants.java36
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java19
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java51
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java59
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java25
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java34
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java6
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java7
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java103
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java6
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java12
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java39
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java8
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java102
37 files changed, 913 insertions, 583 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 4347614f..dd654b1d 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
@@ -7,9 +7,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.
@@ -35,56 +35,36 @@ import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
public interface DroolsController extends Startable, Lockable {
/**
- * No Group ID identifier.
- */
- String NO_GROUP_ID = "NO-GROUP-ID";
-
- /**
- * No Artifact ID identifier.
- */
- String NO_ARTIFACT_ID = "NO-ARTIFACT-ID";
-
- /**
- * No version identifier.
- */
- String NO_VERSION = "NO-VERSION";
-
- /**
- * Factory to track and manage drools controllers.
- */
- DroolsControllerFactory factory = new IndexedDroolsControllerFactory();
-
- /**
* get group id.
- *
+ *
* @return group id
*/
String getGroupId();
/**
* get artifact id.
- *
+ *
* @return artifact id
*/
String getArtifactId();
/**
* get version.
- *
+ *
* @return version
*/
String getVersion();
/**
* return the policy session names.
- *
+ *
* @return policy session
*/
List<String> getSessionNames();
/**
* return the policy full session names.
- *
+ *
* @return policy session
*/
List<String> getCanonicalSessionNames();
@@ -98,10 +78,10 @@ public interface DroolsController extends Startable, Lockable {
/**
* offers a raw event to this controller for processing.
- *
+ *
* @param topic topic associated with the event
* @param event the event
- *
+ *
* @return true if the operation was successful
*/
boolean offer(String topic, String event);
@@ -117,7 +97,7 @@ public interface DroolsController extends Startable, Lockable {
/**
* delivers "event" to "sink".
- *
+ *
* @param sink destination
* @param event event
* @return true if successful, false if a failure has occurred.
@@ -131,28 +111,28 @@ public interface DroolsController extends Startable, Lockable {
/**
* Get recent source events.
- *
+ *
* @return the most recent received events.
*/
Object[] getRecentSourceEvents();
/**
* Get recent sink events.
- *
+ *
* @return the most recent delivered events
*/
String[] getRecentSinkEvents();
/**
* Get container.
- *
+ *
* @return the underlying policy container
*/
PolicyContainer getContainer();
/**
* Does it owns the coder.
- *
+ *
* @param coderClass the encoder object
* @param modelHash the hash for the model
* @return true it owns it
@@ -161,7 +141,7 @@ public interface DroolsController extends Startable, Lockable {
/**
* fetches a class from the model.
- *
+ *
* @param className the class to fetch
* @return the actual class object, or null if not found
*/
@@ -174,13 +154,13 @@ public interface DroolsController extends Startable, Lockable {
/**
* update the new version of the maven jar rules file.
- *
+ *
* @param newGroupId - new group id
* @param newArtifactId - new artifact id
* @param newVersion - new version
* @param decoderConfigurations - decoder configurations
* @param encoderConfigurations - encoder configurations
- *
+ *
* @throws Exception from within drools libraries
* @throws LinkageError from within drools libraries
*/
@@ -190,7 +170,7 @@ public interface DroolsController extends Startable, Lockable {
/**
* gets the classnames of facts as well as the current count.
- *
+ *
* @param sessionName the session name
* @return map of class to count
*/
@@ -198,7 +178,7 @@ public interface DroolsController extends Startable, Lockable {
/**
* gets the count of facts for a given session.
- *
+ *
* @param sessionName the session name
* @return the fact count
*/
@@ -206,7 +186,7 @@ public interface DroolsController extends Startable, Lockable {
/**
* gets all the facts of a given class for a given session.
- *
+ *
* @param sessionName the session identifier
* @param className the class type
* @param delete retract from drools the results of the query?
@@ -221,7 +201,7 @@ public interface DroolsController extends Startable, Lockable {
/**
* gets the facts associated with a query for a give session for a given queried entity.
- *
+ *
* @param sessionName the session
* @param queryName the query identifier
* @param queriedEntity the queried entity
@@ -254,7 +234,7 @@ public interface DroolsController extends Startable, Lockable {
/**
* halts and permanently releases all resources.
- *
+ *
*/
void halt();
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerConstants.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerConstants.java
new file mode 100644
index 00000000..16cf3592
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerConstants.java
@@ -0,0 +1,51 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.controller;
+
+import lombok.Getter;
+
+public class DroolsControllerConstants {
+
+ /**
+ * No Group ID identifier.
+ */
+ public static final String NO_GROUP_ID = "NO-GROUP-ID";
+
+ /**
+ * No Artifact ID identifier.
+ */
+ public static final String NO_ARTIFACT_ID = "NO-ARTIFACT-ID";
+
+ /**
+ * No version identifier.
+ */
+ public static final String NO_VERSION = "NO-VERSION";
+
+ /**
+ * Factory to track and manage drools controllers.
+ */
+ @Getter
+ private static final DroolsControllerFactory factory = new IndexedDroolsControllerFactory();
+
+ private DroolsControllerConstants() {
+ // do nothing
+ }
+}
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 89e2a1a8..733a492d 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
@@ -32,7 +32,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.drools.controller.internal.MavenDroolsController;
import org.onap.policy.drools.controller.internal.NullDroolsController;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
@@ -79,19 +79,19 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
public DroolsController build(Properties properties, List<? extends TopicSource> eventSources,
List<? extends TopicSink> eventSinks) throws LinkageError {
- String groupId = properties.getProperty(DroolsProperties.RULES_GROUPID);
+ String groupId = properties.getProperty(DroolsPropertyConstants.RULES_GROUPID);
if (groupId == null || groupId.isEmpty()) {
- groupId = DroolsController.NO_GROUP_ID;
+ groupId = DroolsControllerConstants.NO_GROUP_ID;
}
- String artifactId = properties.getProperty(DroolsProperties.RULES_ARTIFACTID);
+ String artifactId = properties.getProperty(DroolsPropertyConstants.RULES_ARTIFACTID);
if (artifactId == null || artifactId.isEmpty()) {
- artifactId = DroolsController.NO_ARTIFACT_ID;
+ artifactId = DroolsControllerConstants.NO_ARTIFACT_ID;
}
- String version = properties.getProperty(DroolsProperties.RULES_VERSION);
+ String version = properties.getProperty(DroolsPropertyConstants.RULES_VERSION);
if (version == null || version.isEmpty()) {
- version = DroolsController.NO_VERSION;
+ version = DroolsControllerConstants.NO_VERSION;
}
List<TopicCoderFilterConfiguration> topics2DecodedClasses2Filters = codersAndFilters(properties, eventSources);
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 b09ae85c..ca1f2283 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
@@ -43,11 +43,14 @@ import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
import org.onap.policy.common.utils.services.OrderedServiceImpl;
import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.core.PolicyContainer;
import org.onap.policy.drools.core.PolicySession;
import org.onap.policy.drools.core.jmx.PdpJmx;
import org.onap.policy.drools.features.DroolsControllerFeatureApi;
+import org.onap.policy.drools.features.DroolsControllerFeatureApiConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolParams;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
@@ -64,6 +67,8 @@ import org.slf4j.LoggerFactory;
*/
public class MavenDroolsController implements DroolsController {
+ private static final String FACT_RETRIEVE_ERROR = "Object cannot be retrieved from fact {}";
+
/**
* logger.
*/
@@ -193,9 +198,9 @@ public class MavenDroolsController implements DroolsController {
throw new IllegalArgumentException("Missing maven version coordinate");
}
- if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID)
- || newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID)
- || newVersion.equalsIgnoreCase(DroolsController.NO_VERSION)) {
+ if (newGroupId.equalsIgnoreCase(DroolsControllerConstants.NO_GROUP_ID)
+ || newArtifactId.equalsIgnoreCase(DroolsControllerConstants.NO_ARTIFACT_ID)
+ || newVersion.equalsIgnoreCase(DroolsControllerConstants.NO_VERSION)) {
throw new IllegalArgumentException("BRAINLESS maven coordinates provided: "
+ newGroupId + ":" + newArtifactId + ":"
+ newVersion);
@@ -755,7 +760,7 @@ public class MavenDroolsController implements DroolsController {
classNames.put(className, 1);
}
} catch (Exception e) {
- logger.warn("Object cannot be retrieved from fact {}", fact, e);
+ logger.warn(FACT_RETRIEVE_ERROR, fact, e);
}
}
@@ -803,7 +808,7 @@ public class MavenDroolsController implements DroolsController {
kieSession.delete(factHandle);
}
} catch (Exception e) {
- logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
+ logger.warn(FACT_RETRIEVE_ERROR, factHandle, e);
}
}
@@ -881,7 +886,7 @@ public class MavenDroolsController implements DroolsController {
return true;
}
} catch (Exception e) {
- logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
+ logger.warn(FACT_RETRIEVE_ERROR, factHandle, e);
}
}
return false;
@@ -889,7 +894,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public <T> boolean delete(@NonNull T fact) {
- return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
+ return this.getSessionNames().stream().map(ss -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
}
@Override
@@ -903,7 +908,7 @@ public class MavenDroolsController implements DroolsController {
try {
kieSession.delete(factHandle);
} catch (Exception e) {
- logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
+ logger.warn(FACT_RETRIEVE_ERROR, factHandle, e);
success = false;
}
}
@@ -912,7 +917,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public <T> boolean delete(@NonNull Class<T> fact) {
- return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
+ return this.getSessionNames().stream().map(ss -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
}
@@ -972,11 +977,11 @@ public class MavenDroolsController implements DroolsController {
// these may be overridden by junit tests
protected EventProtocolCoder getCoderManager() {
- return EventProtocolCoder.manager;
+ return EventProtocolCoderConstants.getManager();
}
protected OrderedServiceImpl<DroolsControllerFeatureApi> getDroolsProviders() {
- return DroolsControllerFeatureApi.providers;
+ return DroolsControllerFeatureApiConstants.getProviders();
}
protected PolicyContainer makePolicyContainer(String groupId, String artifactId, String version) {
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 4b38e722..5416d321 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
@@ -7,9 +7,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.
@@ -28,6 +28,7 @@ import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.core.PolicyContainer;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
@@ -78,17 +79,17 @@ public class NullDroolsController implements DroolsController {
@Override
public String getGroupId() {
- return NO_GROUP_ID;
+ return DroolsControllerConstants.NO_GROUP_ID;
}
@Override
public String getArtifactId() {
- return NO_ARTIFACT_ID;
+ return DroolsControllerConstants.NO_ARTIFACT_ID;
}
@Override
public String getVersion() {
- return NO_VERSION;
+ return DroolsControllerConstants.NO_VERSION;
}
@Override
@@ -187,8 +188,8 @@ public class NullDroolsController implements DroolsController {
}
@Override
- public List<Object> factQuery(String sessionName, String queryName,
- String queriedEntity,
+ public List<Object> factQuery(String sessionName, String queryName,
+ String queriedEntity,
boolean delete, Object... queryParams) {
return new ArrayList<>();
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApi.java b/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApi.java
index d5a16a12..abf524e4 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApi.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApi.java
@@ -22,7 +22,6 @@ package org.onap.policy.drools.features;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.services.OrderedService;
-import org.onap.policy.common.utils.services.OrderedServiceImpl;
import org.onap.policy.drools.controller.DroolsController;
/**
@@ -74,10 +73,4 @@ public interface DroolsControllerFeatureApi extends OrderedService {
boolean success) {
return false;
}
-
- /**
- * Feature providers implementing this interface.
- */
- public static final OrderedServiceImpl<DroolsControllerFeatureApi> providers =
- new OrderedServiceImpl<>(DroolsControllerFeatureApi.class);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApiConstants.java b/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApiConstants.java
new file mode 100644
index 00000000..5ff8e86f
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureApiConstants.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.features;
+
+import lombok.Getter;
+import org.onap.policy.common.utils.services.OrderedServiceImpl;
+
+public class DroolsControllerFeatureApiConstants {
+
+ /**
+ * Feature providers implementing this interface.
+ */
+ @Getter
+ private static final OrderedServiceImpl<DroolsControllerFeatureApi> providers =
+ new OrderedServiceImpl<>(DroolsControllerFeatureApi.class);
+
+ private DroolsControllerFeatureApiConstants() {
+ // do nothing
+ }
+}
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 c9e78c6a..9c6ac223 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
@@ -23,18 +23,11 @@ package org.onap.policy.drools.features;
import java.util.Properties;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.services.OrderedService;
-import org.onap.policy.common.utils.services.OrderedServiceImpl;
import org.onap.policy.drools.system.PolicyController;
public interface PolicyControllerFeatureApi extends OrderedService {
/**
- * Feature providers implementing this interface.
- */
- OrderedServiceImpl<PolicyControllerFeatureApi> providers =
- new OrderedServiceImpl<>(PolicyControllerFeatureApi.class);
-
- /**
* called before creating a controller with name 'name' and
* properties 'properties'.
*
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApiConstants.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApiConstants.java
new file mode 100644
index 00000000..230228f0
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApiConstants.java
@@ -0,0 +1,38 @@
+/*
+ * ============LICENSE_START=======================================================
+ * policy-management
+ * ================================================================================
+ * 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.features;
+
+import lombok.Getter;
+import org.onap.policy.common.utils.services.OrderedServiceImpl;
+
+public class PolicyControllerFeatureApiConstants {
+
+ /**
+ * Feature providers implementing this interface.
+ */
+ @Getter
+ private static final OrderedServiceImpl<PolicyControllerFeatureApi> providers =
+ new OrderedServiceImpl<>(PolicyControllerFeatureApi.class);
+
+ private PolicyControllerFeatureApiConstants() {
+ // do nothing
+ }
+}
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 bd834c4d..b6d827a4 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
@@ -23,7 +23,6 @@ package org.onap.policy.drools.features;
import java.util.Properties;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.services.OrderedService;
-import org.onap.policy.common.utils.services.OrderedServiceImpl;
import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
import org.onap.policy.drools.system.PolicyEngine;
@@ -32,11 +31,6 @@ import org.onap.policy.drools.system.PolicyEngine;
* Provides Interception Points during the Policy Engine lifecycle.
*/
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.
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApiConstants.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApiConstants.java
new file mode 100644
index 00000000..e62714a5
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApiConstants.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-engine
+ * ================================================================================
+ * 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.features;
+
+import lombok.Getter;
+import org.onap.policy.common.utils.services.OrderedServiceImpl;
+
+public class PolicyEngineFeatureApiConstants {
+ /**
+ * Feature providers implementing this interface.
+ */
+ @Getter
+ private static final OrderedServiceImpl<PolicyEngineFeatureApi> providers =
+ new OrderedServiceImpl<>(PolicyEngineFeatureApi.class);
+
+ private PolicyEngineFeatureApiConstants() {
+ // do nothing
+ }
+}
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 88987eab..ca1ad371 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
@@ -34,7 +34,7 @@ import java.util.List;
import java.util.Properties;
import java.util.function.BiPredicate;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.utils.PropertyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -111,7 +111,7 @@ public class FileSystemPersistence implements SystemPersistence {
/**
* Configuration directory.
*/
- protected Path configurationDirectory = Paths.get(DEFAULT_CONFIGURATION_DIR);
+ protected Path configurationDirectory = Paths.get(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR);
/**
* Logger.
@@ -123,11 +123,11 @@ public class FileSystemPersistence implements SystemPersistence {
String tempConfigDir = configDir;
if (tempConfigDir == null) {
- tempConfigDir = DEFAULT_CONFIGURATION_DIR;
- this.configurationDirectory = Paths.get(DEFAULT_CONFIGURATION_DIR);
+ tempConfigDir = SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR;
+ this.configurationDirectory = Paths.get(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR);
}
- if (!tempConfigDir.equals(DEFAULT_CONFIGURATION_DIR)) {
+ if (!tempConfigDir.equals(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR)) {
this.configurationDirectory = Paths.get(tempConfigDir);
}
@@ -263,9 +263,9 @@ public class FileSystemPersistence implements SystemPersistence {
private boolean testControllerName(String controllerFilename, Properties controllerProperties) {
String controllerName = controllerFilename
.substring(0, controllerFilename.length() - PROPERTIES_FILE_CONTROLLER_SUFFIX.length());
- String controllerPropName = controllerProperties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
+ String controllerPropName = controllerProperties.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME);
if (controllerPropName == null) {
- controllerProperties.setProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME, controllerName);
+ controllerProperties.setProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, controllerName);
} else if (!controllerPropName.equals(controllerName)) {
logger.error("{}: mismatch controller named {} against {} in file {}",
this, controllerPropName, controllerName, controllerFilename);
@@ -290,7 +290,7 @@ public class FileSystemPersistence implements SystemPersistence {
if (Files.exists(path)) {
try {
logger.info("{}: there is an existing configuration file @ {} ", this, path);
- Path bakPath = Paths.get(this.configurationDirectory.toString(),
+ Path bakPath = Paths.get(this.configurationDirectory.toString(),
name + fileSuffix + FILE_BACKUP_SUFFIX);
Files.copy(path, bakPath, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
@@ -365,7 +365,7 @@ public class FileSystemPersistence implements SystemPersistence {
if (Files.exists(path)) {
try {
- Path bakPath = Paths.get(this.configurationDirectory.toString(),
+ Path bakPath = Paths.get(this.configurationDirectory.toString(),
name + fileSuffix + FILE_BACKUP_SUFFIX);
Files.move(path, bakPath, StandardCopyOption.REPLACE_EXISTING);
} catch (final Exception e) {
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 ee1e8b52..d5a35c32 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
@@ -28,16 +28,6 @@ import java.util.Properties;
* System Configuration.
*/
public interface SystemPersistence {
- /**
- * configuration directory.
- */
- 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.
- */
- SystemPersistence manager = new FileSystemPersistence();
/**
* sets a configuration directory and ensures it exists.
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistenceConstants.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistenceConstants.java
new file mode 100644
index 00000000..0b46fb02
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistenceConstants.java
@@ -0,0 +1,41 @@
+/*
+ * ============LICENSE_START=======================================================
+ * policy-management
+ * ================================================================================
+ * 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.persistence;
+
+import lombok.Getter;
+
+public class SystemPersistenceConstants {
+ /**
+ * configuration directory.
+ */
+ 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.
+ */
+ @Getter
+ private static final SystemPersistence manager = new FileSystemPersistence();
+
+ private SystemPersistenceConstants() {
+ // do nothing
+ }
+}
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 62a0cbe2..6cbe94ae 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
@@ -29,11 +29,6 @@ import org.onap.policy.drools.controller.DroolsController;
*/
public interface EventProtocolCoder {
- /**
- * singleton reference to the global event protocol coder.
- */
- public static EventProtocolCoder manager = new MultiplexorEventProtocolCoder();
-
public static class CoderFilters {
/**
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderConstants.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderConstants.java
new file mode 100644
index 00000000..45dc39e4
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderConstants.java
@@ -0,0 +1,37 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright(C) 2018 Samsung Electronics Co., Ltd.
+ * ================================================================================
+ * 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.protocol.coders;
+
+import lombok.Getter;
+
+public class EventProtocolCoderConstants {
+
+ /**
+ * singleton reference to the global event protocol coder.
+ */
+ @Getter
+ private static final EventProtocolCoder manager = new MultiplexorEventProtocolCoder();
+
+ private EventProtocolCoderConstants() {
+ // do nothing
+ }
+}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java
index 8643da3d..89a7a420 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,15 +36,11 @@ import org.slf4j.LoggerFactory;
* 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 UNSUPPORTED_EX_MSG = "Unsupported:";
private static final String MISSING_CLASS = "class must be provided";
private static Logger logger = LoggerFactory.getLogger(GenericEventProtocolCoder.class);
@@ -287,7 +284,7 @@ abstract class GenericEventProtocolCoder {
if (!isCodingSupported(groupId, artifactId, topic)) {
throw new IllegalArgumentException(
- "Unsupported:" + codersKey(groupId, artifactId, topic) + " for encoding");
+ UNSUPPORTED_EX_MSG + codersKey(groupId, artifactId, topic) + " for encoding");
}
String key = this.codersKey(groupId, artifactId, topic);
@@ -318,7 +315,7 @@ abstract class GenericEventProtocolCoder {
public String encode(String groupId, String artifactId, String topic, Object event) {
if (!isCodingSupported(groupId, artifactId, topic)) {
- throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
+ throw new IllegalArgumentException(UNSUPPORTED_EX_MSG + codersKey(groupId, artifactId, topic));
}
if (event == null) {
@@ -455,7 +452,8 @@ abstract class GenericEventProtocolCoder {
List<CoderFilters> coderFilters = encoderSet.getCoders();
for (CoderFilters coder : coderFilters) {
if (coder.getCodedClass().equals(encodedClass.getClass().getName())) {
- DroolsController droolsController = DroolsController.factory.get(groupId, artifactId, "");
+ DroolsController droolsController =
+ DroolsControllerConstants.getFactory().get(groupId, artifactId, "");
if (droolsController.ownsCoder(
encodedClass.getClass(), coder.getModelClassLoaderHash())) {
droolsControllers.add(droolsController);
@@ -487,7 +485,7 @@ abstract class GenericEventProtocolCoder {
public List<CoderFilters> getFilters(String groupId, String artifactId, String topic) {
if (!isCodingSupported(groupId, artifactId, topic)) {
- throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
+ throw new IllegalArgumentException(UNSUPPORTED_EX_MSG + codersKey(groupId, artifactId, topic));
}
String key = this.codersKey(groupId, artifactId, topic);
@@ -540,7 +538,7 @@ abstract class GenericEventProtocolCoder {
String groupId, String artifactId, String topic, String classname) {
if (!isCodingSupported(groupId, artifactId, topic)) {
- throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
+ throw new IllegalArgumentException(UNSUPPORTED_EX_MSG + codersKey(groupId, artifactId, topic));
}
if (classname == null || classname.isEmpty()) {
@@ -565,7 +563,7 @@ abstract class GenericEventProtocolCoder {
String groupId, String artifactId, String topic) {
if (!isCodingSupported(groupId, artifactId, topic)) {
- throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
+ throw new IllegalArgumentException(UNSUPPORTED_EX_MSG + codersKey(groupId, artifactId, topic));
}
String key = this.codersKey(groupId, artifactId, topic);
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java
index 57976a3e..ff154fb5 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java
@@ -37,6 +37,7 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,6 +46,8 @@ import org.slf4j.LoggerFactory;
* Tools used for encoding/decoding using GSON.
*/
class GsonProtocolCoderToolset extends ProtocolCoderToolset {
+ private static final String FETCH_CLASS_EX_MSG = "cannot fetch application class ";
+
/**
* Logger.
*/
@@ -155,7 +158,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
public Object decode(String json) {
final DroolsController droolsController =
- DroolsController.factory.get(this.groupId, this.artifactId, "");
+ DroolsControllerConstants.getFactory().get(this.groupId, this.artifactId, "");
if (droolsController == null) {
logger.warn("{}: no drools-controller to process {}", this, json);
throw new IllegalStateException("no drools-controller to process event");
@@ -173,13 +176,13 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
if (decoderClass == null) {
logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass());
throw new IllegalStateException(
- "cannot fetch application class " + decoderFilter.getCodedClass());
+ FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass());
}
} catch (final Exception e) {
logger.warn("{}: cannot fetch application class {} because of {}", this,
decoderFilter.getCodedClass(), e.getMessage());
throw new UnsupportedOperationException(
- "cannot fetch application class " + decoderFilter.getCodedClass(), e);
+ FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass(), e);
}
if (this.customCoder != null) {
@@ -195,7 +198,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
logger.warn("{}: cannot fetch application class {} because of {}", this,
decoderFilter.getCodedClass(), e.getMessage());
throw new UnsupportedOperationException(
- "cannot fetch application class " + decoderFilter.getCodedClass(), e);
+ FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass(), e);
}
} else {
try {
@@ -218,7 +221,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
if (this.customCoder != null) {
try {
final DroolsController droolsController =
- DroolsController.factory.get(this.groupId, this.artifactId, null);
+ DroolsControllerConstants.getFactory().get(this.groupId, this.artifactId, null);
final Class<?> gsonClassContainer =
droolsController.fetchModelClass(this.customCoder.getClassContainer());
final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
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 a5fbfdd3..2d40a1f1 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
@@ -58,15 +58,17 @@ import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.features.PolicyControllerFeatureApi;
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
-import org.onap.policy.drools.properties.DroolsProperties;
-import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.coders.ProtocolCoderToolset;
import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyControllerConstants;
import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -84,10 +86,49 @@ import org.slf4j.LoggerFactory;
schemes = {SwaggerDefinition.Scheme.HTTP},
tags = {@Tag(name = "pdp-d-telemetry", description = "Drools PDP Telemetry Operations")})
public class RestManager {
+
+ private static final String CANNOT_PERFORM_OPERATION = "cannot perform operation";
+ private static final String NO_FILTERS = " no filters";
+ private static final String NOT_FOUND = " not found: ";
+ private static final String NOT_FOUND_MSG = " not found";
+ private static final String DOES_NOT_EXIST_MSG = " does not exist";
+ private static final String NOT_ACCEPTABLE_MSG = " not acceptable";
+ private static final String FETCH_POLICY_FAILED = "{}: cannot get policy-controller because of {}";
+ private static final String FETCH_POLICY_BY_NAME_FAILED = "{}: cannot get policy-controller {} because of {}";
+ private static final String FETCH_POLICY_BY_TOPIC_FAILED =
+ "{}: cannot get policy-controller {} topic {} because of {}";
+ private static final String FETCH_DROOLS_FAILED = "{}: cannot get drools-controller {} because of {}";
+ private static final String FETCH_DROOLS_BY_ENTITY_FAILED =
+ "{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}";
+ private static final String FETCH_DROOLS_BY_PARAMS_FAILED =
+ "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}";
+ private static final String FETCH_DROOLS_BY_FACTTYPE_FAILED =
+ "{}: cannot get: drools-controller {}, session {}, factType {}, because of {}";
+ private static final String FETCH_DECODERS_BY_POLICY_FAILED =
+ "{}: cannot get decoders for policy-controller {} because of {}";
+ private static final String FETCH_DECODERS_BY_TOPIC_FAILED =
+ "{}: cannot get decoders for policy-controller {} topic {} because of {}";
+ private static final String FETCH_DECODER_BY_TYPE_FAILED =
+ "{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}";
+ private static final String FETCH_DECODER_BY_FILTER_FAILED =
+ "{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}";
+ private static final String FETCH_ENCODER_BY_FILTER_FAILED =
+ "{}: cannot get encoder filters for policy-controller {} because of {}";
+
/**
* Logger.
*/
- private static Logger logger = LoggerFactory.getLogger(RestManager.class);
+ private static final Logger logger = LoggerFactory.getLogger(RestManager.class);
+
+ /**
+ * Feed Ports into Resources.
+ */
+ private static final List<String> INPUTS = Arrays.asList("configuration");
+
+ /**
+ * Resource Toggles.
+ */
+ private static final List<String> SWITCHES = Arrays.asList("activation", "lock");
/**
* GET.
@@ -99,7 +140,7 @@ public class RestManager {
@ApiOperation(value = "Retrieves the Engine Operational Status",
notes = "Top-level abstraction. Provides a global view of resources", response = PolicyEngine.class)
public Response engine() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build();
}
/**
@@ -114,13 +155,14 @@ public class RestManager {
response = PolicyEngine.class)
public Response engineShutdown() {
try {
- PolicyEngine.manager.shutdown();
+ PolicyEngineConstants.getManager().shutdown();
} catch (final IllegalStateException e) {
- logger.error("{}: cannot shutdown {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
- return Response.status(Response.Status.BAD_REQUEST).entity(PolicyEngine.manager).build();
+ logger.error("{}: cannot shutdown {} because of {}", this, PolicyEngineConstants.getManager(),
+ e.getMessage(), e);
+ return Response.status(Response.Status.BAD_REQUEST).entity(PolicyEngineConstants.getManager()).build();
}
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build();
}
/**
@@ -133,7 +175,7 @@ public class RestManager {
@ApiOperation(value = "Engine Features",
notes = "Provides the list of loaded features using the PolicyEngineFeatureAPI", responseContainer = "List")
public Response engineFeatures() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatures()).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getFeatures()).build();
}
@GET
@@ -142,7 +184,8 @@ public class RestManager {
notes = "Provides detailed list of loaded features using the PolicyEngineFeatureAPI",
responseContainer = "List", response = PolicyEngineFeatureApi.class)
public Response engineFeaturesInventory() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatureProviders()).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getFeatureProviders())
+ .build();
}
/**
@@ -158,8 +201,8 @@ public class RestManager {
public Response engineFeature(
@ApiParam(value = "Feature Name", required = true) @PathParam("featureName") String featureName) {
try {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatureProvider(featureName))
- .build();
+ return Response.status(Response.Status.OK)
+ .entity(PolicyEngineConstants.getManager().getFeatureProvider(featureName)).build();
} catch (final IllegalArgumentException iae) {
logger.debug("feature unavailable: {}", featureName, iae);
return Response.status(Response.Status.NOT_FOUND).entity(new Error(iae.getMessage())).build();
@@ -175,7 +218,7 @@ public class RestManager {
@Path("engine/inputs")
@ApiOperation(value = "Engine Input Ports", notes = "List of input ports", responseContainer = "List")
public Response engineInputs() {
- return Response.status(Response.Status.OK).entity(Arrays.asList(Inputs.values())).build();
+ return Response.status(Response.Status.OK).entity(INPUTS).build();
}
/**
@@ -193,14 +236,15 @@ public class RestManager {
final PolicyController controller = null;
boolean success;
try {
- success = PolicyEngine.manager.configure(configuration);
+ success = PolicyEngineConstants.getManager().configure(configuration);
} catch (final Exception e) {
success = false;
- logger.info("{}: cannot configure {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
+ logger.info("{}: cannot configure {} because of {}", this, PolicyEngineConstants.getManager(),
+ e.getMessage(), e);
}
if (!success) {
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation"))
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION))
.build();
} else {
return Response.status(Response.Status.OK).entity(controller).build();
@@ -217,7 +261,7 @@ public class RestManager {
@ApiOperation(value = "Engine Configuration Properties", notes = "Used for booststrapping the engine",
response = Properties.class)
public Response engineProperties() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getProperties()).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getProperties()).build();
}
/**
@@ -230,7 +274,7 @@ public class RestManager {
@ApiOperation(value = "Engine Environment Properties",
notes = "Installation and OS environment properties used by the engine", response = Properties.class)
public Response engineEnvironment() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getEnvironment()).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getEnvironment()).build();
}
/**
@@ -243,9 +287,10 @@ public class RestManager {
@Consumes(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Gets an environment variable", response = String.class)
public Response engineEnvironment(
- @ApiParam(value = "Environment Property", required = true) @PathParam("envProperty") String envProperty) {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getEnvironmentProperty(envProperty))
- .build();
+ @ApiParam(value = "Environment Property",
+ required = true) @PathParam("envProperty") String envProperty) {
+ return Response.status(Response.Status.OK)
+ .entity(PolicyEngineConstants.getManager().getEnvironmentProperty(envProperty)).build();
}
/**
@@ -261,7 +306,7 @@ public class RestManager {
public Response engineEnvironmentAdd(
@ApiParam(value = "Environment Property", required = true) @PathParam("envProperty") String envProperty,
@ApiParam(value = "Environment Value", required = true) String envValue) {
- final String previousValue = PolicyEngine.manager.setEnvironmentProperty(envProperty, envValue);
+ final String previousValue = PolicyEngineConstants.getManager().setEnvironmentProperty(envProperty, envValue);
return Response.status(Response.Status.OK).entity(previousValue).build();
}
@@ -275,7 +320,7 @@ public class RestManager {
@ApiOperation(value = "Engine Control Switches", notes = "List of the Engine Control Switches",
responseContainer = "List")
public Response engineSwitches() {
- return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
+ return Response.status(Response.Status.OK).entity(SWITCHES).build();
}
/**
@@ -292,17 +337,18 @@ public class RestManager {
public Response engineActivation() {
boolean success = true;
try {
- PolicyEngine.manager.activate();
+ PolicyEngineConstants.getManager().activate();
} catch (final Exception e) {
success = false;
- logger.info("{}: cannot activate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
+ logger.info("{}: cannot activate {} because of {}", this, PolicyEngineConstants.getManager(),
+ e.getMessage(), e);
}
if (!success) {
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation"))
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION))
.build();
} else {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build();
}
}
@@ -320,17 +366,18 @@ public class RestManager {
public Response engineDeactivation() {
boolean success = true;
try {
- PolicyEngine.manager.deactivate();
+ PolicyEngineConstants.getManager().deactivate();
} catch (final Exception e) {
success = false;
- logger.info("{}: cannot deactivate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
+ logger.info("{}: cannot deactivate {} because of {}", this, PolicyEngineConstants.getManager(),
+ e.getMessage(), e);
}
if (!success) {
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation"))
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION))
.build();
} else {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build();
}
}
@@ -347,11 +394,11 @@ public class RestManager {
@ApiResponses(value = {@ApiResponse(code = 406,
message = "The system is an administrative state that prevents " + "this request to be fulfilled")})
public Response engineLock() {
- final boolean success = PolicyEngine.manager.lock();
+ final boolean success = PolicyEngineConstants.getManager().lock();
if (success) {
- return Response.status(Status.OK).entity(PolicyEngine.manager).build();
+ return Response.status(Status.OK).entity(PolicyEngineConstants.getManager()).build();
} else {
- return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build();
+ return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build();
}
}
@@ -368,11 +415,11 @@ public class RestManager {
@ApiResponses(value = {@ApiResponse(code = 406,
message = "The system is an administrative state that prevents " + "this request to be fulfilled")})
public Response engineUnlock() {
- final boolean success = PolicyEngine.manager.unlock();
+ final boolean success = PolicyEngineConstants.getManager().unlock();
if (success) {
- return Response.status(Status.OK).entity(PolicyEngine.manager).build();
+ return Response.status(Status.OK).entity(PolicyEngineConstants.getManager()).build();
} else {
- return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build();
+ return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build();
}
}
@@ -386,7 +433,8 @@ public class RestManager {
@ApiOperation(value = "Lists the Policy Controllers Names", notes = "Unique Policy Controller Identifiers",
responseContainer = "List")
public Response controllers() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllerIds()).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getPolicyControllerIds())
+ .build();
}
/**
@@ -399,7 +447,8 @@ public class RestManager {
@ApiOperation(value = "Lists the Policy Controllers", notes = "Detailed list of Policy Controllers",
responseContainer = "List", response = PolicyController.class)
public Response controllerInventory() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllers()).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getPolicyControllers())
+ .build();
}
/**
@@ -424,17 +473,17 @@ public class RestManager {
.build();
}
- final String controllerName = config.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
+ final String controllerName = config.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME);
if (controllerName == null || controllerName.isEmpty()) {
return Response.status(Response.Status.BAD_REQUEST)
.entity(new Error(
- "Configuration must have an entry for " + DroolsProperties.PROPERTY_CONTROLLER_NAME))
+ "Configuration must have an entry for " + DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME))
.build();
}
PolicyController controller;
try {
- controller = PolicyController.factory.get(controllerName);
+ controller = PolicyControllerConstants.getFactory().get(controllerName);
if (controller != null) {
return Response.status(Response.Status.NOT_MODIFIED).entity(controller).build();
}
@@ -442,14 +491,14 @@ public class RestManager {
logger.trace("OK ", e);
// This is OK
} catch (final IllegalStateException e) {
- logger.info("{}: cannot get policy-controller because of {}", this, e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not found"))
+ logger.info(FETCH_POLICY_FAILED, this, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + NOT_FOUND_MSG))
.build();
}
try {
- controller = PolicyEngine.manager
- .createPolicyController(config.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME), config);
+ controller = PolicyEngineConstants.getManager().createPolicyController(
+ config.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME), config);
} catch (IllegalArgumentException | IllegalStateException e) {
logger.warn("{}: cannot create policy-controller because of {}", this, e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST).entity(new Error(e.getMessage())).build();
@@ -480,7 +529,7 @@ public class RestManager {
@ApiOperation(value = "Lists of Feature Providers Identifiers", notes = "Unique Policy Controller Identifiers",
responseContainer = "List")
public Response controllerFeatures() {
- return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatures()).build();
+ return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getFeatures()).build();
}
/**
@@ -494,7 +543,8 @@ public class RestManager {
notes = "Provides detailed list of loaded features using the PolicyControllerFeatureAPI",
responseContainer = "List", response = PolicyControllerFeatureApi.class)
public Response controllerFeaturesInventory() {
- return Response.status(Response.Status.OK).entity(PolicyController.factory.getFeatureProviders()).build();
+ return Response.status(Response.Status.OK)
+ .entity(PolicyControllerConstants.getFactory().getFeatureProviders()).build();
}
/**
@@ -511,8 +561,9 @@ public class RestManager {
public Response controllerFeature(
@ApiParam(value = "Feature Name", required = true) @PathParam("featureName") String featureName) {
try {
- return Response.status(Response.Status.OK).entity(PolicyController.factory.getFeatureProvider(featureName))
- .build();
+ return Response.status(Response.Status.OK)
+ .entity(PolicyControllerConstants.getFactory().getFeatureProvider(featureName))
+ .build();
} catch (final IllegalArgumentException iae) {
logger.debug("{}: cannot feature {} because of {}", this, featureName, iae.getMessage(), iae);
return Response.status(Response.Status.NOT_FOUND).entity(new Error(iae.getMessage())).build();
@@ -537,14 +588,15 @@ public class RestManager {
public Response controller(@ApiParam(value = "Policy Controller Name",
required = true) @PathParam("controller") String controllerName) {
try {
- return Response.status(Response.Status.OK).entity(PolicyController.factory.get(controllerName)).build();
+ return Response.status(Response.Status.OK)
+ .entity(PolicyControllerConstants.getFactory().get(controllerName)).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build();
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -569,23 +621,23 @@ public class RestManager {
PolicyController controller;
try {
- controller = PolicyController.factory.get(controllerName);
+ controller = PolicyControllerConstants.getFactory().get(controllerName);
if (controller == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + " does not exist")).build();
+ .entity(new Error(controllerName + DOES_NOT_EXIST_MSG)).build();
}
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + " not found: " + e.getMessage())).build();
+ .entity(new Error(controllerName + NOT_FOUND + e.getMessage())).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
try {
- PolicyEngine.manager.removePolicyController(controllerName);
+ PolicyEngineConstants.getManager().removePolicyController(controllerName);
} catch (IllegalArgumentException | IllegalStateException e) {
logger.debug("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(),
e);
@@ -611,15 +663,15 @@ public class RestManager {
public Response controllerProperties(@ApiParam(value = "Policy Controller Name",
required = true) @PathParam("controller") String controllerName) {
try {
- final PolicyController controller = PolicyController.factory.get(controllerName);
+ final PolicyController controller = PolicyControllerConstants.getFactory().get(controllerName);
return Response.status(Response.Status.OK).entity(controller.getProperties()).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build();
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -632,7 +684,7 @@ public class RestManager {
@Path("engine/controllers/{controller}/inputs")
@ApiOperation(value = "Policy Controller Input Ports", notes = "List of input ports", responseContainer = "List")
public Response controllerInputs() {
- return Response.status(Response.Status.OK).entity(Arrays.asList(Inputs.values())).build();
+ return Response.status(Response.Status.OK).entity(INPUTS).build();
}
/**
@@ -659,21 +711,21 @@ public class RestManager {
PolicyController controller;
try {
- controller = PolicyEngine.manager.updatePolicyController(controllerConfiguration);
+ controller = PolicyEngineConstants.getManager().updatePolicyController(controllerConfiguration);
if (controller == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + " does not exist")).build();
+ .entity(new Error(controllerName + DOES_NOT_EXIST_MSG)).build();
}
} catch (final IllegalArgumentException e) {
logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(),
e);
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + " not found: " + e.getMessage())).build();
+ .entity(new Error(controllerName + NOT_FOUND + e.getMessage())).build();
} catch (final Exception e) {
logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(),
- e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
return Response.status(Response.Status.OK).entity(controller).build();
@@ -689,7 +741,7 @@ public class RestManager {
@ApiOperation(value = "Policy Controller Switches", notes = "List of the Policy Controller Switches",
responseContainer = "List")
public Response controllerSwitches() {
- return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
+ return Response.status(Response.Status.OK).entity(SWITCHES).build();
}
/**
@@ -705,7 +757,7 @@ public class RestManager {
message = "The system is an administrative state that prevents " + "this request to be fulfilled")})
public Response controllerLock(@ApiParam(value = "Policy Controller Name",
required = true) @PathParam("controller") String controllerName) {
- final PolicyController policyController = PolicyController.factory.get(controllerName);
+ final PolicyController policyController = PolicyControllerConstants.getFactory().get(controllerName);
final boolean success = policyController.lock();
if (success) {
return Response.status(Status.OK).entity(policyController).build();
@@ -728,7 +780,7 @@ public class RestManager {
message = "The system is an administrative state that prevents " + "this request to be fulfilled")})
public Response controllerUnlock(@ApiParam(value = "Policy Controller Name",
required = true) @PathParam("controller") String controllerName) {
- final PolicyController policyController = PolicyController.factory.get(controllerName);
+ final PolicyController policyController = PolicyControllerConstants.getFactory().get(controllerName);
final boolean success = policyController.unlock();
if (success) {
return Response.status(Status.OK).entity(policyController).build();
@@ -757,12 +809,12 @@ public class RestManager {
final DroolsController drools = this.getDroolsController(controllerName);
return Response.status(Response.Status.OK).entity(drools).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build();
+ logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -789,12 +841,12 @@ public class RestManager {
}
return Response.status(Response.Status.OK).entity(sessionCounts).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build();
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -818,12 +870,12 @@ public class RestManager {
final DroolsController drools = this.getDroolsController(controllerName);
return Response.status(Response.Status.OK).entity(drools.factClassNames(sessionName)).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).entity(new Error("entity not found")).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + sessionName + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + sessionName + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -856,13 +908,14 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(facts.size()).build();
}
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")).build();
+ .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_ACCEPTABLE_MSG))
+ .build();
}
}
@@ -899,21 +952,21 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(facts.size()).build();
}
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", this,
+ logger.debug(FETCH_DROOLS_BY_ENTITY_FAILED, this,
controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
.entity(new Error(
- controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found"))
+ controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_FOUND_MSG))
.build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", this,
+ logger.debug(FETCH_DROOLS_BY_ENTITY_FAILED, this,
controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(
- controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable"))
+ controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_ACCEPTABLE_MSG))
.build();
} catch (final Exception e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", this,
+ logger.debug(FETCH_DROOLS_BY_ENTITY_FAILED, this,
controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
}
@@ -954,23 +1007,23 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(facts).build();
} catch (final IllegalArgumentException e) {
logger.debug(
- "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ FETCH_DROOLS_BY_PARAMS_FAILED,
this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
.entity(new Error(
- controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found"))
+ controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_FOUND_MSG))
.build();
} catch (final IllegalStateException e) {
logger.debug(
- "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ FETCH_DROOLS_BY_PARAMS_FAILED,
this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(
- controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable"))
+ controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_ACCEPTABLE_MSG))
.build();
} catch (final Exception e) {
logger.debug(
- "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ FETCH_DROOLS_BY_PARAMS_FAILED,
this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
}
@@ -1002,17 +1055,18 @@ public class RestManager {
final List<Object> facts = drools.facts(sessionName, factType, true);
return Response.status(Response.Status.OK).entity(facts).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this,
+ logger.debug(FETCH_DROOLS_BY_FACTTYPE_FAILED, this,
controllerName, sessionName, factType, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")).build();
+ .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this,
- controllerName, sessionName, factType, e.getMessage(), e);
+ logger.debug(FETCH_DROOLS_BY_FACTTYPE_FAILED, this,
+ controllerName, sessionName, factType, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_ACCEPTABLE_MSG))
+ .build();
} catch (final Exception e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this,
+ logger.debug(FETCH_DROOLS_BY_FACTTYPE_FAILED, this,
controllerName, sessionName, factType, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
}
@@ -1054,23 +1108,23 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(facts).build();
} catch (final IllegalArgumentException e) {
logger.debug(
- "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ FETCH_DROOLS_BY_PARAMS_FAILED,
this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
.entity(new Error(
- controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found"))
+ controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_FOUND_MSG))
.build();
} catch (final IllegalStateException e) {
logger.debug(
- "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ FETCH_DROOLS_BY_PARAMS_FAILED,
this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(
- controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable"))
+ controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_ACCEPTABLE_MSG))
.build();
} catch (final Exception e) {
logger.debug(
- "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ FETCH_DROOLS_BY_PARAMS_FAILED,
this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
}
@@ -1111,17 +1165,17 @@ public class RestManager {
try {
final DroolsController drools = this.getDroolsController(controllerName);
final List<ProtocolCoderToolset> decoders =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId());
+ EventProtocolCoderConstants.getManager().getDecoders(drools.getGroupId(), drools.getArtifactId());
return Response.status(Response.Status.OK).entity(decoders).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName,
+ logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName,
e.getMessage(), e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build();
+ return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName,
- e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName,
+ e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1146,18 +1200,18 @@ public class RestManager {
required = true) @PathParam("controller") String controllerName) {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final List<CoderFilters> filters =
- EventProtocolCoder.manager.getDecoderFilters(drools.getGroupId(), drools.getArtifactId());
+ final List<CoderFilters> filters = EventProtocolCoderConstants.getManager()
+ .getDecoderFilters(drools.getGroupId(), drools.getArtifactId());
return Response.status(Response.Status.OK).entity(filters).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName,
+ logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName,
e.getMessage(), e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build();
+ return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName,
- e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable"))
- .build();
+ logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName,
+ e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1182,19 +1236,19 @@ public class RestManager {
@ApiParam(value = "Networked Topic Name", required = true) @PathParam("topic") String topic) {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final ProtocolCoderToolset decoder =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
+ final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager()
+ .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
return Response.status(Response.Status.OK).entity(decoder).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this,
+ logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this,
controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + " not found")).build();
+ .entity(new Error(controllerName + ":" + topic + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this,
+ logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this,
controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + topic + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + topic + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1220,24 +1274,24 @@ public class RestManager {
@ApiParam(value = "Networked Topic Name", required = true) @PathParam("topic") String topic) {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final ProtocolCoderToolset decoder =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
+ final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager()
+ .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
if (decoder == null) {
- return Response.status(Response.Status.BAD_REQUEST).entity(new Error(topic + " does not exist"))
+ return Response.status(Response.Status.BAD_REQUEST).entity(new Error(topic + DOES_NOT_EXIST_MSG))
.build();
} else {
return Response.status(Response.Status.OK).entity(decoder.getCoders()).build();
}
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this,
+ logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this,
controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + " not found")).build();
+ .entity(new Error(controllerName + ":" + topic + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this,
+ logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this,
controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + topic + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + topic + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1264,25 +1318,25 @@ public class RestManager {
@ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass) {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final ProtocolCoderToolset decoder =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
+ final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager()
+ .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
final CoderFilters filters = decoder.getCoder(factClass);
if (filters == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(topic + ":" + factClass + " does not exist")).build();
+ .entity(new Error(topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build();
} else {
return Response.status(Response.Status.OK).entity(filters).build();
}
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this,
+ logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this,
controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this,
+ logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this,
controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1318,27 +1372,27 @@ public class RestManager {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final ProtocolCoderToolset decoder =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
+ final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager()
+ .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
final CoderFilters filters = decoder.getCoder(factClass);
if (filters == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(topic + ":" + factClass + " does not exist")).build();
+ .entity(new Error(topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build();
}
filters.setFilter(configFilters);
return Response.status(Response.Status.OK).entity(filters).build();
} catch (final IllegalArgumentException e) {
logger.debug(
- "{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}",
+ FETCH_DECODER_BY_FILTER_FAILED,
this, controllerName, topic, factClass, configFilters, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
logger.debug(
- "{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}",
+ FETCH_DECODER_BY_FILTER_FAILED,
this, controllerName, topic, factClass, configFilters, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1363,32 +1417,32 @@ public class RestManager {
@ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass) {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final ProtocolCoderToolset decoder =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
+ final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager()
+ .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
final CoderFilters filters = decoder.getCoder(factClass);
if (filters == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build();
}
final JsonProtocolFilter filter = filters.getFilter();
if (filter == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build();
}
return Response.status(Response.Status.OK).entity(filter.getRule()).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this,
+ logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this,
controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this,
+ logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this,
controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1415,37 +1469,37 @@ public class RestManager {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final ProtocolCoderToolset decoder =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
+ final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager()
+ .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
final CoderFilters filters = decoder.getCoder(factClass);
if (filters == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build();
}
final JsonProtocolFilter filter = filters.getFilter();
if (filter == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build();
}
filter.setRule(null);
return Response.status(Response.Status.OK).entity(filter.getRule()).build();
} catch (final IllegalArgumentException e) {
logger.debug(
- "{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
+ FETCH_DECODER_BY_TYPE_FAILED,
this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found"))
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG))
.build();
} catch (final IllegalStateException e) {
logger.debug(
- "{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
+ FETCH_DECODER_BY_TYPE_FAILED,
this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(
- controllerName + ":" + topic + ":" + factClass + " not acceptable"))
+ controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG))
.build();
}
}
@@ -1473,19 +1527,19 @@ public class RestManager {
try {
final DroolsController drools = this.getDroolsController(controllerName);
- final ProtocolCoderToolset decoder =
- EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
+ final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager()
+ .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic);
final CoderFilters filters = decoder.getCoder(factClass);
if (filters == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build();
}
final JsonProtocolFilter filter = filters.getFilter();
if (filter == null) {
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build();
}
if (rule == null || rule.isEmpty()) {
@@ -1501,14 +1555,14 @@ public class RestManager {
+ "topic {} type {} because of {}",
this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + " not found")).build();
+ .entity(new Error(controllerName + ":" + topic + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
logger.debug(
"{}: cannot access decoder filter rules for policy-controller {} "
+ "topic {} type {} because of {}",
this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build();
}
}
@@ -1532,17 +1586,17 @@ public class RestManager {
PolicyController policyController;
try {
- policyController = PolicyController.factory.get(controllerName);
+ policyController = PolicyControllerConstants.getFactory().get(controllerName);
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this,
+ logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this,
controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + topic + ":" + " not found")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + NOT_FOUND_MSG)).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this,
+ logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this,
controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + topic + ":" + " not acceptable")).build();
+ .entity(new Error(controllerName + ":" + topic + ":" + NOT_ACCEPTABLE_MSG)).build();
}
final CodingResult result = new CodingResult();
@@ -1552,17 +1606,17 @@ public class RestManager {
Object event;
try {
- event = EventProtocolCoder.manager.decode(policyController.getDrools().getGroupId(),
+ event = EventProtocolCoderConstants.getManager().decode(policyController.getDrools().getGroupId(),
policyController.getDrools().getArtifactId(), topic, json);
result.setDecoding(true);
} catch (final Exception e) {
- logger.debug("{}: cannot get policy-controller {} topic {} because of {}", this, controllerName, topic,
+ logger.debug(FETCH_POLICY_BY_TOPIC_FAILED, this, controllerName, topic,
e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST).entity(new Error(e.getMessage())).build();
}
try {
- result.setJsonEncoding(EventProtocolCoder.manager.encode(topic, event));
+ result.setJsonEncoding(EventProtocolCoderConstants.getManager().encode(topic, event));
result.setEncoding(true);
} catch (final Exception e) {
// continue so to propagate decoding results ..
@@ -1589,16 +1643,17 @@ public class RestManager {
required = true) @PathParam("controller") String controllerName) {
List<CoderFilters> encoders;
try {
- final PolicyController controller = PolicyController.factory.get(controllerName);
+ final PolicyController controller = PolicyControllerConstants.getFactory().get(controllerName);
final DroolsController drools = controller.getDrools();
- encoders = EventProtocolCoder.manager.getEncoderFilters(drools.getGroupId(), drools.getArtifactId());
+ encoders = EventProtocolCoderConstants.getManager().getEncoderFilters(drools.getGroupId(),
+ drools.getArtifactId());
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}", this, controllerName,
+ logger.debug(FETCH_ENCODER_BY_FILTER_FAILED, this, controllerName,
e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST)
- .entity(new Error(controllerName + " not found: " + e.getMessage())).build();
+ .entity(new Error(controllerName + NOT_FOUND + e.getMessage())).build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}", this, controllerName,
+ logger.debug(FETCH_ENCODER_BY_FILTER_FAILED, this, controllerName,
e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(controllerName + " is not accepting the request")).build();
@@ -1620,7 +1675,7 @@ public class RestManager {
@ApiOperation(value = "Topics Control Switches", notes = "List of the Topic Control Switches",
responseContainer = "List")
public Response topicSwitches() {
- return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
+ return Response.status(Response.Status.OK).entity(SWITCHES).build();
}
/**
@@ -1639,7 +1694,7 @@ public class RestManager {
if (success) {
return Response.status(Status.OK).entity(TopicEndpointManager.getManager()).build();
} else {
- return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build();
+ return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build();
}
}
@@ -1659,7 +1714,7 @@ public class RestManager {
if (success) {
return Response.status(Status.OK).entity(TopicEndpointManager.getManager()).build();
} else {
- return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build();
+ return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build();
}
}
@@ -1832,7 +1887,7 @@ public class RestManager {
public Response commSourceTopicSwitches(
@ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm
) {
- return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
+ return Response.status(Response.Status.OK).entity(SWITCHES).build();
}
/**
@@ -1845,7 +1900,7 @@ public class RestManager {
public Response commSinkTopicSwitches(
@ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm
) {
- return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
+ return Response.status(Response.Status.OK).entity(SWITCHES).build();
}
/**
@@ -2028,9 +2083,13 @@ public class RestManager {
.build();
}
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot offer to topic {} because of {}", this, topic, e.getMessage(),
+ e);
return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(topic + " not found")).build();
+ .entity(new Error(topic + NOT_FOUND_MSG)).build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot offer to topic {} because of {}", this, topic, e.getMessage(),
+ e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(topic + " not acceptable due to current state"))
.build();
@@ -2144,14 +2203,14 @@ public class RestManager {
* @throws IllegalArgumentException if an invalid controller name has been passed in
*/
protected DroolsController getDroolsController(String controllerName) {
- final PolicyController controller = PolicyController.factory.get(controllerName);
+ final PolicyController controller = PolicyControllerConstants.getFactory().get(controllerName);
if (controller == null) {
- throw new IllegalArgumentException(controllerName + " does not exist");
+ throw new IllegalArgumentException(controllerName + DOES_NOT_EXIST_MSG);
}
final DroolsController drools = controller.getDrools();
if (drools == null) {
- throw new IllegalArgumentException(controllerName + " has no drools configuration");
+ throw new IllegalArgumentException(controllerName + " has no drools configuration");
}
return drools;
@@ -2229,19 +2288,5 @@ public class RestManager {
this.msg = msg;
}
}
-
- /**
- * Feed Ports into Resources.
- */
- public enum Inputs {
- configuration,
- }
-
- /**
- * Resource Toggles.
- */
- public enum Switches {
- activation, lock,
- }
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafBase.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafBase.java
index 955fb242..67725955 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafBase.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafBase.java
@@ -2,7 +2,7 @@
* ============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.
@@ -21,7 +21,7 @@
package org.onap.policy.drools.server.restful.aaf;
import org.onap.policy.common.endpoints.http.server.aaf.AafAuthFilter;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
/**
* AAF Base Class.
@@ -30,6 +30,6 @@ public abstract class AafBase extends AafAuthFilter {
public static final String AAF_NODETYPE = "pdpd";
public static final String AAF_ROOT_PERMISSION_PROPERTY = "aaf.root.permission";
public static final String AAF_ROOT_PERMISSION =
- PolicyEngine.manager.getProperties().getProperty(
+ PolicyEngineConstants.getManager().getProperties().getProperty(
AAF_ROOT_PERMISSION_PROPERTY, DEFAULT_NAMESPACE + "." + AAF_NODETYPE);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java
index 38085101..0d7806c6 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java
@@ -29,6 +29,7 @@ import java.util.Properties;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.features.PolicyControllerFeatureApi;
+import org.onap.policy.drools.features.PolicyControllerFeatureApiConstants;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
import org.onap.policy.drools.system.internal.AggregatedPolicyController;
import org.slf4j.Logger;
@@ -382,6 +383,6 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
protected List<PolicyControllerFeatureApi> getProviders() {
- return PolicyControllerFeatureApi.providers.getList();
+ return PolicyControllerFeatureApiConstants.getProviders().getList();
}
}
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 11ffd689..1ef578c1 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
@@ -22,8 +22,8 @@ package org.onap.policy.drools.system;
import java.util.Properties;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.drools.persistence.SystemPersistence;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.utils.PropertyUtil;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.drools.utils.logging.MdcTransaction;
@@ -51,35 +51,35 @@ public class Main {
/* system properties */
- for (Properties systemProperties : SystemPersistence.manager.getSystemProperties()) {
+ for (Properties systemProperties : SystemPersistenceConstants.getManager().getSystemProperties()) {
PropertyUtil.setSystemProperties(systemProperties);
}
/* 0. boot */
- PolicyEngine.manager.boot(args);
+ PolicyEngineConstants.getManager().boot(args);
/* 1.a. Configure Engine */
Properties engineProperties;
try {
- engineProperties = SystemPersistence.manager.getEngineProperties();
+ engineProperties = SystemPersistenceConstants.getManager().getEngineProperties();
} catch (IllegalArgumentException iae) {
logger.warn("Main: engine properties not found. Using default configuration.", iae);
- engineProperties = PolicyEngine.manager.defaultTelemetryConfig();
+ engineProperties = PolicyEngineConstants.getManager().defaultTelemetryConfig();
}
- PolicyEngine.manager.configure(engineProperties);
+ PolicyEngineConstants.getManager().configure(engineProperties);
/* 1.b. Load Installation Environment(s) */
- for (Properties env : SystemPersistence.manager.getEnvironmentProperties()) {
- PolicyEngine.manager.setEnvironment(env);
+ for (Properties env : SystemPersistenceConstants.getManager().getEnvironmentProperties()) {
+ PolicyEngineConstants.getManager().setEnvironment(env);
}
/* 2. Add topics */
- for (Properties topicProperties : SystemPersistence.manager.getTopicProperties()) {
+ for (Properties topicProperties : SystemPersistenceConstants.getManager().getTopicProperties()) {
TopicEndpointManager.getManager().addTopics(topicProperties);
}
@@ -91,13 +91,13 @@ public class Main {
.setTargetEntity("engine")
.setTargetServiceName("start");
try {
- final boolean success = PolicyEngine.manager.start();
+ final boolean success = PolicyEngineConstants.getManager().start();
if (!success) {
trans.setStatusCode(false).setResponseDescription("partial start").flush();
logger.warn(
LoggerUtil.TRANSACTION_LOG_MARKER,
"Main: {} has been partially started",
- PolicyEngine.manager);
+ PolicyEngineConstants.getManager());
} else {
trans.setStatusCode(true).transaction();
}
@@ -110,7 +110,7 @@ public class Main {
logger.warn(
LoggerUtil.TRANSACTION_LOG_MARKER,
"Main: cannot start {} (bad state) because of {}",
- PolicyEngine.manager,
+ PolicyEngineConstants.getManager(),
e.getMessage(),
e);
} catch (final Exception e) {
@@ -122,7 +122,7 @@ public class Main {
logger.warn(
LoggerUtil.TRANSACTION_LOG_MARKER,
"Main: cannot start {} because of {}",
- PolicyEngine.manager,
+ PolicyEngineConstants.getManager(),
e.getMessage(),
e);
System.exit(1);
@@ -131,9 +131,9 @@ public class Main {
/* 4. Create and start the controllers */
for (final Properties controllerProperties :
- SystemPersistence.manager.getControllerProperties()) {
+ SystemPersistenceConstants.getManager().getControllerProperties()) {
final String controllerName =
- controllerProperties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
+ controllerProperties.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME);
try {
trans =
MdcTransaction.newTransaction(null, null)
@@ -142,7 +142,7 @@ public class Main {
.setTargetServiceName("start");
final PolicyController controller =
- PolicyEngine.manager.createPolicyController(controllerName, controllerProperties);
+ PolicyEngineConstants.getManager().createPolicyController(controllerName, controllerProperties);
controller.start();
trans
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 9bc75b39..17247f41 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
@@ -7,9 +7,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.
@@ -41,11 +41,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi
public interface PolicyController extends Startable, Lockable {
/**
- * Factory that tracks and manages Policy Controllers.
- */
- static PolicyControllerFactory factory = new IndexedPolicyControllerFactory();
-
- /**
* name of this Policy Controller.
*/
String getName();
@@ -72,7 +67,7 @@ public interface PolicyController extends Startable, Lockable {
/**
* Update maven configuration.
- *
+ *
* @param newDroolsConfiguration new drools configuration
* @return true if the update was successful, false otherwise
*/
@@ -90,11 +85,11 @@ public interface PolicyController extends Startable, Lockable {
/**
* Attempts delivering of an String over communication infrastructure "busType".
- *
+ *
* @param busType bus type
* @param topic topic
* @param event Communication infrastructure identifier
- *
+ *
* @return true if successful, false if a failure has occurred.
* @throws IllegalArgumentException when invalid or insufficient properties are provided
* @throws IllegalStateException when the engine is in a state where this operation is not
@@ -106,7 +101,7 @@ public interface PolicyController extends Startable, Lockable {
/**
* halts and permanently releases all resources.
- *
+ *
* @throws IllegalStateException throws illegal state exception
*/
void halt();
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerConstants.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerConstants.java
new file mode 100644
index 00000000..78d24129
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerConstants.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.system;
+
+import lombok.Getter;
+
+public class PolicyControllerConstants {
+
+ /**
+ * Factory that tracks and manages Policy Controllers.
+ */
+ @Getter
+ private static final PolicyControllerFactory factory = new IndexedPolicyControllerFactory();
+
+ private PolicyControllerConstants() {
+ // do nothing
+ }
+}
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 eb2ed3df..506474cb 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
@@ -46,25 +46,6 @@ import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
* RestTopicWriter <br> PolicyEngine 1 --- 1 ManagementServer
*/
public interface PolicyEngine extends Startable, Lockable, TopicListener {
- /**
- * Policy Engine Manager.
- */
- PolicyEngine manager = new PolicyEngineManager();
-
- /**
- * Default Telemetry Server Port.
- */
- int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
-
- /**
- * Default Telemetry Server Hostname.
- */
- String TELEMETRY_SERVER_DEFAULT_HOST = "localhost";
-
- /**
- * Default Telemetry Server Name.
- */
- String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
/**
* Boot the engine.
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java
new file mode 100644
index 00000000..4d18d6b8
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-management
+ * ================================================================================
+ * 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.system;
+
+import lombok.Getter;
+
+public class PolicyEngineConstants {
+
+ /**
+ * Default Telemetry Server Port.
+ */
+ public static final int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
+
+ /**
+ * Default Telemetry Server Hostname.
+ */
+ public static final String TELEMETRY_SERVER_DEFAULT_HOST = "localhost";
+
+ /**
+ * Default Telemetry Server Name.
+ */
+ public static final String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
+
+ /**
+ * Policy Engine Manager.
+ */
+ @Getter
+ private static final PolicyEngine manager = new PolicyEngineManager();
+
+ private PolicyEngineConstants() {
+ // do nothing
+ }
+}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
index 1c02d705..36d8ca59 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
@@ -20,6 +20,10 @@
package org.onap.policy.drools.system;
+import static org.onap.policy.drools.system.PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_HOST;
+import static org.onap.policy.drools.system.PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_NAME;
+import static org.onap.policy.drools.system.PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_PORT;
+
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.Gson;
@@ -40,13 +44,18 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.core.PolicyContainer;
import org.onap.policy.drools.core.jmx.PdpJmxListener;
import org.onap.policy.drools.features.PolicyControllerFeatureApi;
+import org.onap.policy.drools.features.PolicyControllerFeatureApiConstants;
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
+import org.onap.policy.drools.features.PolicyEngineFeatureApiConstants;
import org.onap.policy.drools.persistence.SystemPersistence;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
import org.onap.policy.drools.server.restful.RestManager;
@@ -279,16 +288,17 @@ class PolicyEngineManager implements PolicyEngine {
.setTargetEntity(config.getEntity());
}
- switch (entity) {
- case PdpdConfiguration.CONFIG_ENTITY_CONTROLLER:
- boolean success = controllerConfig(config);
- mdcTrans.resetSubTransaction().setStatusCode(success).transaction();
- return success;
- default:
- final String msg = "Configuration Entity is not supported: " + entity;
- mdcTrans.resetSubTransaction().setStatusCode(false).setResponseDescription(msg).flush();
- logger.warn(LoggerUtil.TRANSACTION_LOG_MARKER_NAME, msg);
- throw new IllegalArgumentException(msg);
+
+ if (PdpdConfiguration.CONFIG_ENTITY_CONTROLLER.equals(entity)) {
+ boolean success = controllerConfig(config);
+ mdcTrans.resetSubTransaction().setStatusCode(success).transaction();
+ return success;
+
+ } else {
+ final String msg = "Configuration Entity is not supported: " + entity;
+ mdcTrans.resetSubTransaction().setStatusCode(false).setResponseDescription(msg).flush();
+ logger.warn(LoggerUtil.TRANSACTION_LOG_MARKER_NAME, msg);
+ throw new IllegalArgumentException(msg);
}
}
@@ -299,7 +309,7 @@ class PolicyEngineManager implements PolicyEngine {
// check if a PROPERTY_CONTROLLER_NAME property is present
// if so, override the given name
- final String propertyControllerName = properties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
+ final String propertyControllerName = properties.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME);
if (propertyControllerName != null && !propertyControllerName.isEmpty()) {
if (!propertyControllerName.equals(tempName)) {
throw new IllegalStateException("Proposed name (" + tempName + ") and properties name ("
@@ -425,12 +435,15 @@ class PolicyEngineManager implements PolicyEngine {
controllerName);
/*
- * try to bring up bad controller in brainless mode, after having it working, apply
- * the new create/update operation.
+ * try to bring up bad controller in brainless mode, after having it
+ * working, apply the new create/update operation.
*/
- controllerProperties.setProperty(DroolsProperties.RULES_GROUPID, DroolsController.NO_GROUP_ID);
- controllerProperties.setProperty(DroolsProperties.RULES_ARTIFACTID, DroolsController.NO_ARTIFACT_ID);
- controllerProperties.setProperty(DroolsProperties.RULES_VERSION, DroolsController.NO_VERSION);
+ controllerProperties.setProperty(DroolsPropertyConstants.RULES_GROUPID,
+ DroolsControllerConstants.NO_GROUP_ID);
+ controllerProperties.setProperty(DroolsPropertyConstants.RULES_ARTIFACTID,
+ DroolsControllerConstants.NO_ARTIFACT_ID);
+ controllerProperties.setProperty(DroolsPropertyConstants.RULES_VERSION,
+ DroolsControllerConstants.NO_VERSION);
policyController = getPolicyEngine().createPolicyController(controllerName, controllerProperties);
@@ -1272,11 +1285,11 @@ class PolicyEngineManager implements PolicyEngine {
// these methods may be overridden by junit tests
protected List<PolicyEngineFeatureApi> getEngineProviders() {
- return PolicyEngineFeatureApi.providers.getList();
+ return PolicyEngineFeatureApiConstants.getProviders().getList();
}
protected List<PolicyControllerFeatureApi> getControllerProviders() {
- return PolicyControllerFeatureApi.providers.getList();
+ return PolicyControllerFeatureApiConstants.getProviders().getList();
}
protected void globalInitContainer(String[] cliArgs) {
@@ -1292,7 +1305,7 @@ class PolicyEngineManager implements PolicyEngine {
}
protected PolicyControllerFactory getControllerFactory() {
- return PolicyController.factory;
+ return PolicyControllerConstants.getFactory();
}
protected void startPdpJmxListener() {
@@ -1308,14 +1321,14 @@ class PolicyEngineManager implements PolicyEngine {
}
protected EventProtocolCoder getProtocolCoder() {
- return EventProtocolCoder.manager;
+ return EventProtocolCoderConstants.getManager();
}
protected SystemPersistence getPersistenceManager() {
- return SystemPersistence.manager;
+ return SystemPersistenceConstants.getManager();
}
protected PolicyEngine getPolicyEngine() {
- return PolicyEngine.manager;
+ return PolicyEngineConstants.getManager();
}
}
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 51280eb3..5d915104 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
@@ -35,10 +35,13 @@ import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.controller.DroolsControllerFactory;
import org.onap.policy.drools.features.PolicyControllerFeatureApi;
+import org.onap.policy.drools.features.PolicyControllerFeatureApiConstants;
import org.onap.policy.drools.persistence.SystemPersistence;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
@@ -148,14 +151,15 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
return droolsController
.getBaseDomainNames()
.stream()
- .map(d -> new ToscaPolicyTypeIdentifier(d, DroolsProperties.DEFAULT_CONTROLLER_POLICY_TYPE_VERSION))
+ .map(d -> new ToscaPolicyTypeIdentifier(d,
+ DroolsPropertyConstants.DEFAULT_CONTROLLER_POLICY_TYPE_VERSION))
.collect(Collectors.toList());
}
protected List<ToscaPolicyTypeIdentifier> getPolicyTypesFromProperties() {
List<ToscaPolicyTypeIdentifier> policyTypeIds = new ArrayList<>();
- String ptiPropValue = properties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_POLICY_TYPES);
+ String ptiPropValue = properties.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_POLICY_TYPES);
if (ptiPropValue == null) {
return policyTypeIds;
}
@@ -165,7 +169,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
String[] ptv = pti.split(":");
if (ptv.length == 1) {
policyTypeIds.add(new ToscaPolicyTypeIdentifier(ptv[0],
- DroolsProperties.DEFAULT_CONTROLLER_POLICY_TYPE_VERSION));
+ DroolsPropertyConstants.DEFAULT_CONTROLLER_POLICY_TYPE_VERSION));
} else if (ptv.length == 2) {
policyTypeIds.add(new ToscaPolicyTypeIdentifier(ptv[0], ptv[1]));
}
@@ -221,9 +225,10 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
try {
/* Drools Controller created, update initialization properties for restarts */
- this.properties.setProperty(DroolsProperties.RULES_GROUPID, newDroolsConfiguration.getGroupId());
- this.properties.setProperty(DroolsProperties.RULES_ARTIFACTID, newDroolsConfiguration.getArtifactId());
- this.properties.setProperty(DroolsProperties.RULES_VERSION, newDroolsConfiguration.getVersion());
+ this.properties.setProperty(DroolsPropertyConstants.RULES_GROUPID, newDroolsConfiguration.getGroupId());
+ this.properties.setProperty(DroolsPropertyConstants.RULES_ARTIFACTID,
+ newDroolsConfiguration.getArtifactId());
+ this.properties.setProperty(DroolsPropertyConstants.RULES_VERSION, newDroolsConfiguration.getVersion());
getPersistenceManager().storeController(name, this.properties);
@@ -719,7 +724,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
// the following methods may be overridden by junit tests
protected SystemPersistence getPersistenceManager() {
- return SystemPersistence.manager;
+ return SystemPersistenceConstants.getManager();
}
protected TopicEndpoint getEndpointManager() {
@@ -727,11 +732,11 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
protected DroolsControllerFactory getDroolsFactory() {
- return DroolsController.factory;
+ return DroolsControllerConstants.getFactory();
}
protected List<PolicyControllerFeatureApi> getProviders() {
- return PolicyControllerFeatureApi.providers.getList();
+ return PolicyControllerFeatureApiConstants.getProviders().getList();
}
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java b/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java
index 47baa07e..67026c0a 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/controller/DroolsControllerFactoryTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * 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.
@@ -34,7 +34,7 @@ public class DroolsControllerFactoryTest {
@Test
public void buildNullController() {
Properties droolsProps = new Properties();
- DroolsController droolsController = DroolsController.factory.build(droolsProps, null, null);
+ DroolsController droolsController = DroolsControllerConstants.getFactory().build(droolsProps, null, null);
if (!isNullController(droolsController)) {
fail("drools controller is not a null controller");
@@ -44,20 +44,20 @@ public class DroolsControllerFactoryTest {
@Test
public void getNullController() {
DroolsController controller =
- DroolsController.factory.get(DroolsController.NO_GROUP_ID,
- DroolsController.NO_ARTIFACT_ID, DroolsController.NO_VERSION);
+ DroolsControllerConstants.getFactory().get(DroolsControllerConstants.NO_GROUP_ID,
+ DroolsControllerConstants.NO_ARTIFACT_ID, DroolsControllerConstants.NO_VERSION);
assertNotNull(controller);
- assertEquals(DroolsController.NO_GROUP_ID, controller.getGroupId());
- assertEquals(DroolsController.NO_ARTIFACT_ID, controller.getArtifactId());
- assertEquals(DroolsController.NO_VERSION, controller.getVersion());
+ assertEquals(DroolsControllerConstants.NO_GROUP_ID, controller.getGroupId());
+ assertEquals(DroolsControllerConstants.NO_ARTIFACT_ID, controller.getArtifactId());
+ assertEquals(DroolsControllerConstants.NO_VERSION, controller.getVersion());
}
@Test
public void inventory() {
- List<DroolsController> controllers = DroolsController.factory.inventory();
+ List<DroolsController> controllers = DroolsControllerConstants.getFactory().inventory();
assertNotNull(controllers);
-
+
for (int i = 0; i < controllers.size(); i++) {
if (!isNullController(controllers.get(i)) && !isActualController(controllers.get(i))) {
fail("drools controller is not a null controller");
@@ -83,31 +83,31 @@ public class DroolsControllerFactoryTest {
if (droolsController == null) {
return false;
}
-
- if (!DroolsController.NO_GROUP_ID.equals(droolsController.getGroupId())) {
+
+ if (!DroolsControllerConstants.NO_GROUP_ID.equals(droolsController.getGroupId())) {
return false;
}
-
- if (!DroolsController.NO_ARTIFACT_ID.equals(droolsController.getArtifactId())) {
+
+ if (!DroolsControllerConstants.NO_ARTIFACT_ID.equals(droolsController.getArtifactId())) {
return false;
}
- return DroolsController.NO_VERSION.equals(droolsController.getVersion());
+ return DroolsControllerConstants.NO_VERSION.equals(droolsController.getVersion());
}
private boolean isActualController(DroolsController droolsController) {
if (droolsController == null) {
return false;
}
-
+
if (!"org.onap.policy.drools.test".equals(droolsController.getGroupId())) {
return false;
}
-
+
if (!"protocolcoder".equals(droolsController.getArtifactId())) {
return false;
}
-
+
return droolsController.getVersion() != null && droolsController.getVersion().substring(0, 1).matches("[0-9]");
}
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java
index 20b79bde..7187ad1b 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java
@@ -58,7 +58,9 @@ import org.onap.policy.common.utils.services.OrderedServiceImpl;
import org.onap.policy.drools.core.PolicyContainer;
import org.onap.policy.drools.core.PolicySession;
import org.onap.policy.drools.features.DroolsControllerFeatureApi;
+import org.onap.policy.drools.features.DroolsControllerFeatureApiConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolParams;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
@@ -887,8 +889,8 @@ public class MavenDroolsController2Test {
}
};
- assertSame(EventProtocolCoder.manager, drools.getCoderManager());
- assertSame(DroolsControllerFeatureApi.providers, drools.getDroolsProviders());
+ assertSame(EventProtocolCoderConstants.getManager(), drools.getCoderManager());
+ assertSame(DroolsControllerFeatureApiConstants.getProviders(), drools.getDroolsProviders());
}
@Test
diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java
index 4b0c438f..8515582d 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java
@@ -24,6 +24,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
public class NullDroolsControllerTest {
@@ -56,17 +57,17 @@ public class NullDroolsControllerTest {
@Test
public void getGroupId() {
- Assert.assertEquals(new NullDroolsController().getGroupId(), DroolsController.NO_GROUP_ID);
+ Assert.assertEquals(new NullDroolsController().getGroupId(), DroolsControllerConstants.NO_GROUP_ID);
}
@Test
public void getArtifactId() {
- Assert.assertEquals(new NullDroolsController().getArtifactId(), DroolsController.NO_ARTIFACT_ID);
+ Assert.assertEquals(new NullDroolsController().getArtifactId(), DroolsControllerConstants.NO_ARTIFACT_ID);
}
@Test
public void getVersion() {
- Assert.assertEquals(new NullDroolsController().getVersion(), DroolsController.NO_VERSION);
+ Assert.assertEquals(new NullDroolsController().getVersion(), DroolsControllerConstants.NO_VERSION);
}
@Test
diff --git a/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
index b2771944..8cd4ee6e 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
@@ -37,7 +37,7 @@ import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
/**
* (File) System Persistence Tests.
@@ -103,24 +103,24 @@ public class SystemPersistenceTest {
@Test
public void test1NonDefaultConfigDir() {
- SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
- assertEquals(OTHER_CONFIG_DIR, SystemPersistence.manager.getConfigurationPath().toString());
+ SystemPersistenceConstants.getManager().setConfigurationDir(OTHER_CONFIG_DIR);
+ assertEquals(OTHER_CONFIG_DIR, SystemPersistenceConstants.getManager().getConfigurationPath().toString());
- SystemPersistence.manager.setConfigurationDir(null);
- assertEquals(SystemPersistence.DEFAULT_CONFIGURATION_DIR,
- SystemPersistence.manager.getConfigurationPath().toString());
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+ assertEquals(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR,
+ SystemPersistenceConstants.getManager().getConfigurationPath().toString());
- SystemPersistence.manager.setConfigurationDir();
- assertEquals(SystemPersistence.DEFAULT_CONFIGURATION_DIR,
- SystemPersistence.manager.getConfigurationPath().toString());
+ SystemPersistenceConstants.getManager().setConfigurationDir();
+ assertEquals(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR,
+ SystemPersistenceConstants.getManager().getConfigurationPath().toString());
}
@Test
public void test2Engine_Environment_System() throws IOException {
- SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
+ SystemPersistenceConstants.getManager().setConfigurationDir(OTHER_CONFIG_DIR);
final Path policyEnginePropsPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(),
+ Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
FileSystemPersistence.PROPERTIES_FILE_ENGINE);
final Properties engineProps = new Properties();
@@ -132,113 +132,114 @@ public class SystemPersistenceTest {
}
}
- assertEquals(engineProps, SystemPersistence.manager.getEngineProperties());
+ assertEquals(engineProps, SystemPersistenceConstants.getManager().getEngineProperties());
final Path environmentPropertiesPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), ENV_PROPS_FILE);
+ Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), ENV_PROPS_FILE);
if (Files.notExists(environmentPropertiesPath)) {
Files.createFile(environmentPropertiesPath);
}
- assertNotNull(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS));
- assertTrue(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS).isEmpty());
- assertEquals(1, SystemPersistence.manager.getEnvironmentProperties().size());
- assertEquals(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS),
- SystemPersistence.manager.getEnvironmentProperties().get(0));
+ assertNotNull(SystemPersistenceConstants.getManager().getEnvironmentProperties(ENV_PROPS));
+ assertTrue(SystemPersistenceConstants.getManager().getEnvironmentProperties(ENV_PROPS).isEmpty());
+ assertEquals(1, SystemPersistenceConstants.getManager().getEnvironmentProperties().size());
+ assertEquals(SystemPersistenceConstants.getManager().getEnvironmentProperties(ENV_PROPS),
+ SystemPersistenceConstants.getManager().getEnvironmentProperties().get(0));
Path systemPropertiesPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), SYSTEM_PROPS_FILE);
+ Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), SYSTEM_PROPS_FILE);
if (Files.notExists(systemPropertiesPath)) {
Files.createFile(systemPropertiesPath);
}
- assertNotNull(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS));
- assertTrue(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS).isEmpty());
- assertEquals(1, SystemPersistence.manager.getSystemProperties().size());
- assertEquals(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS),
- SystemPersistence.manager.getSystemProperties().get(0));
+ assertNotNull(SystemPersistenceConstants.getManager().getSystemProperties(SYSTEM_PROPS));
+ assertTrue(SystemPersistenceConstants.getManager().getSystemProperties(SYSTEM_PROPS).isEmpty());
+ assertEquals(1, SystemPersistenceConstants.getManager().getSystemProperties().size());
+ assertEquals(SystemPersistenceConstants.getManager().getSystemProperties(SYSTEM_PROPS),
+ SystemPersistenceConstants.getManager().getSystemProperties().get(0));
}
@Test
public void test3Topic() {
- SystemPersistence.manager.setConfigurationDir(null);
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
Path topicPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_TOPIC_FILE);
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_TOPIC_FILE);
Path topicBakPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_TOPIC_FILE_BAK);
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_TOPIC_FILE_BAK);
assertTrue(Files.notExists(topicPath));
assertTrue(Files.notExists(topicBakPath));
- SystemPersistence.manager.storeTopic(TEST_TOPIC_NAME, new Properties());
+ SystemPersistenceConstants.getManager().storeTopic(TEST_TOPIC_NAME, new Properties());
assertTrue(Files.exists(topicPath));
- Properties properties = SystemPersistence.manager.getTopicProperties(TEST_TOPIC_NAME);
+ Properties properties = SystemPersistenceConstants.getManager().getTopicProperties(TEST_TOPIC_NAME);
assertNotNull(properties);
- List<Properties> topicPropsList = SystemPersistence.manager.getTopicProperties();
+ List<Properties> topicPropsList = SystemPersistenceConstants.getManager().getTopicProperties();
assertEquals(1, topicPropsList.size());
- SystemPersistence.manager.backupTopic(TEST_TOPIC_NAME);
+ SystemPersistenceConstants.getManager().backupTopic(TEST_TOPIC_NAME);
assertTrue(Files.exists(topicBakPath));
- SystemPersistence.manager.deleteTopic(TEST_TOPIC_NAME);
+ SystemPersistenceConstants.getManager().deleteTopic(TEST_TOPIC_NAME);
assertTrue(Files.notExists(topicPath));
}
@Test
public void test4Controller() {
- SystemPersistence.manager.setConfigurationDir(null);
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
Path controllerPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
- Path controllerBakPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
+ Path controllerBakPath = Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
+ TEST_CONTROLLER_FILE_BAK);
assertTrue(Files.notExists(controllerPath));
assertTrue(Files.notExists(controllerBakPath));
- SystemPersistence.manager.storeController(TEST_CONTROLLER_NAME, new Properties());
+ SystemPersistenceConstants.getManager().storeController(TEST_CONTROLLER_NAME, new Properties());
assertTrue(Files.exists(controllerPath));
- Properties properties = SystemPersistence.manager.getControllerProperties(TEST_CONTROLLER_NAME);
+ Properties properties = SystemPersistenceConstants.getManager().getControllerProperties(TEST_CONTROLLER_NAME);
assertNotNull(properties);
- List<Properties> controllerPropsList = SystemPersistence.manager.getControllerProperties();
+ List<Properties> controllerPropsList = SystemPersistenceConstants.getManager().getControllerProperties();
assertEquals(1, controllerPropsList.size());
assertEquals(TEST_CONTROLLER_NAME, controllerPropsList
- .get(0).getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME));
+ .get(0).getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME));
- SystemPersistence.manager.backupController(TEST_CONTROLLER_NAME);
+ SystemPersistenceConstants.getManager().backupController(TEST_CONTROLLER_NAME);
assertTrue(Files.exists(controllerBakPath));
- SystemPersistence.manager.deleteController(TEST_CONTROLLER_NAME);
+ SystemPersistenceConstants.getManager().deleteController(TEST_CONTROLLER_NAME);
assertTrue(Files.notExists(controllerPath));
}
/**
* Clean up the working directories.
- *
+ *
* @throws IOException throws IO exception
*/
private static void cleanUpWorkingDirs() throws IOException {
- SystemPersistence.manager.setConfigurationDir(null);
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
- for (Properties properties : SystemPersistence.manager.getControllerProperties()) {
- SystemPersistence.manager.deleteController(properties
- .getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME));
+ for (Properties properties : SystemPersistenceConstants.getManager().getControllerProperties()) {
+ SystemPersistenceConstants.getManager().deleteController(properties
+ .getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME));
}
- SystemPersistence.manager.deleteTopic(TEST_TOPIC_NAME);
+ SystemPersistenceConstants.getManager().deleteTopic(TEST_TOPIC_NAME);
- final Path testControllerBakPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
+ final Path testControllerBakPath =
+ Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
+ TEST_CONTROLLER_FILE_BAK);
final Path testTopicBakPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_TOPIC_FILE_BAK);
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_TOPIC_FILE_BAK);
final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, FileSystemPersistence.PROPERTIES_FILE_ENGINE);
final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE);
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
index db90bea7..6f34c2c1 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
@@ -83,18 +83,18 @@ public class EventProtocolCoderTest {
TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties);
- EventProtocolCoder.manager.addEncoder(
+ EventProtocolCoderConstants.getManager().addEncoder(
EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
.topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getName())
.protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
.modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
- final String json = EventProtocolCoder.manager.encode(NOOP_TOPIC,
+ final String json = EventProtocolCoderConstants.getManager().encode(NOOP_TOPIC,
new DroolsConfiguration(ENCODER_GROUP, ENCODER_ARTIFACT, ENCODER_VERSION));
assertTrue(json.contains(ENCODER_GROUP));
assertTrue(json.contains(ENCODER_ARTIFACT));
- EventProtocolCoder.manager.removeEncoders(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC);
+ EventProtocolCoderConstants.getManager().removeEncoders(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC);
}
}
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 64661845..bd595725 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
@@ -34,9 +34,9 @@ import org.kie.api.builder.ReleaseId;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.controller.internal.MavenDroolsControllerTest;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
import org.onap.policy.drools.util.KieUtils;
@@ -234,13 +234,13 @@ public class ProtocolCoderToolsetTest {
final List<? extends TopicSink> noopTopics = TopicEndpointManager.getManager().addTopicSinks(sinkConfig);
Properties droolsControllerConfig = new Properties();
- droolsControllerConfig.put(DroolsProperties.RULES_GROUPID, releaseId.getGroupId());
- droolsControllerConfig.put(DroolsProperties.RULES_ARTIFACTID, releaseId.getArtifactId());
- droolsControllerConfig.put(DroolsProperties.RULES_VERSION, releaseId.getVersion());
+ droolsControllerConfig.put(DroolsPropertyConstants.RULES_GROUPID, releaseId.getGroupId());
+ droolsControllerConfig.put(DroolsPropertyConstants.RULES_ARTIFACTID, releaseId.getArtifactId());
+ droolsControllerConfig.put(DroolsPropertyConstants.RULES_VERSION, releaseId.getVersion());
droolsControllerConfig.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS + "." + JUNIT_PROTOCOL_CODER_TOPIC
+ PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX, Triple.class.getName());
- DroolsController.factory.build(droolsControllerConfig, null, noopTopics);
+ DroolsControllerConstants.getFactory().build(droolsControllerConfig, null, noopTopics);
}
private JsonProtocolFilter createFilterSet() {
diff --git a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
index 88712a3b..173c1738 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
@@ -48,9 +48,9 @@ import org.junit.runners.MethodSorters;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.network.NetworkUtil;
-import org.onap.policy.drools.persistence.SystemPersistence;
-import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -107,23 +107,23 @@ public class RestManagerTest {
public static void setUp() throws IOException, InterruptedException {
cleanUpWorkingDirs();
- SystemPersistence.manager.setConfigurationDir(null);
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
/* override default port */
- final Properties engineProps = PolicyEngine.manager.defaultTelemetryConfig();
+ final Properties engineProps = PolicyEngineConstants.getManager().defaultTelemetryConfig();
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
- "" + DEFAULT_TELEMETRY_PORT);
+ + PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "" + DEFAULT_TELEMETRY_PORT);
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_NAME
+ PolicyEndPointProperties.PROPERTY_HTTP_FILTER_CLASSES_SUFFIX,
TestAafTelemetryAuthFilter.class.getName());
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_NAME
+ PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX,
TELEMETRY_USER);
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_NAME
+ PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX,
TELEMETRY_PASSWORD);
@@ -141,11 +141,11 @@ public class RestManagerTest {
engineProps.put(DMAAP_SINK_MECHID_KEY, DMAAP_MECHID);
engineProps.put(DMAAP_SINK_PASSWD_KEY, DMAAP_PASSWD);
- PolicyEngine.manager.configure(engineProps);
- PolicyEngine.manager.start();
+ PolicyEngineConstants.getManager().configure(engineProps);
+ PolicyEngineConstants.getManager().start();
Properties controllerProps = new Properties();
- PolicyEngine.manager.createPolicyController(FOO_CONTROLLER, controllerProps);
+ PolicyEngineConstants.getManager().createPolicyController(FOO_CONTROLLER, controllerProps);
// client = HttpClients.createDefault();
CredentialsProvider provider = new BasicCredentialsProvider();
@@ -173,9 +173,9 @@ public class RestManagerTest {
@AfterClass
public static void tearDown() throws IOException, InterruptedException {
/* Shutdown managed resources */
- PolicyController.factory.shutdown();
+ PolicyControllerConstants.getFactory().shutdown();
TopicEndpointManager.getManager().shutdown();
- PolicyEngine.manager.stop();
+ PolicyEngineConstants.getManager().stop();
Thread.sleep(10000L);
client.close();
cleanUpWorkingDirs();
@@ -441,7 +441,7 @@ public class RestManagerTest {
assertEquals(200, response.getStatusLine().getStatusCode());
httpGet.releaseConnection();
- PolicyEngine.manager.setEnvironmentProperty("foo", "bar");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("foo", "bar");
httpGet = new HttpGet(HOST_URL + "/engine/environment/foo");
response = client.execute(httpGet);
String responseBody = this.getResponseBody(response);
@@ -962,10 +962,11 @@ public class RestManagerTest {
}
private static void cleanUpWorkingDirs() throws IOException {
- final Path testControllerPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), FOO_CONTROLLER_FILE);
+ final Path testControllerPath = Paths.get(
+ SystemPersistenceConstants.getManager().getConfigurationPath().toString(), FOO_CONTROLLER_FILE);
final Path testControllerBakPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), FOO_CONTROLLER_FILE_BAK);
+ Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
+ FOO_CONTROLLER_FILE_BAK);
Files.deleteIfExists(testControllerPath);
Files.deleteIfExists(testControllerBakPath);
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index c5fa3980..e9f0b48a 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -56,7 +56,7 @@ import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.features.PolicyControllerFeatureApi;
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
import org.onap.policy.drools.persistence.SystemPersistence;
-import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
@@ -492,19 +492,19 @@ public class PolicyEngineManagerTest {
// empty name in properties - same result
setUp();
- properties.setProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME, "");
+ properties.setProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, "");
assertEquals(controller, mgr.createPolicyController(MY_NAME, properties));
verify(contProv1).beforeCreate(MY_NAME, properties);
// matching name in properties - same result
setUp();
- properties.setProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME, MY_NAME);
+ properties.setProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, MY_NAME);
assertEquals(controller, mgr.createPolicyController(MY_NAME, properties));
verify(contProv1).beforeCreate(MY_NAME, properties);
// mismatching name in properties - nothing should happen besides exception
setUp();
- properties.setProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME, "mistmatched-name");
+ properties.setProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, "mistmatched-name");
assertThatIllegalStateException().isThrownBy(() -> mgr.createPolicyController(MY_NAME, properties));
verify(contProv1, never()).beforeCreate(MY_NAME, properties);
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
index d47c2183..df1f6cca 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
@@ -39,9 +39,9 @@ import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.gson.GsonTestUtils;
-import org.onap.policy.drools.persistence.SystemPersistence;
-import org.onap.policy.drools.properties.DroolsProperties;
-import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolParams;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
@@ -106,7 +106,8 @@ public class PolicyEngineTest {
*/
protected static void cleanUpWorkingDir() {
final Path testControllerPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
+ Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
+ TEST_CONTROLLER_FILE);
try {
Files.deleteIfExists(testControllerPath);
} catch (final Exception e) {
@@ -114,7 +115,8 @@ public class PolicyEngineTest {
}
final Path testControllerBakPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
+ Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
+ TEST_CONTROLLER_FILE_BAK);
try {
Files.deleteIfExists(testControllerBakPath);
} catch (final Exception e) {
@@ -136,7 +138,7 @@ public class PolicyEngineTest {
cleanUpWorkingDir();
/* ensure presence of config directory */
- final Path configDir = Paths.get(SystemPersistence.DEFAULT_CONFIGURATION_DIR);
+ final Path configDir = Paths.get(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR);
if (Files.notExists(configDir)) {
Files.createDirectories(configDir);
}
@@ -152,56 +154,57 @@ public class PolicyEngineTest {
public void test100Configure() {
logger.info("enter");
- final Properties engineProps = PolicyEngine.manager.defaultTelemetryConfig();
+ final Properties engineProps = PolicyEngineConstants.getManager().defaultTelemetryConfig();
/* override default port */
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_NAME
+ PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "" + DEFAULT_TELEMETRY_PORT);
- assertFalse(PolicyEngine.manager.isAlive());
- PolicyEngine.manager.configure(engineProps);
- assertFalse(PolicyEngine.manager.isAlive());
+ assertFalse(PolicyEngineConstants.getManager().isAlive());
+ PolicyEngineConstants.getManager().configure(engineProps);
+ assertFalse(PolicyEngineConstants.getManager().isAlive());
- logger.info("engine {} has configuration {}", PolicyEngine.manager, engineProps);
+ logger.info("engine {} has configuration {}", PolicyEngineConstants.getManager(), engineProps);
- gson.compareGson(PolicyEngine.manager, new File(PolicyEngineTest.class.getSimpleName() + "Config.json"));
+ gson.compareGson(PolicyEngineConstants.getManager(),
+ new File(PolicyEngineTest.class.getSimpleName() + "Config.json"));
}
@Test
public void test200Start() {
logger.info("enter");
- PolicyEngine.manager.start();
+ PolicyEngineConstants.getManager().start();
- assertTrue(PolicyEngine.manager.isAlive());
- assertFalse(PolicyEngine.manager.isLocked());
- assertFalse(PolicyEngine.manager.getHttpServers().isEmpty());
- assertTrue(PolicyEngine.manager.getHttpServers().get(0).isAlive());
+ assertTrue(PolicyEngineConstants.getManager().isAlive());
+ assertFalse(PolicyEngineConstants.getManager().isLocked());
+ assertFalse(PolicyEngineConstants.getManager().getHttpServers().isEmpty());
+ assertTrue(PolicyEngineConstants.getManager().getHttpServers().get(0).isAlive());
}
@Test
public void test300Lock() {
logger.info("enter");
- PolicyEngine.manager.lock();
+ PolicyEngineConstants.getManager().lock();
- assertTrue(PolicyEngine.manager.isAlive());
- assertTrue(PolicyEngine.manager.isLocked());
- assertFalse(PolicyEngine.manager.getHttpServers().isEmpty());
- assertTrue(PolicyEngine.manager.getHttpServers().get(0).isAlive());
+ assertTrue(PolicyEngineConstants.getManager().isAlive());
+ assertTrue(PolicyEngineConstants.getManager().isLocked());
+ assertFalse(PolicyEngineConstants.getManager().getHttpServers().isEmpty());
+ assertTrue(PolicyEngineConstants.getManager().getHttpServers().get(0).isAlive());
}
@Test
public void test301Unlock() {
logger.info("enter");
- PolicyEngine.manager.unlock();
+ PolicyEngineConstants.getManager().unlock();
- assertTrue(PolicyEngine.manager.isAlive());
- assertFalse(PolicyEngine.manager.isLocked());
- assertFalse(PolicyEngine.manager.getHttpServers().isEmpty());
- assertTrue(PolicyEngine.manager.getHttpServers().get(0).isAlive());
+ assertTrue(PolicyEngineConstants.getManager().isAlive());
+ assertFalse(PolicyEngineConstants.getManager().isLocked());
+ assertFalse(PolicyEngineConstants.getManager().getHttpServers().isEmpty());
+ assertTrue(PolicyEngineConstants.getManager().getHttpServers().get(0).isAlive());
}
@Test
@@ -211,20 +214,20 @@ public class PolicyEngineTest {
TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties).get(0).start();
- EventProtocolCoder.manager.addEncoder(
+ EventProtocolCoderConstants.getManager().addEncoder(
EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
.topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getName())
.protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
.modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
- assertTrue(PolicyEngine.manager.deliver(NOOP_TOPIC,
+ assertTrue(PolicyEngineConstants.getManager().deliver(NOOP_TOPIC,
new DroolsConfiguration(ENCODER_GROUP, ENCODER_ARTIFACT, ENCODER_VERSION)));
final TopicSink sink = NoopTopicFactories.getSinkFactory().get(NOOP_TOPIC);
assertTrue(sink.getRecentEvents()[0].contains(ENCODER_GROUP));
assertTrue(sink.getRecentEvents()[0].contains(ENCODER_ARTIFACT));
- EventProtocolCoder.manager.removeEncoders(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC);
+ EventProtocolCoderConstants.getManager().removeEncoders(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC);
}
@Test
@@ -232,19 +235,20 @@ public class PolicyEngineTest {
logger.info("enter");
final Properties controllerProperties = new Properties();
- controllerProperties.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
- PolicyEngine.manager.createPolicyController(TEST_CONTROLLER_NAME, controllerProperties);
+ controllerProperties.put(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
+ PolicyEngineConstants.getManager().createPolicyController(TEST_CONTROLLER_NAME, controllerProperties);
- assertTrue(PolicyController.factory.inventory().size() == 1);
+ assertTrue(PolicyControllerConstants.getFactory().inventory().size() == 1);
- gson.compareGson(PolicyEngine.manager, new File(PolicyEngineTest.class.getSimpleName() + "Add.json"));
+ gson.compareGson(PolicyEngineConstants.getManager(),
+ new File(PolicyEngineTest.class.getSimpleName() + "Add.json"));
}
@Test
public void test401ControllerVerify() {
logger.info("enter");
- final PolicyController testController = PolicyController.factory.get(TEST_CONTROLLER_NAME);
+ final PolicyController testController = PolicyControllerConstants.getFactory().get(TEST_CONTROLLER_NAME);
assertFalse(testController.isAlive());
assertFalse(testController.isLocked());
@@ -259,34 +263,34 @@ public class PolicyEngineTest {
public void test500Deactivate() throws Exception {
logger.info("enter");
- PolicyEngine.manager.deactivate();
+ PolicyEngineConstants.getManager().deactivate();
- final PolicyController testController = PolicyController.factory.get(TEST_CONTROLLER_NAME);
+ final PolicyController testController = PolicyControllerConstants.getFactory().get(TEST_CONTROLLER_NAME);
assertFalse(testController.isAlive());
assertTrue(testController.isLocked());
- assertTrue(PolicyEngine.manager.isLocked());
- assertTrue(PolicyEngine.manager.isAlive());
+ assertTrue(PolicyEngineConstants.getManager().isLocked());
+ assertTrue(PolicyEngineConstants.getManager().isAlive());
}
@Test
public void test501Activate() throws Exception {
logger.info("enter");
- PolicyEngine.manager.activate();
+ PolicyEngineConstants.getManager().activate();
- final PolicyController testController = PolicyController.factory.get(TEST_CONTROLLER_NAME);
+ final PolicyController testController = PolicyControllerConstants.getFactory().get(TEST_CONTROLLER_NAME);
assertTrue(testController.isAlive());
assertFalse(testController.isLocked());
- assertFalse(PolicyEngine.manager.isLocked());
- assertTrue(PolicyEngine.manager.isAlive());
+ assertFalse(PolicyEngineConstants.getManager().isLocked());
+ assertTrue(PolicyEngineConstants.getManager().isAlive());
}
@Test
public void test900ControllerRemove() throws Exception {
logger.info("enter");
- PolicyEngine.manager.removePolicyController(TEST_CONTROLLER_NAME);
- assertTrue(PolicyController.factory.inventory().isEmpty());
+ PolicyEngineConstants.getManager().removePolicyController(TEST_CONTROLLER_NAME);
+ assertTrue(PolicyControllerConstants.getFactory().inventory().isEmpty());
}
@Test
@@ -294,11 +298,11 @@ public class PolicyEngineTest {
logger.info("enter");
/* Shutdown managed resources */
- PolicyController.factory.shutdown();
+ PolicyControllerConstants.getFactory().shutdown();
TopicEndpointManager.getManager().shutdown();
- PolicyEngine.manager.stop();
+ PolicyEngineConstants.getManager().stop();
Thread.sleep(10000L);
- assertFalse(PolicyEngine.manager.isAlive());
+ assertFalse(PolicyEngineConstants.getManager().isAlive());
}
}