diff options
author | Jim Hahn <jrh3@att.com> | 2019-08-05 15:27:16 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-08-13 15:58:15 -0400 |
commit | a156cf3cbad6512510ae9a02a13c0408f901c734 (patch) | |
tree | 0a69bffb2a6c9f961bda1408153cf44f360c6a17 /policy-management/src/main/java/org/onap | |
parent | 62d1ff054b0ec6348ab6f7415063fdaa3f425215 (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/src/main/java/org/onap')
28 files changed, 750 insertions, 429 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(); } } |