aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management')
-rw-r--r--policy-management/checkstyle-suppressions.xml33
-rw-r--r--policy-management/pom.xml36
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java4
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java2
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java2
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java184
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java2
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java1134
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java582
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java112
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java102
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java185
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java533
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafBase.java6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafTelemetryAuthFilter.java2
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/Main.java281
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java27
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java206
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java182
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java60
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java16
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/server/restful/test/TestAafTelemetryAuthFilter.java2
22 files changed, 2172 insertions, 1521 deletions
diff --git a/policy-management/checkstyle-suppressions.xml b/policy-management/checkstyle-suppressions.xml
new file mode 100644
index 00000000..d2b9d1d4
--- /dev/null
+++ b/policy-management/checkstyle-suppressions.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2018 AT&T Technologies. 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<!DOCTYPE suppressions PUBLIC
+ "-//Puppy Crawl//DTD Suppressions 1.0//EN"
+ "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
+
+<suppressions>
+ <suppress checks="AbbreviationAsWordInName"
+ files="DroolsControllerFeatureAPI.java|PolicyControllerFeatureAPI.java|PolicyEngineFeatureAPI.java|EventProtocolCoder.java|ProtocolCoderToolset.java|PdpdConfiguration.java"
+ lines="1-9999"/>
+ <suppress checks="OneTopLevelClass"
+ files="EventProtocolCoder.java|ProtocolCoderToolset.java|PolicyControllerFactory.java|DroolsControllerFactory.java|PolicyEngine.java"
+ lines="1-9999"/>
+</suppressions>
diff --git a/policy-management/pom.xml b/policy-management/pom.xml
index 58c858be..e988b4a5 100644
--- a/policy-management/pom.xml
+++ b/policy-management/pom.xml
@@ -126,6 +126,42 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>onap-java-style</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <phase>process-sources</phase>
+ <configuration>
+ <!-- Use Google Java Style Guide: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
+ with minor changes -->
+ <configLocation>onap-checkstyle/onap-java-style.xml</configLocation>
+ <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory -->
+ <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
+ <includeResources>true</includeResources>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
+ <includeTestResources>true</includeTestResources>
+ <excludes>
+ </excludes>
+ <suppressionsLocation>${project.baseUri}checkstyle-suppressions.xml</suppressionsLocation>
+ <consoleOutput>true</consoleOutput>
+ <failsOnViolation>true</failsOnViolation>
+ <violationSeverity>warning</violationSeverity>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.oparent</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>${oparent.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
</build>
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 93cbc65e..2aaef916 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
@@ -25,9 +25,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.core.PolicyContainer;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
/**
@@ -88,7 +88,7 @@ public class NullDroolsController implements DroolsController {
@Override
public String getVersion() {
return NO_VERSION;
- }
+ }
@Override
public List<String> getSessionNames() {
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 66b206b6..c86f6e0d 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
@@ -220,7 +220,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
* of the operation preventing the invocation of
* lower priority features. False, otherwise..
*/
- public default boolean beforeShutdown(PolicyEngine engine){
+ public default boolean beforeShutdown(PolicyEngine engine) {
return false;
}
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 6864a346..2fcb07d5 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
@@ -305,7 +305,7 @@ public class FileSystemPersistence implements SystemPersistence {
*/
protected File[] sortedListFiles() {
final File[] dirFiles = this.configurationDirectory.toFile().listFiles();
- Arrays.sort(dirFiles, (a, b) -> a.getName().compareTo(b.getName()));
+ Arrays.sort(dirFiles, (e1, e2) -> e1.getName().compareTo(e2.getName()));
return dirFiles;
}
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 3e4e7ecd..6d752897 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
@@ -183,56 +183,54 @@ public interface EventProtocolCoder {
*/
public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic);
-
/**
- * Given a controller id and a topic, it gives back the decoding configuration.
+ * gets all decoders associated with the group and artifact ids.
*
* @param groupId of the controller
* @param artifactId of the controller
- * @param topic the topic
*
- * @return decoding toolset
- *
- * @throw IllegalArgumentException if an invalid parameter is passed
+ * @throws IllegalArgumentException if invalid arguments have been provided
*/
- public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic);
+ public List<CoderFilters> getDecoderFilters(String groupId, String artifactId);
/**
- * Given a controller id and a topic, it gives back all the decoding configurations.
+ * Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding.
*
* @param groupId of the controller
* @param artifactId of the controller
+ * @param topic the topic
+ * @param classname classname
*
- * @return decoding toolset
+ * @return list of decoders
*
* @throw IllegalArgumentException if an invalid parameter is passed
- */
- public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId);
+ */
+ public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname);
/**
- * gets all decoders associated with the group and artifact ids.
+ * Given a controller id and a topic, it gives back the decoding configuration.
*
* @param groupId of the controller
* @param artifactId of the controller
+ * @param topic the topic
*
- * @throws IllegalArgumentException if invalid arguments have been provided
+ * @return decoding toolset
+ *
+ * @throw IllegalArgumentException if an invalid parameter is passed
*/
- public List<CoderFilters> getDecoderFilters(String groupId, String artifactId);
-
+ public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic);
/**
- * Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding.
+ * Given a controller id and a topic, it gives back all the decoding configurations.
*
* @param groupId of the controller
* @param artifactId of the controller
- * @param topic the topic
- * @param classname classname
*
- * @return list of decoders
+ * @return decoding toolset
*
* @throw IllegalArgumentException if an invalid parameter is passed
- */
- public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname);
+ */
+ public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId);
/**
* Given a controller id and a topic, it gives back the classes that implements the encoding.
@@ -411,7 +409,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void addDecoder(String groupId, String artifactId, String topic,
@@ -429,7 +427,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void addEncoder(String groupId, String artifactId, String topic,
@@ -447,7 +445,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void removeDecoders(String groupId, String artifactId, String topic) {
@@ -456,7 +454,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void removeEncoders(String groupId, String artifactId, String topic) {
@@ -465,7 +463,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean isDecodingSupported(String groupId, String artifactId, String topic) {
@@ -473,7 +471,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean isEncodingSupported(String groupId, String artifactId, String topic) {
@@ -481,7 +479,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public Object decode(String groupId, String artifactId, String topic, String json) {
@@ -490,7 +488,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public String encode(String groupId, String artifactId, String topic, Object event) {
@@ -499,7 +497,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public String encode(String topic, Object event) {
@@ -508,7 +506,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public String encode(String topic, Object event, DroolsController droolsController) {
@@ -517,7 +515,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic) {
@@ -525,7 +523,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) {
@@ -533,7 +531,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) {
@@ -542,7 +540,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) {
@@ -582,7 +580,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic) {
@@ -590,7 +588,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) {
@@ -598,7 +596,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) {
@@ -606,7 +604,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass) {
@@ -614,7 +612,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public DroolsController getDroolsController(String topic, Object encodedClass) {
@@ -622,7 +620,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) {
@@ -630,7 +628,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public String toString() {
@@ -722,7 +720,7 @@ abstract class GenericEventProtocolCoder {
if (coders.containsKey(key)) {
Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolsets = coders.get(key);
- logger.info("{}: adding coders for existing {}: ", this, key, toolsets.first());
+ logger.info("{}: adding coders for existing {}: {}", this, key, toolsets.first());
toolsets.first().addCoder(eventClass, protocolFilter, modelClassLoaderHash);
toolsets.second().addCoder(eventClass, protocolFilter, modelClassLoaderHash);
@@ -869,7 +867,7 @@ abstract class GenericEventProtocolCoder {
while (toolsetsIter.hasNext()) {
Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolset = toolsetsIter.next();
if (toolset.first().getControllerId().equals(key)) {
- logger.info("{}: removed coder from toolset for {} from reverse mapping {}: ",
+ logger.info("{}: removed coder from toolset for {} from reverse mapping",
this, reverseKey);
toolsetsIter.remove();
}
@@ -1024,6 +1022,29 @@ abstract class GenericEventProtocolCoder {
/**
* encode an object into a json string.
*
+ * @param topic topic
+ * @param encodedClass object to convert to string
+ * @return the json string
+ * @throws IllegalArgumentException if invalid argument is provided
+ * @throws UnsupportedOperationException if the operation cannot be performed
+ */
+ public String encode(String topic, Object encodedClass, DroolsController droolsController) {
+
+ if (encodedClass == null) {
+ throw new IllegalArgumentException("Invalid encoded class");
+ }
+
+ if (topic == null || topic.isEmpty()) {
+ throw new IllegalArgumentException("Invalid topic");
+ }
+
+ String key = codersKey(droolsController.getGroupId(), droolsController.getArtifactId(), topic);
+ return this.encodeInternal(key, encodedClass);
+ }
+
+ /**
+ * encode an object into a json string.
+ *
* @param key identifier
* @param event object to convert to string
* @return the json string
@@ -1069,29 +1090,6 @@ abstract class GenericEventProtocolCoder {
}
/**
- * encode an object into a json string.
- *
- * @param topic topic
- * @param encodedClass object to convert to string
- * @return the json string
- * @throws IllegalArgumentException if invalid argument is provided
- * @throws UnsupportedOperationException if the operation cannot be performed
- */
- public String encode(String topic, Object encodedClass, DroolsController droolsController) {
-
- if (encodedClass == null) {
- throw new IllegalArgumentException("Invalid encoded class");
- }
-
- if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("Invalid topic");
- }
-
- String key = codersKey(droolsController.getGroupId(), droolsController.getArtifactId(), topic);
- return this.encodeInternal(key, encodedClass);
- }
-
- /**
* Drools creators.
*
* @param topic topic
@@ -1202,6 +1200,31 @@ abstract class GenericEventProtocolCoder {
}
/**
+ * get all filters by maven coordinates, topic, and classname.
+ *
+ * @param groupId group id
+ * @param artifactId artifact id
+ * @param topic topic
+ * @param classname classname
+ * @return list of coders
+ * @throws IllegalArgumentException if invalid input
+ */
+ public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) {
+
+ if (!isCodingSupported(groupId, artifactId, topic)) {
+ throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
+ }
+
+ if (classname == null || classname.isEmpty()) {
+ throw new IllegalArgumentException("classname must be provided");
+ }
+
+ String key = this.codersKey(groupId, artifactId, topic);
+ Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key);
+ return coderTools.first().getCoder(classname);
+ }
+
+ /**
* get all coders by maven coordinates and topic.
*
* @param groupId group id
@@ -1251,31 +1274,6 @@ abstract class GenericEventProtocolCoder {
}
/**
- * get all filters by maven coordinates, topic, and classname.
- *
- * @param groupId group id
- * @param artifactId artifact id
- * @param topic topic
- * @param classname classname
- * @return list of coders
- * @throws IllegalArgumentException if invalid input
- */
- public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) {
-
- if (!isCodingSupported(groupId, artifactId, topic)) {
- throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
- }
-
- if (classname == null || classname.isEmpty()) {
- throw new IllegalArgumentException("classname must be provided");
- }
-
- String key = this.codersKey(groupId, artifactId, topic);
- Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key);
- return coderTools.first().getCoder(classname);
- }
-
- /**
* get coded based on class and topic.
*
* @param topic topic
@@ -1342,7 +1340,7 @@ abstract class GenericEventProtocolCoder {
*
* @param topic topic
* @param fact fact
- * @return
+ * @return list of drools controllers
*/
List<DroolsController> getDroolsControllers(String topic, Object fact) {
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
index 4fd2f522..f65efaed 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
@@ -287,7 +287,7 @@ public class JsonProtocolFilter {
* Get rules.
*
* @param name name
- * @return
+ * @return list of filter rules
*/
public List<FilterRule> getRules(String name) {
if (name == null || name.isEmpty()) {
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
index 7ee8b08a..ead6794c 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
@@ -20,6 +20,21 @@
package org.onap.policy.drools.protocol.coders;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -38,637 +53,630 @@ import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.Cust
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
/**
- * Protocol Coding/Decoding Toolset
+ * Protocol Coding/Decoding Toolset.
*/
public abstract class ProtocolCoderToolset {
- /**
- * Logger
- */
- private static Logger logger = LoggerFactory.getLogger(ProtocolCoderToolset.class);
-
- /**
- * topic
- */
- protected final String topic;
-
- /**
- * controller id
- */
- protected final String controllerId;
-
- /**
- * group id
- */
- protected final String groupId;
-
- /**
- * artifact id
- */
- protected final String artifactId;
-
- /**
- * Protocols and associated Filters
- */
- protected final List<CoderFilters> coders = new CopyOnWriteArrayList<>();
-
- /**
- * Tree model (instead of class model) generic parsing to be able to inspect elements
- */
- protected JsonParser filteringParser = new JsonParser();
-
- /**
- * custom coder
- */
- protected CustomCoder customCoder;
-
- /**
- * Constructor
- *
- * @param topic the topic
- * @param controllerId the controller id
- * @param codedClass the decoded class
- * @param filters list of filters that apply to the selection of this decodedClass in case of
- * multiplicity
- * @throws IllegalArgumentException if invalid data has been passed in
- */
- public ProtocolCoderToolset(String topic, String controllerId, String groupId, String artifactId,
- String codedClass, JsonProtocolFilter filters, CustomCoder customCoder,
- int modelClassLoaderHash) {
-
- if (topic == null || controllerId == null || groupId == null || artifactId == null
- || codedClass == null || filters == null || topic.isEmpty() || controllerId.isEmpty()) {
- throw new IllegalArgumentException("Invalid input");
+ /**
+ * Logger.
+ */
+ private static Logger logger = LoggerFactory.getLogger(ProtocolCoderToolset.class);
+
+ /**
+ * topic.
+ */
+ protected final String topic;
+
+ /**
+ * controller id.
+ */
+ protected final String controllerId;
+
+ /**
+ * group id.
+ */
+ protected final String groupId;
+
+ /**
+ * artifact id.
+ */
+ protected final String artifactId;
+
+ /**
+ * Protocols and associated Filters.
+ */
+ protected final List<CoderFilters> coders = new CopyOnWriteArrayList<>();
+
+ /**
+ * Tree model (instead of class model) generic parsing to be able to inspect elements.
+ */
+ protected JsonParser filteringParser = new JsonParser();
+
+ /**
+ * custom coder.
+ */
+ protected CustomCoder customCoder;
+
+ /**
+ * Constructor.
+ *
+ * @param topic the topic
+ * @param controllerId the controller id
+ * @param codedClass the decoded class
+ * @param filters list of filters that apply to the selection of this decodedClass in case of
+ * multiplicity
+ * @throws IllegalArgumentException if invalid data has been passed in
+ */
+ public ProtocolCoderToolset(String topic, String controllerId, String groupId, String artifactId,
+ String codedClass, JsonProtocolFilter filters, CustomCoder customCoder,
+ int modelClassLoaderHash) {
+
+ if (topic == null || controllerId == null || groupId == null || artifactId == null
+ || codedClass == null || filters == null || topic.isEmpty() || controllerId.isEmpty()) {
+ throw new IllegalArgumentException("Invalid input");
+ }
+
+ this.topic = topic;
+ this.controllerId = controllerId;
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.coders.add(new CoderFilters(codedClass, filters, modelClassLoaderHash));
+ this.customCoder = customCoder;
+ }
+
+ /**
+ * gets the coder + filters associated with this class name.
+ *
+ * @param classname class name
+ * @return the decoder filters or null if not found
+ */
+ public CoderFilters getCoder(String classname) {
+ if (classname == null || classname.isEmpty()) {
+ throw new IllegalArgumentException("no classname provided");
+ }
+
+ for (final CoderFilters decoder : this.coders) {
+ if (decoder.factClass.equals(classname)) {
+ return decoder;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * get a copy of the coder filters in use.
+ *
+ * @return coder filters
+ */
+ public List<CoderFilters> getCoders() {
+ return new ArrayList<>(this.coders);
+ }
+
+ /**
+ * add coder or replace it exists.
+ *
+ * @param eventClass decoder
+ * @param filter filter
+ */
+ public void addCoder(String eventClass, JsonProtocolFilter filter, int modelClassLoaderHash) {
+ if (eventClass == null || eventClass.isEmpty()) {
+ throw new IllegalArgumentException("no event class provided");
+ }
+
+ for (final CoderFilters coder : this.coders) {
+ if (coder.getCodedClass().equals(eventClass)) {
+ coder.setFilter(filter);
+ coder.setFromClassLoaderHash(modelClassLoaderHash);
+ return;
+ }
+ }
+ this.coders.add(new CoderFilters(eventClass, filter, modelClassLoaderHash));
+ }
+
+ /**
+ * remove coder.
+ *
+ * @param eventClass event class
+ */
+ public void removeCoders(String eventClass) {
+ if (eventClass == null || eventClass.isEmpty()) {
+ throw new IllegalArgumentException("no event class provided");
+ }
+
+ List<CoderFilters> temp = new ArrayList<>();
+ for (final CoderFilters coder : this.coders) {
+ if (coder.factClass.equals(eventClass)) {
+ temp.add(coder);
+ }
+ }
+
+ this.coders.removeAll(temp);
}
- this.topic = topic;
- this.controllerId = controllerId;
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.coders.add(new CoderFilters(codedClass, filters, modelClassLoaderHash));
- this.customCoder = customCoder;
- }
-
- /**
- * gets the coder + filters associated with this class name
- *
- * @param classname class name
- * @return the decoder filters or null if not found
- */
- public CoderFilters getCoder(String classname) {
- if (classname == null || classname.isEmpty())
- throw new IllegalArgumentException("no classname provided");
-
- for (final CoderFilters decoder : this.coders) {
- if (decoder.factClass.equals(classname)) {
- return decoder;
- }
+ /**
+ * gets the topic.
+ *
+ * @return the topic
+ */
+ public String getTopic() {
+ return this.topic;
}
- return null;
- }
-
- /**
- * get a copy of the coder filters in use
- *
- * @return coder filters
- */
- public List<CoderFilters> getCoders() {
- return new ArrayList<>(this.coders);
- }
-
- /**
- * add coder or replace it exists
- *
- * @param eventClass decoder
- * @param filter filter
- */
- public void addCoder(String eventClass, JsonProtocolFilter filter, int modelClassLoaderHash) {
- if (eventClass == null || eventClass.isEmpty())
- throw new IllegalArgumentException("no event class provided");
-
- for (final CoderFilters coder : this.coders) {
- if (coder.getCodedClass().equals(eventClass)) {
- coder.setFilter(filter);
- coder.setFromClassLoaderHash(modelClassLoaderHash);
- return;
- }
+
+ /**
+ * gets the controller id.
+ *
+ * @return the controller id
+ */
+ public String getControllerId() {
+ return this.controllerId;
}
- this.coders.add(new CoderFilters(eventClass, filter, modelClassLoaderHash));
- }
-
- /**
- * remove coder
- * @param eventClass event class
- */
- public void removeCoders(String eventClass) {
- if (eventClass == null || eventClass.isEmpty())
- throw new IllegalArgumentException("no event class provided");
-
- List<CoderFilters> temp = new ArrayList<>();
- for (final CoderFilters coder : this.coders) {
- if (coder.factClass.equals(eventClass)) {
- temp.add(coder);
- }
+
+ /**
+ * Get group id.
+ *
+ * @return the groupId
+ */
+ public String getGroupId() {
+ return this.groupId;
}
- this.coders.removeAll(temp);
- }
-
- /**
- * gets the topic
- *
- * @return the topic
- */
- public String getTopic() {
- return this.topic;
- }
-
- /**
- * gets the controller id
- *
- * @return the controller id
- */
- public String getControllerId() {
- return this.controllerId;
- }
-
- /**
- * @return the groupId
- */
- public String getGroupId() {
- return this.groupId;
- }
-
- /**
- * @return the artifactId
- */
- public String getArtifactId() {
- return this.artifactId;
- }
-
- /**
- * @return the customCoder
- */
- public CustomCoder getCustomCoder() {
- return this.customCoder;
- }
-
- /**
- * @param customCoder the customCoder to set
- */
- public void setCustomCoder(CustomCoder customCoder) {
- this.customCoder = customCoder;
- }
-
- /**
- * performs filtering on a json string
- *
- * @param json json string
- * @return the decoder that passes the filter, otherwise null
- * @throws UnsupportedOperationException can't filter
- * @throws IllegalArgumentException invalid input
- */
- protected CoderFilters filter(String json) {
-
-
- // 1. Get list of decoding classes for this controller Id and topic
- // 2. If there are no classes, return error
- // 3. Otherwise, from the available classes for decoding, pick the first one that
- // passes the filters
-
- // Don't parse if it is not necessary
-
- if (this.coders.isEmpty()) {
- throw new IllegalStateException("No coders available");
+ /**
+ * Get artifact id.
+ *
+ * @return the artifactId
+ */
+ public String getArtifactId() {
+ return this.artifactId;
}
- if (this.coders.size() == 1) {
- final JsonProtocolFilter filter = this.coders.get(0).getFilter();
- if (!filter.isRules()) {
- return this.coders.get(0);
- }
+ /**
+ * Get custom coder.
+ *
+ * @return the customCoder
+ */
+ public CustomCoder getCustomCoder() {
+ return this.customCoder;
}
- JsonElement event;
- try {
- event = this.filteringParser.parse(json);
- } catch (final Exception e) {
- throw new UnsupportedOperationException(e);
+ /**
+ * Set custom coder.
+ *
+ * @param customCoder the customCoder to set.
+ */
+ public void setCustomCoder(CustomCoder customCoder) {
+ this.customCoder = customCoder;
}
- for (final CoderFilters decoder : this.coders) {
- try {
- final boolean accepted = decoder.getFilter().accept(event);
- if (accepted) {
- return decoder;
+ /**
+ * performs filtering on a json string.
+ *
+ * @param json json string
+ * @return the decoder that passes the filter, otherwise null
+ * @throws UnsupportedOperationException can't filter
+ * @throws IllegalArgumentException invalid input
+ */
+ protected CoderFilters filter(String json) {
+
+
+ // 1. Get list of decoding classes for this controller Id and topic
+ // 2. If there are no classes, return error
+ // 3. Otherwise, from the available classes for decoding, pick the first one that
+ // passes the filters
+
+ // Don't parse if it is not necessary
+
+ if (this.coders.isEmpty()) {
+ throw new IllegalStateException("No coders available");
}
- } catch (final Exception e) {
- logger.info("{}: unexpected failure accepting {} because of {}", this, event,
- e.getMessage(), e);
- // continue
- }
+
+ if (this.coders.size() == 1) {
+ final JsonProtocolFilter filter = this.coders.get(0).getFilter();
+ if (!filter.isRules()) {
+ return this.coders.get(0);
+ }
+ }
+
+ JsonElement event;
+ try {
+ event = this.filteringParser.parse(json);
+ } catch (final Exception e) {
+ throw new UnsupportedOperationException(e);
+ }
+
+ for (final CoderFilters decoder : this.coders) {
+ try {
+ final boolean accepted = decoder.getFilter().accept(event);
+ if (accepted) {
+ return decoder;
+ }
+ } catch (final Exception e) {
+ logger.info("{}: unexpected failure accepting {} because of {}", this, event,
+ e.getMessage(), e);
+ // continue
+ }
+ }
+
+ return null;
}
- return null;
- }
-
- /**
- * Decode json into a POJO object
- *
- * @param json json string
- *
- * @return a POJO object for the json string
- * @throws IllegalArgumentException if an invalid parameter has been received
- * @throws UnsupportedOperationException if parsing into POJO is not possible
- */
- public abstract Object decode(String json);
-
- /**
- * Encodes a POJO object into a JSON String
- *
- * @param event JSON POJO event to be converted to String
- * @return JSON string version of POJO object
- * @throws IllegalArgumentException if an invalid parameter has been received
- * @throws UnsupportedOperationException if parsing into POJO is not possible
- */
- public abstract String encode(Object event);
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("ProtocolCoderToolset [topic=").append(this.topic).append(", controllerId=")
+ /**
+ * Decode json into a POJO object.
+ *
+ * @param json json string
+ *
+ * @return a POJO object for the json string
+ * @throws IllegalArgumentException if an invalid parameter has been received
+ * @throws UnsupportedOperationException if parsing into POJO is not possible
+ */
+ public abstract Object decode(String json);
+
+ /**
+ * Encodes a POJO object into a JSON String.
+ *
+ * @param event JSON POJO event to be converted to String
+ * @return JSON string version of POJO object
+ * @throws IllegalArgumentException if an invalid parameter has been received
+ * @throws UnsupportedOperationException if parsing into POJO is not possible
+ */
+ public abstract String encode(Object event);
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("ProtocolCoderToolset [topic=").append(this.topic).append(", controllerId=")
.append(this.controllerId).append(", groupId=").append(this.groupId).append(", artifactId=")
.append(this.artifactId).append(", coders=").append(this.coders)
.append(", filteringParser=").append(this.filteringParser).append(", customCoder=")
.append(this.customCoder).append("]");
- return builder.toString();
- }
+ return builder.toString();
+ }
}
/**
- * Tools used for encoding/decoding using Jackson
+ * Tools used for encoding/decoding using Jackson.
*/
class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
- private static final String WARN_FETCH_FAILED = "{}: cannot fetch application class {}";
-private static final String WARN_FETCH_FAILED_BECAUSE = "{}: cannot fetch application class {} because of {}";
-private static final String FETCH_FAILED = "cannot fetch application class ";
-private static final String ENCODE_FAILED = "event cannot be encoded";
-private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class);
- /**
- * decoder
- */
- @JsonIgnore
- protected final ObjectMapper decoder = new ObjectMapper();
-
- /**
- * encoder
- */
- @JsonIgnore
- protected final ObjectMapper encoder = new ObjectMapper();
-
- /**
- * Toolset to encode/decode tools associated with a topic
- *
- * @param topic topic
- * @param decodedClass decoded class of an event
- * @param filter
- */
- public JacksonProtocolCoderToolset(String topic, String controllerId, String groupId,
- String artifactId, String decodedClass, JsonProtocolFilter filter,
- CustomJacksonCoder customJacksonCoder, int modelClassLoaderHash) {
- super(topic, controllerId, groupId, artifactId, decodedClass, filter, customJacksonCoder,
- modelClassLoaderHash);
- this.decoder.registerModule(new JavaTimeModule());
- this.decoder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- }
-
- /**
- * gets the Jackson decoder
- *
- * @return the Jackson decoder
- */
- @JsonIgnore
- protected ObjectMapper getDecoder() {
- return this.decoder;
- }
-
- /**
- * gets the Jackson encoder
- *
- * @return the Jackson encoder
- */
- @JsonIgnore
- protected ObjectMapper getEncoder() {
- return this.encoder;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object decode(String json) {
-
- // 0. Use custom coder if available
-
- if (this.customCoder != null) {
- throw new UnsupportedOperationException(
- "Jackon Custom Decoder is not supported at this time");
+ private static final String WARN_FETCH_FAILED = "{}: cannot fetch application class {}";
+ private static final String WARN_FETCH_FAILED_BECAUSE = "{}: cannot fetch application class {} because of {}";
+ private static final String FETCH_FAILED = "cannot fetch application class ";
+ private static final String ENCODE_FAILED = "event cannot be encoded";
+ private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class);
+
+ /**
+ * decoder.
+ */
+ @JsonIgnore
+ protected final ObjectMapper decoder = new ObjectMapper();
+
+ /**
+ * encoder.
+ */
+ @JsonIgnore
+ protected final ObjectMapper encoder = new ObjectMapper();
+
+ /**
+ * Toolset to encode/decode tools associated with a topic.
+ *
+ * @param topic topic
+ * @param decodedClass decoded class of an event
+ * @param filter filter
+ */
+ public JacksonProtocolCoderToolset(String topic, String controllerId, String groupId,
+ String artifactId, String decodedClass, JsonProtocolFilter filter,
+ CustomJacksonCoder customJacksonCoder, int modelClassLoaderHash) {
+ super(topic, controllerId, groupId, artifactId, decodedClass, filter, customJacksonCoder,
+ modelClassLoaderHash);
+ this.decoder.registerModule(new JavaTimeModule());
+ this.decoder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
- final DroolsController droolsController =
- DroolsController.factory.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");
+ /**
+ * gets the Jackson decoder.
+ *
+ * @return the Jackson decoder
+ */
+ @JsonIgnore
+ protected ObjectMapper getDecoder() {
+ return this.decoder;
}
- final CoderFilters decoderFilter = this.filter(json);
- if (decoderFilter == null) {
- logger.debug("{}: no decoder to process {}", this, json);
- throw new UnsupportedOperationException("no decoder to process event");
+ /**
+ * gets the Jackson encoder.
+ *
+ * @return the Jackson encoder
+ */
+ @JsonIgnore
+ protected ObjectMapper getEncoder() {
+ return this.encoder;
}
- Class<?> decoderClass;
- try {
- decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass());
- if (decoderClass == null) {
- logger.warn(WARN_FETCH_FAILED, this, decoderFilter.getCodedClass());
- throw new IllegalStateException(
- FETCH_FAILED + decoderFilter.getCodedClass());
- }
- } catch (final Exception e) {
- logger.warn(WARN_FETCH_FAILED_BECAUSE, this,
- decoderFilter.getCodedClass(), e.getMessage());
- throw new UnsupportedOperationException(
- FETCH_FAILED + decoderFilter.getCodedClass(), e);
- }
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public Object decode(String json) {
+ // 0. Use custom coder if available
- try {
- return this.decoder.readValue(json, decoderClass);
- } catch (final Exception e) {
- logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(),
- e.getMessage(), e);
- throw new UnsupportedOperationException(
- "cannont decode into " + decoderFilter.getCodedClass(), e);
- }
- }
+ if (this.customCoder != null) {
+ throw new UnsupportedOperationException(
+ "Jackon Custom Decoder is not supported at this time");
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public String encode(Object event) {
+ final DroolsController droolsController =
+ DroolsController.factory.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");
+ }
- // 0. Use custom coder if available
+ final CoderFilters decoderFilter = this.filter(json);
+ if (decoderFilter == null) {
+ logger.debug("{}: no decoder to process {}", this, json);
+ throw new UnsupportedOperationException("no decoder to process event");
+ }
- if (this.customCoder != null) {
- throw new UnsupportedOperationException(
- "Jackon Custom Encoder is not supported at this time");
+ Class<?> decoderClass;
+ try {
+ decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass());
+ if (decoderClass == null) {
+ logger.warn(WARN_FETCH_FAILED, this, decoderFilter.getCodedClass());
+ throw new IllegalStateException(
+ FETCH_FAILED + decoderFilter.getCodedClass());
+ }
+ } catch (final Exception e) {
+ logger.warn(WARN_FETCH_FAILED_BECAUSE, this,
+ decoderFilter.getCodedClass(), e.getMessage());
+ throw new UnsupportedOperationException(
+ FETCH_FAILED + decoderFilter.getCodedClass(), e);
+ }
+
+
+ try {
+ return this.decoder.readValue(json, decoderClass);
+ } catch (final Exception e) {
+ logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(),
+ e.getMessage(), e);
+ throw new UnsupportedOperationException(
+ "cannont decode into " + decoderFilter.getCodedClass(), e);
+ }
}
- try {
- return this.encoder.writeValueAsString(event);
- } catch (final JsonProcessingException e) {
- logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e);
- throw new UnsupportedOperationException(ENCODE_FAILED);
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String encode(Object event) {
+
+ // 0. Use custom coder if available
+
+ if (this.customCoder != null) {
+ throw new UnsupportedOperationException(
+ "Jackon Custom Encoder is not supported at this time");
+ }
+
+ try {
+ return this.encoder.writeValueAsString(event);
+ } catch (final JsonProcessingException e) {
+ logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e);
+ throw new UnsupportedOperationException(ENCODE_FAILED);
+ }
}
- }
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("JacksonProtocolCoderToolset [toString()=").append(super.toString()).append("]");
- return builder.toString();
- }
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("JacksonProtocolCoderToolset [toString()=").append(super.toString()).append("]");
+ return builder.toString();
+ }
}
/**
- * Tools used for encoding/decoding using Jackson
+ * Tools used for encoding/decoding using Jackson.
*/
class GsonProtocolCoderToolset extends ProtocolCoderToolset {
- /**
- * Logger
- */
- private static final Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class);
-
- /**
- * Formatter for JSON encoding/decoding
- */
- @JsonIgnore
- public static final DateTimeFormatter format =
- DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
-
- @JsonIgnore
- public static final DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT;
-
- /**
- * Adapter for ZonedDateTime
- */
- public static class GsonUTCAdapter
- implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
- @Override
- public ZonedDateTime deserialize(JsonElement element, Type type,
- JsonDeserializationContext context) {
- try {
- return ZonedDateTime.parse(element.getAsString(), format);
- } catch (final Exception e) {
- logger.info("GsonUTCAdapter: cannot parse {} because of {}", element, e.getMessage(), e);
- }
- return null;
- }
+ /**
+ * Logger.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class);
+
+ /**
+ * Formatter for JSON encoding/decoding.
+ */
+ @JsonIgnore
+ public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
+
+ @JsonIgnore
+ public static final DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT;
+
+ /**
+ * Adapter for ZonedDateTime.
+ */
+ public static class GsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
+ @Override
+ public ZonedDateTime deserialize(JsonElement element, Type type,
+ JsonDeserializationContext context) {
+ try {
+ return ZonedDateTime.parse(element.getAsString(), format);
+ } catch (final Exception e) {
+ logger.info("GsonUTCAdapter: cannot parse {} because of {}", element, e.getMessage(), e);
+ }
+ return null;
+ }
- @Override
- public JsonElement serialize(ZonedDateTime datetime, Type type,
- JsonSerializationContext context) {
- return new JsonPrimitive(datetime.format(format));
+ @Override
+ public JsonElement serialize(ZonedDateTime datetime, Type type,
+ JsonSerializationContext context) {
+ return new JsonPrimitive(datetime.format(format));
+ }
}
- }
- public static class GsonInstantAdapter
- implements JsonSerializer<Instant>, JsonDeserializer<Instant> {
+ public static class GsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> {
- @Override
- public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
- return Instant.ofEpochMilli(json.getAsLong());
- }
+ @Override
+ public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
+ return Instant.ofEpochMilli(json.getAsLong());
+ }
- @Override
- public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) {
- return new JsonPrimitive(src.toEpochMilli());
- }
+ @Override
+ public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) {
+ return new JsonPrimitive(src.toEpochMilli());
+ }
- }
-
-
- /**
- * decoder
- */
- @JsonIgnore
- protected final Gson decoder = new GsonBuilder().disableHtmlEscaping()
- .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter())
- .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create();
-
- /**
- * encoder
- */
- @JsonIgnore
- protected final Gson encoder = new GsonBuilder().disableHtmlEscaping()
- .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter())
- .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create();
-
- /**
- * Toolset to encode/decode tools associated with a topic
- *
- * @param topic topic
- * @param decodedClass decoded class of an event
- * @param filter
- */
- public GsonProtocolCoderToolset(String topic, String controllerId, String groupId,
- String artifactId, String decodedClass, JsonProtocolFilter filter,
- CustomGsonCoder customGsonCoder, int modelClassLoaderHash) {
- super(topic, controllerId, groupId, artifactId, decodedClass, filter, customGsonCoder,
- modelClassLoaderHash);
- }
-
- /**
- * gets the Gson decoder
- *
- * @return the Gson decoder
- */
- @JsonIgnore
- protected Gson getDecoder() {
- return this.decoder;
- }
-
- /**
- * gets the Gson encoder
- *
- * @return the Gson encoder
- */
- @JsonIgnore
- protected Gson getEncoder() {
- return this.encoder;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object decode(String json) {
-
- final DroolsController droolsController =
- DroolsController.factory.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");
}
- final CoderFilters decoderFilter = this.filter(json);
- if (decoderFilter == null) {
- logger.debug("{}: no decoder to process {}", this, json);
- throw new UnsupportedOperationException("no decoder to process event");
+
+ /**
+ * decoder.
+ */
+ @JsonIgnore
+ protected final Gson decoder = new GsonBuilder().disableHtmlEscaping()
+ .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter())
+ .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create();
+
+ /**
+ * encoder.
+ */
+ @JsonIgnore
+ protected final Gson encoder = new GsonBuilder().disableHtmlEscaping()
+ .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter())
+ .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create();
+
+ /**
+ * Toolset to encode/decode tools associated with a topic.
+ *
+ * @param topic topic
+ * @param decodedClass decoded class of an event
+ * @param filter filter
+ */
+ public GsonProtocolCoderToolset(String topic, String controllerId, String groupId,
+ String artifactId, String decodedClass, JsonProtocolFilter filter,
+ CustomGsonCoder customGsonCoder, int modelClassLoaderHash) {
+ super(topic, controllerId, groupId, artifactId, decodedClass, filter, customGsonCoder,
+ modelClassLoaderHash);
}
- Class<?> decoderClass;
- try {
- decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass());
- if (decoderClass == null) {
- logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass());
- throw new IllegalStateException(
- "cannot fetch application class " + 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);
+ /**
+ * gets the Gson decoder.
+ *
+ * @return the Gson decoder
+ */
+ @JsonIgnore
+ protected Gson getDecoder() {
+ return this.decoder;
}
- if (this.customCoder != null) {
- try {
- final Class<?> gsonClassContainer =
- droolsController.fetchModelClass(this.customCoder.getClassContainer());
- final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
- final Object gsonObject = gsonField.get(null);
- final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson",
- new Class[] {String.class, Class.class});
- return fromJsonMethod.invoke(gsonObject, json, decoderClass);
- } 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);
- }
- } else {
- try {
- return this.decoder.fromJson(json, decoderClass);
- } catch (final Exception e) {
- logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(),
- e.getMessage(), e);
- throw new UnsupportedOperationException(
- "cannont decode into " + decoderFilter.getCodedClass(), e);
- }
+ /**
+ * gets the Gson encoder.
+ *
+ * @return the Gson encoder
+ */
+ @JsonIgnore
+ protected Gson getEncoder() {
+ return this.encoder;
}
- }
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public Object decode(String json) {
+
+ final DroolsController droolsController =
+ DroolsController.factory.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");
+ }
+ final CoderFilters decoderFilter = this.filter(json);
+ if (decoderFilter == null) {
+ logger.debug("{}: no decoder to process {}", this, json);
+ throw new UnsupportedOperationException("no decoder to process event");
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public String encode(Object event) {
+ Class<?> decoderClass;
+ try {
+ decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass());
+ if (decoderClass == null) {
+ logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass());
+ throw new IllegalStateException(
+ "cannot fetch application class " + 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);
+ }
- if (this.customCoder != null) {
- try {
- final DroolsController droolsController =
- DroolsController.factory.get(this.groupId, this.artifactId, null);
- final Class<?> gsonClassContainer =
- droolsController.fetchModelClass(this.customCoder.getClassContainer());
- final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
- final Object gsonObject = gsonField.get(null);
- final Method toJsonMethod =
- gsonObject.getClass().getDeclaredMethod("toJson", new Class[] {Object.class});
- return (String) toJsonMethod.invoke(gsonObject, event);
- } catch (final Exception e) {
- logger.warn("{} cannot custom-encode {} because of {}", this, event, e.getMessage(), e);
- throw new UnsupportedOperationException("event cannot be encoded", e);
- }
- } else {
- try {
- return this.encoder.toJson(event);
- } catch (final Exception e) {
- logger.warn("{} cannot encode {} because of {}", this, event, e.getMessage(), e);
- throw new UnsupportedOperationException("event cannot be encoded", e);
- }
+ if (this.customCoder != null) {
+ try {
+ final Class<?> gsonClassContainer =
+ droolsController.fetchModelClass(this.customCoder.getClassContainer());
+ final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
+ final Object gsonObject = gsonField.get(null);
+ final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson",
+ new Class[] {String.class, Class.class});
+ return fromJsonMethod.invoke(gsonObject, json, decoderClass);
+ } 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);
+ }
+ } else {
+ try {
+ return this.decoder.fromJson(json, decoderClass);
+ } catch (final Exception e) {
+ logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(),
+ e.getMessage(), e);
+ throw new UnsupportedOperationException(
+ "cannont decode into " + decoderFilter.getCodedClass(), e);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String encode(Object event) {
+
+ if (this.customCoder != null) {
+ try {
+ final DroolsController droolsController =
+ DroolsController.factory.get(this.groupId, this.artifactId, null);
+ final Class<?> gsonClassContainer =
+ droolsController.fetchModelClass(this.customCoder.getClassContainer());
+ final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
+ final Object gsonObject = gsonField.get(null);
+ final Method toJsonMethod =
+ gsonObject.getClass().getDeclaredMethod("toJson", new Class[] {Object.class});
+ return (String) toJsonMethod.invoke(gsonObject, event);
+ } catch (final Exception e) {
+ logger.warn("{} cannot custom-encode {} because of {}", this, event, e.getMessage(), e);
+ throw new UnsupportedOperationException("event cannot be encoded", e);
+ }
+ } else {
+ try {
+ return this.encoder.toJson(event);
+ } catch (final Exception e) {
+ logger.warn("{} cannot encode {} because of {}", this, event, e.getMessage(), e);
+ throw new UnsupportedOperationException("event cannot be encoded", e);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("GsonProtocolCoderToolset [toString()=").append(super.toString()).append("]");
+ return builder.toString();
}
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("GsonProtocolCoderToolset [toString()=").append(super.toString()).append("]");
- return builder.toString();
- }
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
index 7c1b128f..f7fc4d21 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
@@ -24,286 +24,308 @@ import java.util.List;
public class TopicCoderFilterConfiguration {
- /**
- * Custom coder, contains class and static field to access parser that the controller
- * desires to use instead of the framework provided parser
- */
- public abstract static class CustomCoder {
- protected String className;
- protected String staticCoderField;
-
- /**
- * create custom coder from raw string in the following format
- * (typically embedded in a property file):
- *
- * Note this is to support decoding/encoding of partial structures that are
- * only known by the model.
- *
- * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field>
- */
- public CustomCoder(String rawCustomCoder) {
- if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
-
- this.className = rawCustomCoder.substring(0,rawCustomCoder.indexOf(","));
- if (this.className == null || this.className.isEmpty()) {
- throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
- }
-
- this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",")+1);
- if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
- throw new IllegalArgumentException
- ("No staticCoderField to create CustomCoder cannot be created for class " +
- className);
- }
-
- }
- }
- /**
- * @param classContainer
- * @param staticCoderField
- */
- public CustomCoder(String className, String staticCoderField) {
- if (className == null || className.isEmpty()) {
- throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
- }
-
- if (staticCoderField == null || staticCoderField.isEmpty()) {
- throw new IllegalArgumentException
- ("No staticCoderField to create CustomCoder cannot be created for class " +
- className);
- }
-
- this.className = className;
- this.staticCoderField = staticCoderField;
- }
-
- /**
- * @return the className
- */
- public String getClassContainer() {
- return className;
- }
-
- /**
- * @param className the className to set
- */
- public void setClassContainer(String className) {
- this.className = className;
- }
-
- /**
- * @return the staticCoderField
- */
- public String getStaticCoderField() {
- return staticCoderField;
- }
-
- /**
- * @param staticCoderField the staticGson to set
- */
- public void setStaticCoderField(String staticCoderField) {
- this.staticCoderField = staticCoderField;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("CustomCoder [className=").append(className).append(", staticCoderField=")
- .append(staticCoderField).append("]");
- return builder.toString();
- }
- }
-
- public static class CustomGsonCoder extends CustomCoder {
-
- public CustomGsonCoder(String className, String staticCoderField) {
- super(className, staticCoderField);
- }
-
- public CustomGsonCoder(String customGson) {
- super(customGson);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]");
- return builder.toString();
- }
-
- }
-
- public static class CustomJacksonCoder extends CustomCoder {
-
- public CustomJacksonCoder(String className, String staticCoderField) {
- super(className, staticCoderField);
- }
-
- public CustomJacksonCoder(String customJackson) {
- super(customJackson);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]");
- return builder.toString();
- }
-
- }
-
- /**
- * Coder/Decoder class and Filter container. The decoder class is potential,
- * in order to be operational needs to be fetched from an available
- * class loader.
- *
- */
- public static class PotentialCoderFilter {
-
- /**
- * decoder class (pending from being able to be fetched and found
- * in some class loader)
- */
- protected String codedClass;
-
- /**
- * filters to apply to the selection of the decodedClass;
- */
- protected JsonProtocolFilter filter;
-
- /**
- * constructor
- *
- * @param codedClass decoder class
- * @param filter filters to apply
- */
- public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) {
- this.codedClass = codedClass;
- this.filter = filter;
- }
-
- /**
- * @return the decodedClass
- */
- public String getCodedClass() {
- return codedClass;
- }
-
- /**
- * @param decodedClass the decodedClass to set
- */
- public void setCodedClass(String decodedClass) {
- this.codedClass = decodedClass;
- }
-
- /**
- * @return the filter
- */
- public JsonProtocolFilter getFilter() {
- return filter;
- }
-
- /**
- * @param filter the filter to set
- */
- public void setFilter(JsonProtocolFilter filter) {
- this.filter = filter;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("PotentialCoderFilter [codedClass=").append(codedClass).append(", filter=").append(filter)
- .append("]");
- return builder.toString();
- }
- }
-
- /**
- * the source topic
- */
- protected final String topic;
-
- /**
- * List of decoder -> filters
- */
- protected final List<PotentialCoderFilter> coderFilters;
-
- /**
- * custom gson coder that this controller prefers to use instead of the framework ones
- */
- protected CustomGsonCoder customGsonCoder;
-
- /**
- * custom jackson coder that this controller prefers to use instead of the framework ones
- */
- protected CustomJacksonCoder customJacksonCoder;
-
- /**
- * Constructor
- *
- * @param decoderFilters list of decoders and associated filters
- * @param topic the topic
- */
- public TopicCoderFilterConfiguration(String topic, List<PotentialCoderFilter> decoderFilters,
- CustomGsonCoder customGsonCoder,
- CustomJacksonCoder customJacksonCoder) {
- this.coderFilters = decoderFilters;
- this.topic = topic;
- this.customGsonCoder = customGsonCoder;
- this.customJacksonCoder = customJacksonCoder;
- }
-
- /**
- * @return the topic
- */
- public String getTopic() {
- return topic;
- }
-
- /**
- * @return the decoderFilters
- */
- public List<PotentialCoderFilter> getCoderFilters() {
- return coderFilters;
- }
-
- /**
- * @return the customGsonCoder
- */
- public CustomGsonCoder getCustomGsonCoder() {
- return customGsonCoder;
- }
-
- /**
- * @param customGsonCoder the customGsonCoder to set
- */
- public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
- this.customGsonCoder = customGsonCoder;
- }
-
- /**
- * @return the customJacksonCoder
- */
- public CustomJacksonCoder getCustomJacksonCoder() {
- return customJacksonCoder;
- }
-
- /**
- * @param customJacksonCoder the customJacksonCoder to set
- */
- public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) {
- this.customJacksonCoder = customJacksonCoder;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("TopicCoderFilterConfiguration [topic=").append(topic).append(", coderFilters=")
- .append(coderFilters).append(", customGsonCoder=").append(customGsonCoder)
- .append(", customJacksonCoder=").append(customJacksonCoder).append("]");
- return builder.toString();
- }
+ /**
+ * Custom coder, contains class and static field to access parser that the controller desires to
+ * use instead of the framework provided parser.
+ */
+ public abstract static class CustomCoder {
+ protected String className;
+ protected String staticCoderField;
+ /**
+ * create custom coder from raw string in the following format (typically embedded in a property
+ * file):
+ *
+ * <p>Note this is to support decoding/encoding of partial structures that are only known by the
+ * model.
+ *
+ * @param rawCustomCoder with format: &lt;class-containing-custom-coder&gt;,&lt;static-coder-field&gt.
+ */
+ public CustomCoder(String rawCustomCoder) {
+ if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
+ this.className = rawCustomCoder.substring(0, rawCustomCoder.indexOf(","));
+ if (this.className == null || this.className.isEmpty()) {
+ throw new IllegalArgumentException(
+ "No classname to create CustomCoder cannot be created");
+ }
+
+ this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",") + 1);
+ if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
+ throw new IllegalArgumentException(
+ "No staticCoderField to create CustomCoder cannot be created for class " + className);
+ }
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param className class name
+ * @param staticCoderField static coder field
+ */
+ public CustomCoder(String className, String staticCoderField) {
+ if (className == null || className.isEmpty()) {
+ throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
+ }
+
+ if (staticCoderField == null || staticCoderField.isEmpty()) {
+ throw new IllegalArgumentException(
+ "No staticCoderField to create CustomCoder cannot be created for class " + className);
+ }
+
+ this.className = className;
+ this.staticCoderField = staticCoderField;
+ }
+
+ /**
+ * Get class container.
+ *
+ * @return the className
+ **/
+ public String getClassContainer() {
+ return className;
+ }
+
+ /**
+ * Set class container.
+ *
+ * @param className the className to set
+ **/
+ public void setClassContainer(String className) {
+ this.className = className;
+ }
+
+ /**
+ * Get static coder field.
+ *
+ * @return the staticCoderField
+ **/
+ public String getStaticCoderField() {
+ return staticCoderField;
+ }
+
+ /**
+ * Set static coder field.
+ *
+ * @param staticCoderField the staticGson to set
+ **/
+ public void setStaticCoderField(String staticCoderField) {
+ this.staticCoderField = staticCoderField;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder
+ .append("CustomCoder [className=")
+ .append(className)
+ .append(", staticCoderField=")
+ .append(staticCoderField)
+ .append("]");
+ return builder.toString();
+ }
+ }
+
+ public static class CustomGsonCoder extends CustomCoder {
+
+ public CustomGsonCoder(String className, String staticCoderField) {
+ super(className, staticCoderField);
+ }
+
+ public CustomGsonCoder(String customGson) {
+ super(customGson);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]");
+ return builder.toString();
+ }
+ }
+
+ public static class CustomJacksonCoder extends CustomCoder {
+
+ public CustomJacksonCoder(String className, String staticCoderField) {
+ super(className, staticCoderField);
+ }
+
+ public CustomJacksonCoder(String customJackson) {
+ super(customJackson);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]");
+ return builder.toString();
+ }
+ }
+
+ /**
+ * Coder/Decoder class and Filter container. The decoder class is potential, in order to be
+ * operational needs to be fetched from an available class loader.
+ */
+ public static class PotentialCoderFilter {
+
+ /* decoder class (pending from being able to be fetched and found in some class loader) */
+ protected String codedClass;
+
+ /* filters to apply to the selection of the decodedClass; */
+ protected JsonProtocolFilter filter;
+
+ /**
+ * constructor.
+ *
+ * @param codedClass decoder class
+ * @param filter filters to apply
+ */
+ public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) {
+ this.codedClass = codedClass;
+ this.filter = filter;
+ }
+
+ /**
+ * Get coded class.
+ *
+ * @return the decodedClass
+ **/
+ public String getCodedClass() {
+ return codedClass;
+ }
+
+ /** Set coded class.
+ *
+ * @param decodedClass the decodedClass to set
+ **/
+ public void setCodedClass(String decodedClass) {
+ this.codedClass = decodedClass;
+ }
+
+ /**
+ * Get filter.
+ *
+ * @return the filter
+ **/
+ public JsonProtocolFilter getFilter() {
+ return filter;
+ }
+
+ /**
+ * Set filter.
+ *
+ * @param filter the filter to set
+ **/
+ public void setFilter(JsonProtocolFilter filter) {
+ this.filter = filter;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder
+ .append("PotentialCoderFilter [codedClass=")
+ .append(codedClass)
+ .append(", filter=")
+ .append(filter)
+ .append("]");
+ return builder.toString();
+ }
+ }
+
+ /* the source topic */
+ protected final String topic;
+
+ /* List of decoder -> filters */
+ protected final List<PotentialCoderFilter> coderFilters;
+
+ /* custom gson coder that this controller prefers to use instead of the framework ones */
+ protected CustomGsonCoder customGsonCoder;
+
+ /* custom jackson coder that this controller prefers to use instead of the framework ones */
+ protected CustomJacksonCoder customJacksonCoder;
+
+ /**
+ * Constructor.
+ *
+ * @param decoderFilters list of decoders and associated filters
+ * @param topic the topic
+ */
+ public TopicCoderFilterConfiguration(
+ String topic,
+ List<PotentialCoderFilter> decoderFilters,
+ CustomGsonCoder customGsonCoder,
+ CustomJacksonCoder customJacksonCoder) {
+ this.coderFilters = decoderFilters;
+ this.topic = topic;
+ this.customGsonCoder = customGsonCoder;
+ this.customJacksonCoder = customJacksonCoder;
+ }
+
+ /**
+ * Get topic.
+ * @return the topic
+ **/
+ public String getTopic() {
+ return topic;
+ }
+
+ /** Get coder filters.
+ *
+ * @return the decoderFilters
+ **/
+ public List<PotentialCoderFilter> getCoderFilters() {
+ return coderFilters;
+ }
+
+ /**
+ * Get custom gson coder.
+ *
+ * @return the customGsonCoder
+ **/
+ public CustomGsonCoder getCustomGsonCoder() {
+ return customGsonCoder;
+ }
+
+ /**
+ * Set custom gson coder.
+ *
+ * @param customGsonCoder the customGsonCoder to set
+ **/
+ public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
+ this.customGsonCoder = customGsonCoder;
+ }
+
+ /** Get custom jackson coder.
+ *
+ * @return the customJacksonCoder
+ **/
+ public CustomJacksonCoder getCustomJacksonCoder() {
+ return customJacksonCoder;
+ }
+
+ /**
+ * Set custom Jackson coder.
+ * @param customJacksonCoder the customJacksonCoder to set
+ **/
+ public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) {
+ this.customJacksonCoder = customJacksonCoder;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder
+ .append("TopicCoderFilterConfiguration [topic=")
+ .append(topic)
+ .append(", coderFilters=")
+ .append(coderFilters)
+ .append(", customGsonCoder=")
+ .append(customGsonCoder)
+ .append(", customJacksonCoder=")
+ .append(customJacksonCoder)
+ .append("]");
+ return builder.toString();
+ }
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
index 62b66611..69e13b43 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
@@ -20,6 +20,12 @@
package org.onap.policy.drools.protocol.configuration;
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
import java.util.HashMap;
import java.util.Map;
@@ -27,41 +33,34 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
/**
- * Drools Related Information
+ * Drools Related Information.
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ControllerConfiguration {
- public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
- public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update";
- public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
- public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
-
+ public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
+ public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update";
+ public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
+ public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
+
/**
- *
- * (Required)
+ * (Required).
*
*/
@JsonProperty("name")
private String name;
/**
* Set of operations that can be applied to a controller: create, lock
- * (Required)
+ * (Required).
*
*/
@JsonProperty("operation")
private String operation;
/**
- * Maven Related Information
+ * Maven Related Information.
*
*/
@JsonProperty("drools")
@@ -71,18 +70,19 @@ public class ControllerConfiguration {
protected static final Object NOT_FOUND_VALUE = new Object();
/**
- * No args constructor for use in serialization
+ * No args constructor for use in serialization.
*
*/
public ControllerConfiguration() {
- // Empty
+ // Empty
}
/**
+ * Constructor.
*
- * @param name
- * @param drools
- * @param operation
+ * @param name name
+ * @param operation operation
+ * @param drools drools
*/
public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
this.name = name;
@@ -91,8 +91,7 @@ public class ControllerConfiguration {
}
/**
- *
- * (Required)
+ * (Required).
*
* @return
* The name
@@ -103,8 +102,7 @@ public class ControllerConfiguration {
}
/**
- *
- * (Required)
+ * (Required).
*
* @param name
* The name
@@ -121,7 +119,7 @@ public class ControllerConfiguration {
/**
* Set of operations that can be applied to a controller: create, lock
- * (Required)
+ * (Required).
*
* @return
* The operation
@@ -133,7 +131,7 @@ public class ControllerConfiguration {
/**
* Set of operations that can be applied to a controller: create, lock
- * (Required)
+ * (Required).
*
* @param operation
* The operation
@@ -149,7 +147,7 @@ public class ControllerConfiguration {
}
/**
- * Maven Related Information
+ * Maven Related Information.
*
* @return
* The drools
@@ -160,7 +158,7 @@ public class ControllerConfiguration {
}
/**
- * Maven Related Information
+ * Maven Related Information.
*
* @param drools
* The drools
@@ -224,24 +222,43 @@ public class ControllerConfiguration {
}
}
+ /**
+ * Get.
+ *
+ * @param name name
+ * @return the object
+ */
@SuppressWarnings({
"unchecked"
- })
- public<T >T get(String name) {
+ })
+ public <T> T get(String name) {
Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
- if (ControllerConfiguration.NOT_FOUND_VALUE!= value) {
+ if (ControllerConfiguration.NOT_FOUND_VALUE != value) {
return ((T) value);
} else {
return ((T) getAdditionalProperties().get(name));
}
}
+ /**
+ * Set the property.
+ *
+ * @param name property name
+ * @param value property value
+ */
public void set(String name, Object value) {
if (!declaredProperty(name, value)) {
getAdditionalProperties().put(name, (Object) value);
}
}
+ /**
+ * With - sets the property and additionally returns the object.
+ *
+ * @param name property name
+ * @param value property value
+ * @return this
+ */
public ControllerConfiguration with(String name, Object value) {
if (!declaredProperty(name, value)) {
getAdditionalProperties().put(name, (Object) value);
@@ -251,7 +268,8 @@ public class ControllerConfiguration {
@Override
public int hashCode() {
- return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties).toHashCode();
+ return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties)
+ .toHashCode();
}
@Override
@@ -263,30 +281,50 @@ public class ControllerConfiguration {
return false;
}
ControllerConfiguration rhs = ((ControllerConfiguration) other);
- return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals();
+ return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools)
+ .append(additionalProperties, rhs.additionalProperties).isEquals();
}
+ /**
+ * Call set name.
+ *
+ * @param value value
+ */
public void callSetName(Object value) {
if (value instanceof String) {
setName((String) value);
} else {
- throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
+ throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "
+ + value.getClass().toString());
}
}
+ /**
+ * Call set operation.
+ *
+ * @param value value
+ */
public void callSetOperation(Object value) {
if (value instanceof String) {
setOperation((String) value);
} else {
- throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
+ throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "
+ + value.getClass().toString());
}
}
+ /**
+ * Call set drools.
+ *
+ * @param value value
+ */
public void callSetDrools(Object value) {
if (value instanceof DroolsConfiguration) {
setDrools((DroolsConfiguration) value);
} else {
- throw new IllegalArgumentException("property \"drools\" is of type \"org.onap.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString());
+ throw new IllegalArgumentException("property \"drools\" is of type"
+ + "\"org.onap.policy.drools.protocol.configuration.Drools\", but got "
+ + value.getClass().toString());
}
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java
index cac4f565..e1f7f63a 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java
@@ -20,22 +20,21 @@
package org.onap.policy.drools.protocol.configuration;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
/**
- * Maven Related Information
+ * Maven Related Information.
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -43,21 +42,23 @@ public class DroolsConfiguration {
/**
* Maven Artifact ID
- * (Required)
+ * (Required).
*
*/
@JsonProperty("artifactId")
private String artifactId;
+
/**
* Maven Group ID
- * (Required)
+ * (Required).
*
*/
@JsonProperty("groupId")
private String groupId;
+
/**
* Maven Version
- * (Required)
+ * (Required).
*
*/
@JsonProperty("version")
@@ -67,18 +68,19 @@ public class DroolsConfiguration {
protected static final Object NOT_FOUND_VALUE = new Object();
/**
- * No args constructor for use in serialization
+ * No args constructor for use in serialization.
*
*/
public DroolsConfiguration() {
- // Empty
+ // Empty
}
/**
+ * Constructor.
*
- * @param groupId
- * @param artifactId
- * @param version
+ * @param groupId group id
+ * @param artifactId artifact id
+ * @param version version
*/
public DroolsConfiguration(String artifactId, String groupId, String version) {
this.artifactId = artifactId;
@@ -88,7 +90,7 @@ public class DroolsConfiguration {
/**
* Maven Artifact ID
- * (Required)
+ * (Required).
*
* @return
* The artifactId
@@ -100,7 +102,7 @@ public class DroolsConfiguration {
/**
* Maven Artifact ID
- * (Required)
+ * (Required).
*
* @param artifactId
* The artifactId
@@ -117,7 +119,7 @@ public class DroolsConfiguration {
/**
* Maven Group ID
- * (Required)
+ * (Required).
*
* @return
* The groupId
@@ -129,7 +131,7 @@ public class DroolsConfiguration {
/**
* Maven Group ID
- * (Required)
+ * (Required).
*
* @param groupId
* The groupId
@@ -146,7 +148,7 @@ public class DroolsConfiguration {
/**
* Maven Version
- * (Required)
+ * (Required).
*
* @return
* The version
@@ -158,7 +160,7 @@ public class DroolsConfiguration {
/**
* Maven Version
- * (Required)
+ * (Required).
*
* @param version
* The version
@@ -222,24 +224,43 @@ public class DroolsConfiguration {
}
}
+ /**
+ * Get declared property.
+ *
+ * @param name property name
+ * @return the property object
+ */
@SuppressWarnings({
"unchecked"
- })
- public<T >T get(String name) {
+ })
+ public <T> T get(String name) {
Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
- if (DroolsConfiguration.NOT_FOUND_VALUE!= value) {
+ if (DroolsConfiguration.NOT_FOUND_VALUE != value) {
return (T) value;
} else {
return (T) getAdditionalProperties().get(name);
}
}
+ /**
+ * Set property value.
+ *
+ * @param name property name
+ * @param value property value
+ */
public void set(String name, Object value) {
if (!declaredProperty(name, value)) {
getAdditionalProperties().put(name, value);
}
}
+ /**
+ * Set property value and return object.
+ *
+ * @param name property name
+ * @param value property value
+ * @return this
+ */
public DroolsConfiguration with(String name, Object value) {
if (!declaredProperty(name, value)) {
getAdditionalProperties().put(name, value);
@@ -249,7 +270,8 @@ public class DroolsConfiguration {
@Override
public int hashCode() {
- return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties).toHashCode();
+ return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties)
+ .toHashCode();
}
@Override
@@ -261,30 +283,50 @@ public class DroolsConfiguration {
return false;
}
DroolsConfiguration rhs = ((DroolsConfiguration) other);
- return new EqualsBuilder().append(artifactId, rhs.artifactId).append(groupId, rhs.groupId).append(version, rhs.version).append(additionalProperties, rhs.additionalProperties).isEquals();
+ return new EqualsBuilder().append(artifactId, rhs.artifactId)
+ .append(groupId, rhs.groupId).append(version, rhs.version)
+ .append(additionalProperties, rhs.additionalProperties).isEquals();
}
+ /**
+ * Call set artifact id.
+ *
+ * @param value id
+ */
public void callSetArtifactId(Object value) {
if (value instanceof String) {
setArtifactId((String) value);
} else {
- throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
+ throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "
+ + value.getClass().toString());
}
}
+ /**
+ * Call set group id.
+ *
+ * @param value id
+ */
public void callSetGroupId(Object value) {
if (value instanceof String) {
setGroupId((String) value);
} else {
- throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
+ throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "
+ + value.getClass().toString());
}
}
+ /**
+ * Call set version.
+ *
+ * @param value version
+ */
public void callSetVersion(Object value) {
if (value instanceof String) {
setVersion((String) value);
} else {
- throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
+ throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "
+ + value.getClass().toString());
}
}
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java
index 29888bbb..58cd67fd 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java
@@ -20,84 +20,65 @@
package org.onap.policy.drools.protocol.configuration;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
/**
- * ENGINE-CONFIGURATION
- * <p>
- *
- *
+ * ENGINE-CONFIGURATION.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PdpdConfiguration {
-
- /**
- * Controller Entity ID
- */
- public static final String CONFIG_ENTITY_CONTROLLER = "controller";
- /**
- * Unique Transaction ID. This is an UUID.
- * (Required)
- *
- */
+ /** Controller Entity ID. */
+ public static final String CONFIG_ENTITY_CONTROLLER = "controller";
+
+ /** Unique Transaction ID. This is an UUID. (Required) */
@JsonProperty("requestID")
private String requestID;
- /**
- * Set of entities on which configuration can be performed: controller
- * (Required)
- *
- */
+ /* Set of entities on which configuration can be performed: controller (Required) */
@JsonProperty("entity")
private String entity;
- /**
- * Controller Information, only applicable when the entity is set to controller
- *
- */
+ /* Controller Information, only applicable when the entity is set to controller */
@JsonProperty("controllers")
private List<ControllerConfiguration> controllers = new ArrayList<>();
- @JsonIgnore
- private Map<String, Object> additionalProperties = new HashMap<>();
+
+ @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
protected static final Object NOT_FOUND_VALUE = new Object();
- /**
- * No args constructor for use in serialization
- *
- */
+ /** No args constructor for use in serialization. */
public PdpdConfiguration() {
- // Empty
+ // Empty
}
/**
+ * Constructor.
*
- * @param controller
- * @param requestID
- * @param entity
+ * @param requestID request id
+ * @param entity entity
+ * @param controllers controllers
*/
- public PdpdConfiguration(String requestID, String entity, List<ControllerConfiguration> controllers) {
+ public PdpdConfiguration(
+ String requestID, String entity, List<ControllerConfiguration> controllers) {
this.requestID = requestID;
this.entity = entity;
this.controllers = controllers;
}
/**
- * Unique Transaction ID. This is an UUID.
- * (Required)
- *
- * @return
- * The requestID
+ * Unique Transaction ID. This is an UUID. (Required)
+ *
+ * @return The requestID
*/
@JsonProperty("requestID")
public String getRequestID() {
@@ -105,11 +86,9 @@ public class PdpdConfiguration {
}
/**
- * Unique Transaction ID. This is an UUID.
- * (Required)
- *
- * @param requestID
- * The requestID
+ * Unique Transaction ID. This is an UUID. (Required)
+ *
+ * @param requestID The requestID
*/
@JsonProperty("requestID")
public void setRequestID(String requestID) {
@@ -122,11 +101,9 @@ public class PdpdConfiguration {
}
/**
- * Set of entities on which configuration can be performed: controller
- * (Required)
- *
- * @return
- * The entity
+ * Set of entities on which configuration can be performed: controller (Required).
+ *
+ * @return The entity
*/
@JsonProperty("entity")
public String getEntity() {
@@ -134,11 +111,9 @@ public class PdpdConfiguration {
}
/**
- * Set of entities on which configuration can be performed: controller
- * (Required)
- *
- * @param entity
- * The entity
+ * Set of entities on which configuration can be performed: controller (Required).
+ *
+ * @param entity The entity
*/
@JsonProperty("entity")
public void setEntity(String entity) {
@@ -151,10 +126,9 @@ public class PdpdConfiguration {
}
/**
- * Controller Information, only applicable when the entity is set to controller
- *
- * @return
- * The controller
+ * Controller Information, only applicable when the entity is set to controller.
+ *
+ * @return The controller
*/
@JsonProperty("controller")
public List<ControllerConfiguration> getControllers() {
@@ -162,10 +136,9 @@ public class PdpdConfiguration {
}
/**
- * Controller Information, only applicable when the entity is set to controller
- *
- * @param controller
- * The controller
+ * Controller Information, only applicable when the entity is set to controller.
+ *
+ * @param controllers controllers
*/
@JsonProperty("controller")
public void setControllers(List<ControllerConfiguration> controllers) {
@@ -226,24 +199,37 @@ public class PdpdConfiguration {
}
}
- @SuppressWarnings({
- "unchecked"
- })
- public<T >T get(String name) {
+ /**
+ * Get.
+ *
+ * @param name name
+ * @return object
+ */
+ @SuppressWarnings({"unchecked"})
+ public <T> T get(String name) {
Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
- if (PdpdConfiguration.NOT_FOUND_VALUE!= value) {
+ if (PdpdConfiguration.NOT_FOUND_VALUE != value) {
return (T) value;
} else {
return (T) getAdditionalProperties().get(name);
}
}
+ /**
+ * Set property.
+ *
+ * @param name name
+ * @param value value
+ */
public void set(String name, Object value) {
if (!declaredProperty(name, value)) {
getAdditionalProperties().put(name, value);
}
}
+ /**
+ * With - sets and returns the object.
+ */
public PdpdConfiguration with(String name, Object value) {
if (!declaredProperty(name, value)) {
getAdditionalProperties().put(name, value);
@@ -253,7 +239,12 @@ public class PdpdConfiguration {
@Override
public int hashCode() {
- return new HashCodeBuilder().append(requestID).append(entity).append(controllers).append(additionalProperties).toHashCode();
+ return new HashCodeBuilder()
+ .append(requestID)
+ .append(entity)
+ .append(controllers)
+ .append(additionalProperties)
+ .toHashCode();
}
@Override
@@ -265,31 +256,59 @@ public class PdpdConfiguration {
return false;
}
PdpdConfiguration rhs = (PdpdConfiguration) other;
- return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals();
+ return new EqualsBuilder()
+ .append(requestID, rhs.requestID)
+ .append(entity, rhs.entity)
+ .append(controllers, rhs.controllers)
+ .append(additionalProperties, rhs.additionalProperties)
+ .isEquals();
}
-
+
+ /**
+ * Call set request id.
+ *
+ * @param value value
+ */
public void callSetRequestId(Object value) {
if (value instanceof String) {
setRequestID((String) value);
} else {
- throw new IllegalArgumentException("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
- }
+ throw new IllegalArgumentException(
+ "property \"requestID\" is of type \"java.lang.String\", but got "
+ + value.getClass().toString());
+ }
}
-
+
+ /**
+ * Call set entity.
+ *
+ * @param value value
+ */
public void callSetEntity(Object value) {
if (value instanceof String) {
setEntity((String) value);
} else {
- throw new IllegalArgumentException("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
- }
+ throw new IllegalArgumentException(
+ "property \"entity\" is of type \"java.lang.String\", but got "
+ + value.getClass().toString());
+ }
}
+ /**
+ * Call set controllers.
+ *
+ * @param value value
+ */
@SuppressWarnings("unchecked")
- public void callSetControllers(Object value) {
+ public void callSetControllers(Object value) {
if (value instanceof List) {
- setControllers((List<ControllerConfiguration> ) value);
+ setControllers((List<ControllerConfiguration>) value);
} else {
- throw new IllegalArgumentException("property \"controllers\" is of type \"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", but got "+ value.getClass().toString());
- }
+ throw new IllegalArgumentException(
+ "property \"controllers\" is of type "
+ + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "
+ + "but got "
+ + value.getClass().toString());
+ }
}
}
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 00da884e..64fd6823 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
@@ -21,7 +21,14 @@
package org.onap.policy.drools.server.restful;
import ch.qos.logback.classic.LoggerContext;
-
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Info;
+import io.swagger.annotations.SwaggerDefinition;
+import io.swagger.annotations.Tag;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -70,18 +77,9 @@ import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import io.swagger.annotations.Info;
-import io.swagger.annotations.SwaggerDefinition;
-import io.swagger.annotations.Tag;
-
/**
- * Telemetry JAX-RS Interface to the PDP-D
+ * Telemetry JAX-RS Interface to the PDP-D.
*/
@Path("/policy/pdp")
@@ -94,10 +92,15 @@ import io.swagger.annotations.Tag;
tags = {@Tag(name = "pdp-d-telemetry", description = "Drools PDP Telemetry Operations")})
public class RestManager {
/**
- * Logger
+ * Logger.
*/
private static Logger logger = LoggerFactory.getLogger(RestManager.class);
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine")
@ApiOperation(value = "Retrieves the Engine Operational Status",
@@ -106,6 +109,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine")
@ApiOperation(value = "Shuts down the Engine",
@@ -122,6 +130,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/features")
@ApiOperation(value = "Engine Features",
@@ -139,6 +152,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatureProviders()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/features/{featureName}")
@ApiOperation(value = "Engine Feature", notes = "Provides Details for a given feature Engine Provider",
@@ -155,6 +173,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/inputs")
@ApiOperation(value = "Engine Input Ports", notes = "List of input ports", responseContainer = "List")
@@ -162,6 +185,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(Arrays.asList(Inputs.values())).build();
}
+ /**
+ * POST.
+ *
+ * @return response object
+ */
@POST
@Path("engine/inputs/configuration")
@ApiOperation(value = "Engine Input Configuration Requests",
@@ -186,6 +214,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/properties")
@ApiOperation(value = "Engine Configuration Properties", notes = "Used for booststrapping the engine",
@@ -194,6 +227,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getProperties()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/environment")
@ApiOperation(value = "Engine Environment Properties",
@@ -202,6 +240,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getEnvironment()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/environment/{envProperty}")
@Consumes(MediaType.TEXT_PLAIN)
@@ -212,6 +255,11 @@ public class RestManager {
.build();
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/environment/{envProperty}")
@Consumes(MediaType.TEXT_PLAIN)
@@ -224,6 +272,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(previousValue).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/switches")
@ApiOperation(value = "Engine Control Switches", notes = "List of the Engine Control Switches",
@@ -232,6 +285,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/switches/activation")
@ApiOperation(value = "Switches on the Engine Activation Switch",
@@ -255,6 +313,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/switches/activation")
@ApiOperation(value = "Switches off Engine Activation Switch",
@@ -278,6 +341,11 @@ public class RestManager {
}
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/switches/lock")
@ApiOperation(value = "Switches on the Engine Lock Control",
@@ -294,6 +362,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/switches/lock")
@ApiOperation(value = "Switches off the Lock control",
@@ -310,6 +383,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers")
@ApiOperation(value = "Lists the Policy Controllers Names", notes = "Unique Policy Controller Identifiers",
@@ -318,6 +396,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllerIds()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/inventory")
@ApiOperation(value = "Lists the Policy Controllers", notes = "Detailed list of Policy Controllers",
@@ -326,6 +409,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllers()).build();
}
+ /**
+ * POST.
+ *
+ * @return response object
+ */
@POST
@Path("engine/controllers")
@ApiOperation(value = "Creates and starts a new Policy Controller",
@@ -389,6 +477,11 @@ public class RestManager {
return Response.status(Response.Status.CREATED).entity(controller).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/features")
@ApiOperation(value = "Lists of Feature Providers Identifiers", notes = "Unique Policy Controller Identifiers",
@@ -397,6 +490,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatures()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/features/inventory")
@ApiOperation(value = "Detailed Controllers Feature Inventory",
@@ -406,6 +504,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(PolicyController.factory.getFeatureProviders()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/features/{featureName}")
@ApiOperation(value = "Controller Feature",
@@ -423,6 +526,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}")
@ApiOperation(value = "Retrieves a Policy Controller",
@@ -447,6 +555,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/controllers/{controller}")
@ApiOperation(value = "Deletes a Policy Controller",
@@ -489,6 +602,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(controller).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/properties")
@ApiOperation(value = "Retrieves the configuration properties of a Policy Controller",
@@ -512,6 +630,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/inputs")
@ApiOperation(value = "Policy Controller Input Ports", notes = "List of input ports", responseContainer = "List")
@@ -519,6 +642,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(Arrays.asList(Inputs.values())).build();
}
+ /**
+ * POST.
+ *
+ * @return response object
+ */
@POST
@Path("engine/controllers/{controller}/inputs/configuration")
@ApiOperation(value = "Policy Controller Input Configuration Requests",
@@ -558,6 +686,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(controller).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/switches")
@ApiOperation(value = "Policy Controller Switches", notes = "List of the Policy Controller Switches",
@@ -566,6 +699,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/controllers/{controller}/switches/lock")
@ApiOperation(value = "Switches on the Policy Controller Lock Control",
@@ -584,6 +722,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/controllers/{controller}/switches/lock")
@ApiOperation(value = "Switches off the Policy Controller Lock Control",
@@ -602,6 +745,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/drools")
@ApiOperation(value = "Retrieves the Drools Controller subcomponent of the Policy Controller",
@@ -625,6 +773,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/drools/facts")
@ApiOperation(value = "Retrieves Facts Summary information for a given controller",
@@ -652,6 +805,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/drools/facts/{session}")
@ApiOperation(value = "Retrieves Fact Types (classnames) for a given controller and its count",
@@ -676,6 +834,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/drools/facts/{session}/{factType}")
@ApiOperation(
@@ -710,47 +873,16 @@ public class RestManager {
}
}
- @DELETE
- @Path("engine/controllers/{controller}/drools/facts/{session}/{factType}")
- @ApiOperation(
- value = "Deletes all the fact objects of a given type from the drools working memory"
- + "for a given controller and session. The objects retracted from the working "
- + "memory are provided in the response.",
- notes = "The fact types are the classnames of the objects inserted in the drools working memory",
- responseContainer = "List")
- @ApiResponses(value = {@ApiResponse(code = 404, message = "The controller, session, or fact type, cannot be found"),
- @ApiResponse(code = 406,
- message = "The system is an administrative state that prevents " + "this request to be fulfilled"),
- @ApiResponse(code = 500, message = "A server error has occurred processing this request")})
- public Response droolsFactsDelete(
- @ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName,
- @ApiParam(value = "Drools Session Name", required = true) @PathParam("session") String sessionName,
- @ApiParam(value = "Drools Fact Type", required = true) @PathParam("factType") String factType) {
- try {
- final DroolsController drools = this.getDroolsController(controllerName);
- 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,
- controllerName, sessionName, factType, e.getMessage(), e);
- return Response.status(Response.Status.NOT_FOUND)
- .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")).build();
- } catch (final IllegalStateException e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this,
- controllerName, sessionName, factType, e.getMessage(), e);
- return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")).build();
- } catch (final Exception e) {
- logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this,
- controllerName, sessionName, factType, e.getMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
- }
- }
-
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/drools/facts/{session}/{query}/{queriedEntity}")
@ApiOperation(
- value = "Gets all the fact objects returned by a DRL query with no parameters from the drools working memory"
+ value = "Gets all the fact objects returned by a DRL query with no parameters "
+ + "from the drools working memory"
+ "for a given controller and session",
notes = "The DRL query must be defined in the DRL file", responseContainer = "List")
@ApiResponses(value = {
@@ -794,6 +926,11 @@ public class RestManager {
}
}
+ /**
+ * POST.
+ *
+ * @return response object
+ */
@POST
@Path("engine/controllers/{controller}/drools/facts/{session}/{query}/{queriedEntity}")
@ApiOperation(
@@ -846,10 +983,58 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
+ @DELETE
+ @Path("engine/controllers/{controller}/drools/facts/{session}/{factType}")
+ @ApiOperation(
+ value = "Deletes all the fact objects of a given type from the drools working memory"
+ + "for a given controller and session. The objects retracted from the working "
+ + "memory are provided in the response.",
+ notes = "The fact types are the classnames of the objects inserted in the drools working memory",
+ responseContainer = "List")
+ @ApiResponses(value = {@ApiResponse(code = 404, message = "The controller, session, or fact type, cannot be found"),
+ @ApiResponse(code = 406,
+ message = "The system is an administrative state that prevents " + "this request to be fulfilled"),
+ @ApiResponse(code = 500, message = "A server error has occurred processing this request")})
+ public Response droolsFactsDelete(
+ @ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName,
+ @ApiParam(value = "Drools Session Name", required = true) @PathParam("session") String sessionName,
+ @ApiParam(value = "Drools Fact Type", required = true) @PathParam("factType") String factType) {
+ try {
+ final DroolsController drools = this.getDroolsController(controllerName);
+ 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,
+ controllerName, sessionName, factType, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")).build();
+ } catch (final IllegalStateException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this,
+ controllerName, sessionName, factType, e.getMessage(), e);
+ return Response.status(Response.Status.NOT_ACCEPTABLE)
+ .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")).build();
+ } catch (final Exception e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this,
+ controllerName, sessionName, factType, e.getMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
+ }
+ }
+
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/controllers/{controller}/drools/facts/{session}/{query}/{queriedEntity}")
@ApiOperation(
- value = "Deletes all the fact objects returned by a DRL query with parameters from the drools working memory"
+ value = "Deletes all the fact objects returned by a DRL query with parameters "
+ + "from the drools working memory "
+ "for a given controller and session",
notes = "The DRL query with parameters must be defined in the DRL file", responseContainer = "List")
@ApiResponses(value = {
@@ -898,6 +1083,11 @@ public class RestManager {
}
}
+ /**
+ * POST.
+ *
+ * @return response object
+ */
@POST
@Path("engine/controllers/tools/coders/decoders/filters/rules/{ruleName}")
@ApiOperation(value = "Produces a Decoder Rule Filter in a format that the Policy Controller can understand",
@@ -915,6 +1105,11 @@ public class RestManager {
return Response.status(Status.OK).entity(new JsonProtocolFilter.FilterRule(name, literalRegex)).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/decoders")
@ApiOperation(value = "Gets all the decoders used by a controller",
@@ -945,6 +1140,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/decoders/filters")
@ApiOperation(value = "Gets all the filters used by a controller",
@@ -976,6 +1176,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/decoders/{topic}")
@ApiOperation(value = "Gets all the decoders in use by a controller for a networked topic",
@@ -1008,6 +1213,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/decoders/{topic}/filters")
@ApiOperation(value = "Gets all filters attached to decoders for a given networked topic in use by a controller",
@@ -1046,6 +1256,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}")
@ApiOperation(
@@ -1086,6 +1301,11 @@ public class RestManager {
}
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}")
@ApiOperation(value = "Attaches filters to the decoder for a given networked topic " + "and fact type",
@@ -1137,6 +1357,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules")
@ApiOperation(value = "Gets the filter rules attached to a topic decoder of a controller",
@@ -1183,6 +1408,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules/{ruleName}")
@ApiOperation(value = "Gets a filter rule by name attached to a topic decoder of a controller",
@@ -1236,6 +1466,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules/{ruleName}")
@ApiOperation(value = "Deletes a filter rule by name attached to a topic decoder of a controller",
@@ -1303,6 +1538,11 @@ public class RestManager {
}
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules")
@ApiOperation(value = "Places a new filter rule in a topic decoder",
@@ -1347,19 +1587,26 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(filter.getRules()).build();
} catch (final IllegalArgumentException e) {
logger.debug(
- "{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}",
- this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
+ "{}: cannot access decoder filter rules for policy-controller {} "
+ + "topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND)
.entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")).build();
} catch (final IllegalStateException e) {
logger.debug(
- "{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}",
- this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
+ "{}: cannot access decoder filter rules for policy-controller {} "
+ + "topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build();
}
}
+ /**
+ * POST.
+ *
+ * @return response object
+ */
@POST
@Path("engine/controllers/{controller}/decoders/{topic}")
@Consumes(MediaType.TEXT_PLAIN)
@@ -1416,6 +1663,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(result).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/controllers/{controller}/encoders")
@ApiOperation(value = "Retrieves the encoder filters of a controller",
@@ -1461,6 +1713,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/topics/switches/lock")
@ApiOperation(value = "Locks all the managed topics", notes = "The operation affects all managed sources and sinks",
@@ -1476,6 +1733,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/topics/switches/lock")
@ApiOperation(value = "Unlocks all the managed topics",
@@ -1491,6 +1753,11 @@ public class RestManager {
}
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources")
@ApiOperation(value = "Retrieves the managed topic sources", notes = "Network Topic Sources Agregation",
@@ -1499,6 +1766,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getTopicSources()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks")
@ApiOperation(value = "Retrieves the managed topic sinks", notes = "Network Topic Sinks Agregation",
@@ -1507,6 +1779,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getTopicSinks()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/ueb")
@ApiOperation(value = "Retrieves the UEB managed topic sources", notes = "UEB Topic Sources Agregation",
@@ -1515,6 +1792,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getUebTopicSources()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/ueb")
@ApiOperation(value = "Retrieves the UEB managed topic sinks", notes = "UEB Topic Sinks Agregation",
@@ -1523,6 +1805,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getUebTopicSinks()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/dmaap")
@ApiOperation(value = "Retrieves the DMaaP managed topic sources", notes = "DMaaP Topic Sources Agregation",
@@ -1531,6 +1818,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getDmaapTopicSources()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/dmaap")
@ApiOperation(value = "Retrieves the DMaaP managed topic sinks", notes = "DMaaP Topic Sinks Agregation",
@@ -1539,6 +1831,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getDmaapTopicSinks()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/ueb/{topic}")
@ApiOperation(value = "Retrieves an UEB managed topic source",
@@ -1548,6 +1845,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getUebTopicSource(topic)).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/ueb/{topic}")
@ApiOperation(value = "Retrieves an UEB managed topic sink",
@@ -1557,6 +1859,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getUebTopicSink(topic)).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/dmaap/{topic}")
@ApiOperation(value = "Retrieves a DMaaP managed topic source",
@@ -1567,6 +1874,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getDmaapTopicSource(topic)).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/dmaap/{topic}")
@ApiOperation(value = "Retrieves a DMaaP managed topic sink",
@@ -1576,6 +1888,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getDmaapTopicSink(topic)).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/ueb/{topic}/events")
@ApiOperation(value = "Retrieves the latest events received by an UEB topic",
@@ -1586,6 +1903,11 @@ public class RestManager {
.entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSource(topic).getRecentEvents())).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/ueb/{topic}/events")
@ApiOperation(value = "Retrieves the latest events sent from a topic",
@@ -1596,6 +1918,11 @@ public class RestManager {
.entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSink(topic).getRecentEvents())).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/dmaap/{topic}/events")
@ApiOperation(value = "Retrieves the latest events received by a DMaaP topic",
@@ -1607,6 +1934,11 @@ public class RestManager {
.entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSource(topic).getRecentEvents())).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/dmaap/{topic}/events")
@ApiOperation(value = "Retrieves the latest events send through a DMaaP topic",
@@ -1617,6 +1949,11 @@ public class RestManager {
.entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSink(topic).getRecentEvents())).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/noop")
@ApiOperation(value = "Retrieves the NOOP managed topic sinks", notes = "NOOP Topic Sinks Agregation",
@@ -1625,6 +1962,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getNoopTopicSinks()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/noop/{topic}")
@ApiOperation(value = "Retrieves a NOOP managed topic sink",
@@ -1633,6 +1975,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getNoopTopicSink(topic)).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sinks/noop/{topic}/events")
@ApiOperation(value = "Retrieves the latest events send through a NOOP topic",
@@ -1642,6 +1989,11 @@ public class RestManager {
.entity(Arrays.asList(TopicEndpoint.manager.getNoopTopicSink(topic).getRecentEvents())).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/ueb/{topic}/switches")
@ApiOperation(value = "UEB Topic Control Switches", notes = "List of the UEB Topic Control Switches",
@@ -1650,6 +2002,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/topics/sources/ueb/{topic}/switches/lock")
@ApiOperation(value = "Locks an UEB Source topic", response = UebTopicSource.class)
@@ -1665,6 +2022,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/topics/sources/ueb/{topic}/switches/lock")
@ApiOperation(value = "Unlocks an UEB Source topic", response = UebTopicSource.class)
@@ -1684,6 +2046,11 @@ public class RestManager {
return new Error("cannot perform operation on " + topic);
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/topics/sources/dmaap/{topic}/switches")
@ApiOperation(value = "DMaaP Topic Control Switches", notes = "List of the DMaaP Topic Control Switches",
@@ -1692,6 +2059,11 @@ public class RestManager {
return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build();
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/topics/sources/dmaap/{topic}/switches/lock")
@ApiOperation(value = "Locks an DMaaP Source topic", response = DmaapTopicSource.class)
@@ -1707,6 +2079,11 @@ public class RestManager {
}
}
+ /**
+ * DELETE.
+ *
+ * @return response object
+ */
@DELETE
@Path("engine/topics/sources/dmaap/{topic}/switches/lock")
@ApiOperation(value = "Unlocks an DMaaP Source topic", response = DmaapTopicSource.class)
@@ -1723,6 +2100,11 @@ public class RestManager {
}
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/topics/sources/ueb/{topic}/events")
@Consumes(MediaType.TEXT_PLAIN)
@@ -1762,6 +2144,11 @@ public class RestManager {
logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic, ex.getMessage(), ex);
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/topics/sources/dmaap/{topic}/events")
@Consumes(MediaType.TEXT_PLAIN)
@@ -1801,6 +2188,11 @@ public class RestManager {
logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic, ex.getMessage(), ex);
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/tools/uuid")
@ApiOperation(value = "Produces an UUID", notes = "UUID generation utility")
@@ -1809,6 +2201,11 @@ public class RestManager {
return Response.status(Status.OK).entity(UUID.randomUUID().toString()).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/tools/loggers")
@ApiOperation(value = "all active loggers", responseContainer = "List")
@@ -1828,6 +2225,11 @@ public class RestManager {
return Response.status(Status.OK).entity(names).build();
}
+ /**
+ * GET.
+ *
+ * @return response object
+ */
@GET
@Path("engine/tools/loggers/{logger}")
@Produces(MediaType.TEXT_PLAIN)
@@ -1851,6 +2253,11 @@ public class RestManager {
return Response.status(Status.OK).entity(loggerLevel).build();
}
+ /**
+ * PUT.
+ *
+ * @return response object
+ */
@PUT
@Path("engine/tools/loggers/{logger}/{level}")
@Produces(MediaType.TEXT_PLAIN)
@@ -1878,7 +2285,7 @@ public class RestManager {
}
/**
- * gets the underlying drools controller from the named policy controller
+ * gets the underlying drools controller from the named policy controller.
*
* @param controllerName the policy controller name
* @return the underlying drools controller
@@ -1910,22 +2317,22 @@ public class RestManager {
}
/**
- * Coding/Encoding Results Aggregation Helper class
+ * Coding/Encoding Results Aggregation Helper class.
*/
public static class CodingResult {
/**
- * serialized output
+ * serialized output.
*/
private String jsonEncoding;
/**
- * encoding result
+ * encoding result.
*/
private Boolean encoding;
/**
- * decoding result
+ * decoding result.
*/
private Boolean decoding;
@@ -1955,7 +2362,7 @@ public class RestManager {
}
/**
- * Generic Error Reporting class
+ * Generic Error Reporting class.
*/
public static class Error {
private String msg;
@@ -1974,14 +2381,14 @@ public class RestManager {
}
/**
- * Feed Ports into Resources
+ * Feed Ports into Resources.
*/
public enum Inputs {
configuration,
}
/**
- * Resource Toggles
+ * 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 0c8465a7..955fb242 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
@@ -24,12 +24,12 @@ import org.onap.policy.common.endpoints.http.server.aaf.AafAuthFilter;
import org.onap.policy.drools.system.PolicyEngine;
/**
- * AAF Base Class
+ * AAF Base Class.
*/
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
- (AAF_ROOT_PERMISSION_PROPERTY, DEFAULT_NAMESPACE + "." + AAF_NODETYPE);
+ PolicyEngine.manager.getProperties().getProperty(
+ AAF_ROOT_PERMISSION_PROPERTY, DEFAULT_NAMESPACE + "." + AAF_NODETYPE);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafTelemetryAuthFilter.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafTelemetryAuthFilter.java
index f2e50ee2..f76b3de2 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafTelemetryAuthFilter.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/aaf/AafTelemetryAuthFilter.java
@@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest;
import org.onap.policy.common.utils.network.NetworkUtil;
/**
- * AAF Telemetry Authorization
+ * AAF Telemetry Authorization.
*/
public class AafTelemetryAuthFilter extends AafBase {
private static final String RESOURCE_TYPE = AAF_ROOT_PERMISSION + "." + "telemetry";
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 c8956839..79268b2c 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
@@ -32,130 +32,167 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Programmatic entry point to the management layer
+ * Programmatic entry point to the management layer.
*/
public class Main {
- /**
- * logback configuration file system property
- */
- public static final String LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY =
- "logback.configurationFile";
-
- /**
- * logback configuration file system property
- */
- public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "config/logback.xml";
-
- /**
- * constructor (hides public default one)
- */
- private Main() {}
-
- /**
- * main
- *
- * @param args program arguments
- */
- public static void main(String[] args) {
-
- /* logging defaults */
-
- if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) {
- if (Files.exists(Paths.get(LOGBACK_CONFIGURATION_FILE_DEFAULT))) {
- System.setProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
- LOGBACK_CONFIGURATION_FILE_DEFAULT);
- } else {
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, ch.qos.logback.classic.Level.INFO.toString());
- }
+ /** logback configuration file system property. */
+ public static final String LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY =
+ "logback.configurationFile";
+
+ /** logback configuration file system property. */
+ public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "config/logback.xml";
+
+ /** constructor (hides public default one). */
+ private Main() {}
+
+ /**
+ * main.
+ *
+ * @param args program arguments.
+ */
+ public static void main(String[] args) {
+
+ /* logging defaults */
+
+ if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) {
+ if (Files.exists(Paths.get(LOGBACK_CONFIGURATION_FILE_DEFAULT))) {
+ System.setProperty(
+ LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, LOGBACK_CONFIGURATION_FILE_DEFAULT);
+ } else {
+ LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, ch.qos.logback.classic.Level.INFO.toString());
+ }
+ }
+
+ /* make sure the default configuration directory is properly set up */
+
+ SystemPersistence.manager.setConfigurationDir(null);
+
+ /* logging defaults */
+
+ if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) {
+ if (Files.exists(Paths.get(LOGBACK_CONFIGURATION_FILE_DEFAULT))) {
+ System.setProperty(
+ LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, LOGBACK_CONFIGURATION_FILE_DEFAULT);
+ } else {
+ LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, ch.qos.logback.classic.Level.INFO.toString());
+ }
+ }
+
+ /* 0. boot */
+
+ PolicyEngine.manager.boot(args);
+
+ /* start logger */
+
+ final Logger logger = LoggerFactory.getLogger(Main.class);
+
+ /* 1.a. Configure the Engine */
+
+ Properties engineProperties = SystemPersistence.manager.getEngineProperties();
+ if (engineProperties == null) {
+ engineProperties = PolicyEngine.manager.defaultTelemetryConfig();
+ }
+
+ PolicyEngine.manager.configure(engineProperties);
+
+ /* 1.b. Load Installation Environment(s) */
+
+ for (final Properties env : SystemPersistence.manager.getEnvironmentProperties()) {
+ PolicyEngine.manager.setEnvironment(env);
+ }
+
+ /* 2. Start the Engine with the basic services only (no Policy Controllers) */
+
+ MDCTransaction trans =
+ MDCTransaction.newTransaction(null, null)
+ .setServiceName(Main.class.getSimpleName())
+ .setTargetEntity("engine")
+ .setTargetServiceName("start");
+ try {
+ final boolean success = PolicyEngine.manager.start();
+ if (!success) {
+ trans.setStatusCode(false).setResponseDescription("partial start").flush();
+ logger.warn(
+ LoggerUtil.TRANSACTION_LOG_MARKER,
+ "Main: {} has been partially started",
+ PolicyEngine.manager);
+ } else {
+ trans.setStatusCode(true).transaction();
+ }
+ } catch (final IllegalStateException e) {
+ trans
+ .setStatusCode(false)
+ .setResponseCode(e.getClass().getSimpleName())
+ .setResponseDescription(e.getMessage())
+ .flush();
+ logger.warn(
+ LoggerUtil.TRANSACTION_LOG_MARKER,
+ "Main: cannot start {} (bad state) because of {}",
+ PolicyEngine.manager,
+ e.getMessage(),
+ e);
+ } catch (final Exception e) {
+ trans
+ .setStatusCode(false)
+ .setResponseCode(e.getClass().getSimpleName())
+ .setResponseDescription(e.getMessage())
+ .flush();
+ logger.warn(
+ LoggerUtil.TRANSACTION_LOG_MARKER,
+ "Main: cannot start {} because of {}",
+ PolicyEngine.manager,
+ e.getMessage(),
+ e);
+ System.exit(1);
+ }
+
+ /* 3. Create and start the controllers */
+
+ for (final Properties controllerProperties :
+ SystemPersistence.manager.getControllerProperties()) {
+ final String controllerName =
+ controllerProperties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
+ try {
+ trans =
+ MDCTransaction.newTransaction(null, null)
+ .setServiceName(Main.class.getSimpleName())
+ .setTargetEntity("controller:" + controllerName)
+ .setTargetServiceName("start");
+
+ final PolicyController controller =
+ PolicyEngine.manager.createPolicyController(controllerName, controllerProperties);
+ controller.start();
+
+ trans
+ .setStatusCode(true)
+ .setResponseDescription(controller.getDrools().getCanonicalSessionNames().toString())
+ .transaction();
+ } catch (final Exception e) {
+ trans
+ .setStatusCode(false)
+ .setResponseCode(e.getClass().getSimpleName())
+ .setResponseDescription(e.getMessage())
+ .flush();
+ logger.error(
+ LoggerUtil.TRANSACTION_LOG_MARKER,
+ "Main: cannot instantiate policy-controller {} because of {}",
+ controllerName,
+ e.getMessage(),
+ e);
+ } catch (final LinkageError e) {
+ trans
+ .setStatusCode(false)
+ .setResponseCode(e.getClass().getSimpleName())
+ .setResponseDescription(e.getMessage())
+ .flush();
+ logger.warn(
+ LoggerUtil.TRANSACTION_LOG_MARKER,
+ "Main: cannot instantiate policy-controller {} (linkage) because of {}",
+ controllerName,
+ e.getMessage(),
+ e);
+ }
+ }
}
-
- /* make sure the default configuration directory is properly set up */
-
- SystemPersistence.manager.setConfigurationDir(null);
-
- /* logging defaults */
-
- if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) {
- if (Files.exists(Paths.get(LOGBACK_CONFIGURATION_FILE_DEFAULT))) {
- System.setProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
- LOGBACK_CONFIGURATION_FILE_DEFAULT);
- } else {
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, ch.qos.logback.classic.Level.INFO.toString());
- }
- }
-
- /* 0. boot */
-
- PolicyEngine.manager.boot(args);
-
- /* start logger */
-
- final Logger logger = LoggerFactory.getLogger(Main.class);
-
- /* 1.a. Configure the Engine */
-
- Properties engineProperties = SystemPersistence.manager.getEngineProperties();
- if (engineProperties == null)
- engineProperties = PolicyEngine.manager.defaultTelemetryConfig();
-
- PolicyEngine.manager.configure(engineProperties);
-
- /* 1.b. Load Installation Environment(s) */
-
- for (final Properties env : SystemPersistence.manager.getEnvironmentProperties()) {
- PolicyEngine.manager.setEnvironment(env);
- }
-
- /* 2. Start the Engine with the basic services only (no Policy Controllers) */
-
- MDCTransaction trans =
- MDCTransaction.newTransaction(null, null).setServiceName(Main.class.getSimpleName()).
- setTargetEntity("engine").setTargetServiceName("start");
- try {
- final boolean success = PolicyEngine.manager.start();
- if (!success) {
- trans.setStatusCode(false).setResponseDescription("partial start").flush();
- logger.warn(LoggerUtil.TRANSACTION_LOG_MARKER, "Main: {} has been partially started", PolicyEngine.manager);
- } else {
- trans.setStatusCode(true).transaction();
- }
- } catch (final IllegalStateException e) {
- trans.setStatusCode(false).setResponseCode(e.getClass().getSimpleName()).setResponseDescription(e.getMessage()).flush();
- logger.warn(LoggerUtil.TRANSACTION_LOG_MARKER, "Main: cannot start {} (bad state) because of {}", PolicyEngine.manager, e.getMessage(), e);
- } catch (final Exception e) {
- trans.setStatusCode(false).setResponseCode(e.getClass().getSimpleName()).setResponseDescription(e.getMessage()).flush();
- logger.warn(LoggerUtil.TRANSACTION_LOG_MARKER, "Main: cannot start {} because of {}", PolicyEngine.manager, e.getMessage(), e);
- System.exit(1);
- }
-
- /* 3. Create and start the controllers */
-
- for (final Properties controllerProperties : SystemPersistence.manager
- .getControllerProperties()) {
- final String controllerName =
- controllerProperties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
- try {
- trans =
- MDCTransaction.newTransaction(null, null).setServiceName(Main.class.getSimpleName()).
- setTargetEntity("controller:" + controllerName).setTargetServiceName("start");
-
- final PolicyController controller =
- PolicyEngine.manager.createPolicyController(controllerName, controllerProperties);
- controller.start();
-
- trans.setStatusCode(true).
- setResponseDescription(controller.getDrools().getCanonicalSessionNames().toString()).
- transaction();
- } catch (final Exception e) {
- trans.setStatusCode(false).setResponseCode(e.getClass().getSimpleName()).setResponseDescription(e.getMessage()).flush();
- logger.error(LoggerUtil.TRANSACTION_LOG_MARKER, "Main: cannot instantiate policy-controller {} because of {}",
- controllerName, e.getMessage(), e);
- } catch (final LinkageError e) {
- trans.setStatusCode(false).setResponseCode(e.getClass().getSimpleName()).setResponseDescription(e.getMessage()).flush();
- logger.warn(LoggerUtil.TRANSACTION_LOG_MARKER, "Main: cannot instantiate policy-controller {} (linkage) because of {}",
- controllerName, e.getMessage(), e);
- }
- }
- }
}
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 dcd4d11a..514dc364 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
@@ -23,9 +23,9 @@ package org.onap.policy.drools.system;
import java.util.List;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.capabilities.Lockable;
import org.onap.policy.common.capabilities.Startable;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.drools.controller.DroolsController;
@@ -41,32 +41,32 @@ import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
public interface PolicyController extends Startable, Lockable {
/**
- * Factory that tracks and manages Policy Controllers
+ * Factory that tracks and manages Policy Controllers.
*/
static PolicyControllerFactory factory = new IndexedPolicyControllerFactory();
/**
- * name of this Policy Controller
+ * name of this Policy Controller.
*/
String getName();
/**
- * Get the topic readers of interest for this controller
+ * Get the topic readers of interest for this controller.
*/
List<? extends TopicSource> getTopicSources();
/**
- * Get the topic readers of interest for this controller
+ * Get the topic readers of interest for this controller.
*/
List<? extends TopicSink> getTopicSinks();
/**
- * Get the Drools Controller
+ * Get the Drools Controller.
*/
DroolsController getDrools();
/**
- * update maven configuration
+ * update maven configuration.
*
* @param newDroolsConfiguration new drools configuration
* @return true if the update was successful, false otherwise
@@ -74,17 +74,16 @@ public interface PolicyController extends Startable, Lockable {
boolean updateDrools(DroolsConfiguration newDroolsConfiguration);
/**
- * Get the Properties
+ * Get the Properties.
*/
Properties getProperties();
/**
- * Attempts delivering of an String over communication infrastructure "busType"
+ * Attempts delivering of an String over communication infrastructure "busType".
*
- * @param event Communication infrastructure identifier
- * @param busType
+ * @param busType bus type
* @param topic topic
- * @param event the event object to send
+ * @param event Communication infrastructure identifier
*
* @return true if successful, false if a failure has occurred.
* @throws IllegalArgumentException when invalid or insufficient properties are provided
@@ -96,9 +95,9 @@ public interface PolicyController extends Startable, Lockable {
boolean deliver(CommInfrastructure busType, String topic, Object event);
/**
- * halts and permanently releases all resources
+ * halts and permanently releases all resources.
*
- * @throws IllegalStateException
+ * @throws IllegalStateException throws illegal state exception
*/
void halt();
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
index d8d4289f..1241acad 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
@@ -20,31 +20,32 @@
package org.onap.policy.drools.system;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
import org.onap.policy.drools.system.internal.AggregatedPolicyController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Policy Controller Factory to manage controller creation, destruction,
- * and retrieval for management interfaces
+ * and retrieval for management interfaces.
*/
public interface PolicyControllerFactory {
/**
- * Build a controller from a properties file
+ * Build a controller from a properties file.
*
* @param name the global name of this controller
* @param properties input parameters in form of properties for controller
- * initialization.
+ * initialization.
*
* @return a Policy Controller
*
@@ -55,8 +56,8 @@ public interface PolicyControllerFactory {
/**
* patches (updates) a controller from a critical configuration update.
*
- * @param name
- * @param configController
+ * @param name name
+ * @param configController config controller
*
* @return a Policy Controller
*/
@@ -65,27 +66,46 @@ public interface PolicyControllerFactory {
/**
* rebuilds (updates) a controller from a configuration update.
*
- * @param controller
- * @param configController
- *
- * @return a Policy Controller
+ * @param controller controller
+ * @param configController config controller
*/
void patch(PolicyController controller,
DroolsConfiguration configController);
/**
- * get PolicyController from DroolsController
+ * get PolicyController from DroolsController.
*
- * @param droolsController
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
+ * @param droolsController drools controller
+ * @return policy controller
+ * @throws IllegalArgumentException exception
+ * @throws IllegalStateException exception
*/
PolicyController get(DroolsController droolsController);
/**
+ * gets the Policy Controller identified by its name.
+ *
+ * @param policyControllerName name of policy controller
+ * @return policy controller object
+ * @throws IllegalArgumentException exception
+ * @throws IllegalStateException exception
+ */
+ PolicyController get(String policyControllerName);
+
+ /**
+ * gets the Policy Controller identified by group and artifact ids.
+ *
+ * @param groupId group id
+ * @param artifactId artifact id
+ * @return policy controller object
+ * @throws IllegalArgumentException exception
+ * @throws IllegalStateException exception
+ */
+ PolicyController get(String groupId, String artifactId);
+
+ /**
* Makes the Policy Controller identified by controllerName not operational, but
- * does not delete its associated data
+ * does not delete its associated data.
*
* @param controllerName name of the policy controller
* @throws IllegalArgumentException invalid arguments
@@ -94,7 +114,7 @@ public interface PolicyControllerFactory {
/**
* Makes the Policy Controller identified by controller not operational, but
- * does not delete its associated data
+ * does not delete its associated data.
*
* @param controller a Policy Controller
* @throws IllegalArgumentException invalid arguments
@@ -102,12 +122,12 @@ public interface PolicyControllerFactory {
void shutdown(PolicyController controller);
/**
- * Releases all Policy Controllers from operation
+ * Releases all Policy Controllers from operation.
*/
void shutdown();
/**
- * Destroys this Policy Controller
+ * Destroys this Policy Controller.
*
* @param controllerName name of the policy controller
* @throws IllegalArgumentException invalid arguments
@@ -115,7 +135,7 @@ public interface PolicyControllerFactory {
void destroy(String controllerName);
/**
- * Destroys this Policy Controller
+ * Destroys this Policy Controller.
*
* @param controller a Policy Controller
* @throws IllegalArgumentException invalid arguments
@@ -123,51 +143,33 @@ public interface PolicyControllerFactory {
void destroy(PolicyController controller);
/**
- * Releases all Policy Controller resources
+ * Releases all Policy Controller resources.
*/
void destroy();
/**
- * gets the Policy Controller identified by its name
- *
- * @param policyControllerName
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- */
- PolicyController get(String policyControllerName);
-
- /**
- * gets the Policy Controller identified by group and artifact ids
- *
- * @param groupId group id
- * @param artifactId artifact id
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- */
- PolicyController get(String groupId, String artifactId);
-
- /**
- * get features attached to the Policy Controllers
+ * get features attached to the Policy Controllers.
+ *
* @return list of features
*/
List<PolicyControllerFeatureAPI> getFeatureProviders();
/**
- * get named feature attached to the Policy Controllers
+ * get named feature attached to the Policy Controllers.
+ *
* @return the feature
*/
PolicyControllerFeatureAPI getFeatureProvider(String featureName);
/**
- * get features attached to the Policy Controllers
+ * get features attached to the Policy Controllers.
+ *
* @return list of features
*/
List<String> getFeatures();
/**
- * returns the current inventory of Policy Controllers
+ * returns the current inventory of Policy Controllers.
*
* @return a list of Policy Controllers
*/
@@ -175,26 +177,26 @@ public interface PolicyControllerFactory {
}
/**
- * Factory of Policy Controllers indexed by the name of the Policy Controller
+ * Factory of Policy Controllers indexed by the name of the Policy Controller.
*/
class IndexedPolicyControllerFactory implements PolicyControllerFactory {
// get an instance of logger
private static final Logger logger = LoggerFactory.getLogger(PolicyControllerFactory.class);
/**
- * Policy Controller Name Index
+ * Policy Controller Name Index.
*/
private final HashMap<String,PolicyController> policyControllers =
new HashMap<>();
/**
- * Group/Artifact Ids Index
+ * Group/Artifact Ids Index.
*/
private final HashMap<String,PolicyController> coordinates2Controller =
new HashMap<>();
/**
- * produces key for indexing controller names
+ * produces key for indexing controller names.
*
* @param groupId group id
* @param artifactId artifact id
@@ -205,7 +207,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public synchronized PolicyController build(String name, Properties properties) {
@@ -225,14 +227,15 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
this.policyControllers.put(name, controller);
- if (controller.getDrools().isBrained())
+ if (controller.getDrools().isBrained()) {
this.coordinates2Controller.put(coordinates, controller);
+ }
return controller;
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig) {
@@ -244,51 +247,55 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
PolicyController controller = this.get(name);
if (controller == null) {
- logger.warn("A POLICY CONTROLLER of name " + name +
- "does not exist for patch operation: " + droolsConfig);
+ logger.warn("A POLICY CONTROLLER of name {} does not exist for patch operation: {}", name, droolsConfig);
throw new IllegalArgumentException("Not a valid controller of name " + name);
}
this.patch(controller, droolsConfig);
- if (logger.isInfoEnabled())
- logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this);
+ if (logger.isInfoEnabled()) {
+ logger.info("UPDATED drools configuration: {} on {}", droolsConfig, this);
+ }
return controller;
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void patch(PolicyController controller, DroolsConfiguration droolsConfig) {
- if (controller == null)
+ if (controller == null) {
throw new IllegalArgumentException("Not a valid controller: null");
+ }
- if (droolsConfig == null)
+ if (droolsConfig == null) {
throw new IllegalArgumentException("Invalid Drools Configuration");
+ }
if (!controller.updateDrools(droolsConfig)) {
- logger.warn("Cannot update drools configuration: " + droolsConfig + " on " + this);
+ logger.warn("Cannot update drools configuration: {} on {}", droolsConfig, this);
throw new IllegalArgumentException("Cannot update drools configuration Drools Configuration");
}
- if (logger.isInfoEnabled())
- logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this);
+ if (logger.isInfoEnabled()) {
+ logger.info("UPDATED drools configuration: {} on {}", droolsConfig, this);
+ }
String coordinates = toKey(controller.getDrools().getGroupId(),
controller.getDrools().getArtifactId());
- if (controller.getDrools().isBrained())
+ if (controller.getDrools().isBrained()) {
this.coordinates2Controller.put(coordinates, controller);
+ }
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void shutdown(String controllerName) {
@@ -297,7 +304,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
throw makeArgEx(controllerName);
}
- synchronized(this) {
+ synchronized (this) {
if (!this.policyControllers.containsKey(controllerName)) {
return;
}
@@ -308,7 +315,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void shutdown(PolicyController controller) {
@@ -317,7 +324,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void shutdown() {
@@ -326,17 +333,17 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
controller.shutdown();
}
- synchronized(this) {
+ synchronized (this) {
this.policyControllers.clear();
this.coordinates2Controller.clear();
}
}
/**
- * unmanage the controller
+ * unmanage the controller.
*
- * @param controller
- * @throws IllegalArgumentException
+ * @param controller controller
+ * @throws IllegalArgumentException exception
*/
private void unmanage(PolicyController controller) {
PolicyController tempController = controller;
@@ -344,7 +351,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
throw new IllegalArgumentException("Invalid Controller");
}
- synchronized(this) {
+ synchronized (this) {
if (!this.policyControllers.containsKey(tempController.getName())) {
return;
}
@@ -357,7 +364,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void destroy(String controllerName) {
@@ -366,7 +373,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
throw makeArgEx(controllerName);
}
- synchronized(this) {
+ synchronized (this) {
if (!this.policyControllers.containsKey(controllerName)) {
return;
}
@@ -377,7 +384,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void destroy(PolicyController controller) {
@@ -386,7 +393,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void destroy() {
@@ -395,14 +402,14 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
controller.halt();
}
- synchronized(this) {
+ synchronized (this) {
this.policyControllers.clear();
this.coordinates2Controller.clear();
}
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public PolicyController get(String name) {
@@ -411,7 +418,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
throw makeArgEx(name);
}
- synchronized(this) {
+ synchronized (this) {
if (this.policyControllers.containsKey(name)) {
return this.policyControllers.get(name);
} else {
@@ -421,17 +428,17 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public PolicyController get(String groupId, String artifactId) {
- if (groupId == null || groupId.isEmpty() ||
- artifactId == null || artifactId.isEmpty()) {
+ if (groupId == null || groupId.isEmpty()
+ || artifactId == null || artifactId.isEmpty()) {
throw new IllegalArgumentException("Invalid group/artifact ids");
}
- synchronized(this) {
+ synchronized (this) {
String key = toKey(groupId,artifactId);
if (this.coordinates2Controller.containsKey(key)) {
return this.coordinates2Controller.get(key);
@@ -442,7 +449,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public PolicyController get(DroolsController droolsController) {
@@ -451,27 +458,28 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
throw new IllegalArgumentException("No Drools Controller provided");
}
- synchronized(this) {
+ synchronized (this) {
String key = toKey(droolsController.getGroupId(), droolsController.getArtifactId());
if (this.coordinates2Controller.containsKey(key)) {
return this.coordinates2Controller.get(key);
} else {
- logger.error("Drools Controller not associated with Policy Controller " + droolsController + ":" + this);
- throw new IllegalStateException("Drools Controller not associated with Policy Controller " + droolsController + ":" + this);
+ logger.error("Drools Controller not associated with Policy Controller {}:{}", droolsController, this);
+ throw new IllegalStateException("Drools Controller not associated with Policy Controller "
+ + droolsController + ":" + this);
}
}
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<PolicyController> inventory() {
- return new ArrayList<>(this.policyControllers.values());
+ return new ArrayList<>(this.policyControllers.values());
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<String> getFeatures() {
@@ -483,7 +491,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@JsonIgnore
@Override
@@ -492,16 +500,18 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public PolicyControllerFeatureAPI getFeatureProvider(String featureName) {
- if (featureName == null || featureName.isEmpty())
+ if (featureName == null || featureName.isEmpty()) {
throw new IllegalArgumentException("A feature name must be provided");
-
+ }
+
for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) {
- if (feature.getName().equals(featureName))
+ if (feature.getName().equals(featureName)) {
return feature;
+ }
}
throw new IllegalArgumentException("Invalid Feature Name: " + featureName);
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 993c09c0..60e5a1b8 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
@@ -69,34 +69,34 @@ import org.slf4j.LoggerFactory;
*/
public interface PolicyEngine extends Startable, Lockable, TopicListener {
/**
- * Policy Engine Manager
+ * Policy Engine Manager.
*/
PolicyEngine manager = new PolicyEngineManager();
/**
- * Default Telemetry Server Port
+ * Default Telemetry Server Port.
*/
int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
/**
- * Default Telemetry Server Hostname
+ * Default Telemetry Server Hostname.
*/
String TELEMETRY_SERVER_DEFAULT_HOST = "localhost";
/**
- * Default Telemetry Server Name
+ * Default Telemetry Server Name.
*/
String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
/**
- * Boot the engine
+ * Boot the engine.
*
* @param cliArgs command line arguments
*/
void boot(String[] cliArgs);
/**
- * configure the policy engine according to the given properties
+ * configure the policy engine according to the given properties.
*
* @param properties Policy Engine properties
* @throws IllegalArgumentException when invalid or insufficient properties are provided
@@ -104,6 +104,16 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
void configure(Properties properties);
/**
+ * updates the Policy Engine with the given configuration.
+ *
+ * @param configuration the configuration
+ * @return success or failure
+ * @throws IllegalArgumentException if invalid argument provided
+ * @throws IllegalStateException if the system is in an invalid state
+ */
+ boolean configure(PdpdConfiguration configuration);
+
+ /**
* configure the engine's environment. General lab installation configuration is made available
* to the Engine. Typically, custom lab installation that may be needed by arbitrary drools
* applications are made available, for example network component and database host addresses.
@@ -114,15 +124,15 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
void setEnvironment(Properties properties);
/**
- * gets the engine's environment
+ * gets the engine's environment.
*
- * @return
+ * @return properties object
*/
Properties getEnvironment();
/**
* gets an environment's value, by 1) first from the engine's environment, and 2) from the OS
- * environment
+ * environment.
*
* @param key environment key
* @return environment value or null if absent
@@ -130,11 +140,11 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
String getEnvironmentProperty(String key);
/**
- * sets an engine's environment property
+ * sets an engine's environment property.
*
- * @param key
- * @param value
- * @return
+ * @param key key
+ * @param value value
+ * @return property string
*/
String setEnvironmentProperty(String key, String value);
@@ -150,27 +160,17 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
PolicyController createPolicyController(String name, Properties properties);
/**
- * updates the Policy Engine with the given configuration
+ * updates a set of Policy Controllers with configuration information.
*
- * @param configuration the configuration
- * @return success or failure
- * @throws IllegalArgumentException if invalid argument provided
- * @throws IllegalStateException if the system is in an invalid state
- */
- boolean configure(PdpdConfiguration configuration);
-
- /**
- * updates a set of Policy Controllers with configuration information
- *
- * @param configuration
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
+ * @param configuration list of configurations
+ * @return list of controllers
+ * @throws IllegalArgumentException exception
+ * @throws IllegalStateException exception
*/
List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration);
/**
- * updates an already existing Policy Controller with configuration information
+ * updates an already existing Policy Controller with configuration information.
*
* @param configuration configuration
* @return the updated Policy Controller
@@ -181,22 +181,21 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
PolicyController updatePolicyController(ControllerConfiguration configuration);
/**
- * removes the Policy Controller identified by its name from the Policy Engine
+ * removes the Policy Controller identified by its name from the Policy Engine.
*
* @param name name of the Policy Controller
- * @return the removed Policy Controller
*/
void removePolicyController(String name);
/**
- * removes a Policy Controller from the Policy Engine
+ * removes a Policy Controller from the Policy Engine.
*
* @param controller the Policy Controller to remove from the Policy Engine
*/
void removePolicyController(PolicyController controller);
/**
- * returns a list of the available Policy Controllers
+ * returns a list of the available Policy Controllers.
*
* @return list of Policy Controllers
*/
@@ -204,63 +203,63 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
/**
- * get policy controller names
+ * get policy controller names.
*
* @return list of controller names
*/
List<String> getPolicyControllerIds();
/**
- * get unmanaged sources
+ * get unmanaged sources.
*
* @return unmanaged sources
*/
List<TopicSource> getSources();
/**
- * get unmanaged sinks
+ * get unmanaged sinks.
*
* @return unmanaged sinks
*/
List<TopicSink> getSinks();
/**
- * get unmmanaged http servers list
+ * get unmmanaged http servers list.
*
* @return http servers
*/
List<HttpServletServer> getHttpServers();
/**
- * get properties configuration
+ * get properties configuration.
*
* @return properties objects
*/
Properties getProperties();
/**
- * get features attached to the Policy Engine
+ * get features attached to the Policy Engine.
*
* @return list of features
*/
List<PolicyEngineFeatureAPI> getFeatureProviders();
/**
- * get named feature attached to the Policy Engine
+ * get named feature attached to the Policy Engine.
*
* @return the feature
*/
PolicyEngineFeatureAPI getFeatureProvider(String featureName);
/**
- * get features attached to the Policy Engine
+ * get features attached to the Policy Engine.
*
* @return list of features
*/
List<String> getFeatures();
/**
- * Attempts the dispatching of an "event" object
+ * Attempts the dispatching of an "event" object.
*
* @param topic topic
* @param event the event object to send
@@ -272,7 +271,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
boolean deliver(String topic, Object event);
/**
- * Attempts the dispatching of an "event" object over communication infrastructure "busType"
+ * Attempts the dispatching of an "event" object over communication infrastructure "busType".
*
* @param topic topic
* @param event the event object to send
@@ -286,7 +285,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
boolean deliver(String busType, String topic, Object event);
/**
- * Attempts the dispatching of an "event" object over communication infrastructure "busType"
+ * Attempts the dispatching of an "event" object over communication infrastructure "busType".
*
* @param topic topic
* @param event the event object to send
@@ -300,7 +299,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
boolean deliver(CommInfrastructure busType, String topic, Object event);
/**
- * Attempts delivering of an String over communication infrastructure "busType"
+ * Attempts delivering of an String over communication infrastructure "busType".
*
* @param topic topic
* @param event the event object to send
@@ -324,7 +323,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
void deactivate();
/**
- * produces a default telemetry configuration
+ * produces a default telemetry configuration.
*
* @return policy engine configuration
*/
@@ -333,7 +332,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
/**
- * Policy Engine Manager Implementation
+ * Policy Engine Manager Implementation.
*/
class PolicyEngineManager implements PolicyEngine {
private static final String INVALID_TOPIC_MSG = "Invalid Topic";
@@ -345,47 +344,47 @@ class PolicyEngineManager implements PolicyEngine {
private static final String ENGINE_LOCKED_MSG = "Policy Engine is locked";
/**
- * logger
+ * logger.
*/
private static final Logger logger = LoggerFactory.getLogger(PolicyEngineManager.class);
/**
- * Is the Policy Engine running?
+ * Is the Policy Engine running.
*/
private volatile boolean alive = false;
/**
- * Is the engine locked?
+ * Is the engine locked.
*/
private volatile boolean locked = false;
/**
- * Properties used to initialize the engine
+ * Properties used to initialize the engine.
*/
private Properties properties;
/**
- * Environment Properties
+ * Environment Properties.
*/
private final Properties environment = new Properties();
/**
- * Policy Engine Sources
+ * Policy Engine Sources.
*/
private List<? extends TopicSource> sources = new ArrayList<>();
/**
- * Policy Engine Sinks
+ * Policy Engine Sinks.
*/
private List<? extends TopicSink> sinks = new ArrayList<>();
/**
- * Policy Engine HTTP Servers
+ * Policy Engine HTTP Servers.
*/
private List<HttpServletServer> httpServers = new ArrayList<>();
/**
- * gson parser to decode configuration requests
+ * gson parser to decode configuration requests.
*/
private final Gson decoder = new GsonBuilder().disableHtmlEscaping().create();
@@ -527,6 +526,35 @@ class PolicyEngineManager implements PolicyEngine {
}
@Override
+ public boolean configure(PdpdConfiguration config) {
+
+ if (config == null) {
+ throw new IllegalArgumentException("No configuration provided");
+ }
+
+ final String entity = config.getEntity();
+
+ MDCTransaction mdcTrans = MDCTransaction.newTransaction(config.getRequestID(), "brmsgw");
+ if (this.getSources().size() == 1) {
+ Topic topic = this.getSources().get(0);
+ mdcTrans.setServiceName(topic.getTopic()).setRemoteHost(topic.getServers().toString())
+ .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);
+ }
+ }
+
+ @Override
public synchronized PolicyController createPolicyController(String name, Properties properties) {
String tempName = name;
@@ -577,35 +605,6 @@ class PolicyEngineManager implements PolicyEngine {
@Override
- public boolean configure(PdpdConfiguration config) {
-
- if (config == null) {
- throw new IllegalArgumentException("No configuration provided");
- }
-
- final String entity = config.getEntity();
-
- MDCTransaction mdcTrans = MDCTransaction.newTransaction(config.getRequestID(), "brmsgw");
- if (this.getSources().size() == 1) {
- Topic topic = this.getSources().get(0);
- mdcTrans.setServiceName(topic.getTopic()).setRemoteHost(topic.getServers().toString())
- .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);
- }
- }
-
- @Override
public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configControllers) {
final List<PolicyController> policyControllers = new ArrayList<>();
@@ -619,7 +618,7 @@ class PolicyEngineManager implements PolicyEngine {
for (final ControllerConfiguration configController : configControllers) {
MDCTransaction mdcTrans = MDCTransaction.newSubTransaction(null).setTargetEntity(configController.getName())
.setTargetServiceName(configController.getOperation())
- .setTargetVirtualEntity(""+configController.getDrools());
+ .setTargetVirtualEntity("" + configController.getDrools());
try {
final PolicyController policyController = this.updatePolicyController(configController);
policyControllers.add(policyController);
@@ -672,7 +671,7 @@ class PolicyEngineManager implements PolicyEngine {
/* Recovery case */
- logger.warn("controller " + controllerName + " does not exist. " + "Attempting recovery from disk");
+ logger.warn("controller {} does not exist. Attempting recovery from disk", controllerName);
final Properties controllerProperties =
SystemPersistence.manager.getControllerProperties(controllerName);
@@ -686,8 +685,8 @@ class PolicyEngineManager implements PolicyEngine {
throw new IllegalArgumentException(controllerName + " is invalid");
}
- logger.warn("controller " + controllerName + " being recovered. "
- + "Reset controller's bad maven coordinates to brainless");
+ logger.warn("controller being recovered. {} Reset controller's bad maven coordinates to brainless",
+ controllerName);
/*
* try to bring up bad controller in brainless mode, after having it working, apply
@@ -1470,7 +1469,7 @@ class PolicyEngineManager implements PolicyEngine {
/* only this one supported for now */
final List<ControllerConfiguration> configControllers = config.getControllers();
if (configControllers == null || configControllers.isEmpty()) {
- logger.info("No controller configuration provided: {}" + config);
+ logger.info("No controller configuration provided: {}", config);
return false;
}
@@ -1485,8 +1484,7 @@ class PolicyEngineManager implements PolicyEngine {
@Override
public String toString() {
- return "PolicyEngineManager [alive=" + this.alive + ", locked=" + this.locked +
- "]";
+ return "PolicyEngineManager [alive=" + this.alive + ", locked=" + this.locked + "]";
}
}
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 0b6643f8..8d290674 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
@@ -47,33 +47,33 @@ import org.slf4j.LoggerFactory;
public class AggregatedPolicyController implements PolicyController, TopicListener {
/**
- * Logger
+ * Logger.
*/
private static final Logger logger = LoggerFactory.getLogger(AggregatedPolicyController.class);
/**
- * identifier for this policy controller
+ * identifier for this policy controller.
*/
private final String name;
/**
- * Abstracted Event Sources List regardless communication technology
+ * Abstracted Event Sources List regardless communication technology.
*/
private final List<? extends TopicSource> sources;
/**
- * Abstracted Event Sinks List regardless communication technology
+ * Abstracted Event Sinks List regardless communication technology.
*/
private final List<? extends TopicSink> sinks;
/**
- * Mapping topics to sinks
+ * Mapping topics to sinks.
*/
@JsonIgnore
private final HashMap<String, TopicSink> topic2Sinks = new HashMap<>();
/**
- * Is this Policy Controller running (alive) ? reflects invocation of start()/stop() only
+ * Is this Policy Controller running (alive) ? reflects invocation of start()/stop() only.
*/
private volatile boolean alive;
@@ -85,18 +85,18 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
private volatile boolean locked;
/**
- * Policy Drools Controller
+ * Policy Drools Controller.
*/
private volatile DroolsController droolsController;
/**
- * Properties used to initialize controller
+ * Properties used to initialize controller.
*/
private final Properties properties;
/**
* Constructor version mainly used for bootstrapping at initialization time a policy engine
- * controller
+ * controller.
*
* @param name controller name
* @param properties
@@ -127,7 +127,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * initialize drools layer
+ * initialize drools layer.
*
* @throws IllegalArgumentException if invalid parameters are passed in
*/
@@ -142,7 +142,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * initialize sinks
+ * initialize sinks.
*
* @throws IllegalArgumentException if invalid parameters are passed in
*/
@@ -154,7 +154,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean updateDrools(DroolsConfiguration newDroolsConfiguration) {
@@ -206,7 +206,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public String getName() {
@@ -214,7 +214,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean start() {
@@ -243,7 +243,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
this.alive = true;
}
- boolean success = this.droolsController.start();
+ final boolean success = this.droolsController.start();
// register for events
@@ -274,7 +274,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean stop() {
@@ -324,7 +324,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void shutdown() {
@@ -358,7 +358,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void halt() {
@@ -392,7 +392,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public void onTopicEvent(Topic.CommInfrastructure commType, String topic, String event) {
@@ -435,7 +435,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean deliver(Topic.CommInfrastructure commType, String topic, Object event) {
@@ -494,7 +494,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean isAlive() {
@@ -502,7 +502,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean lock() {
@@ -547,7 +547,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean unlock() {
@@ -590,7 +590,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public boolean isLocked() {
@@ -598,7 +598,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<? extends TopicSource> getTopicSources() {
@@ -606,7 +606,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public List<? extends TopicSink> getTopicSinks() {
@@ -614,7 +614,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
public DroolsController getDrools() {
@@ -623,7 +623,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
/**
- * {@inheritDoc}
+ * {@inheritDoc}.
*/
@Override
@JsonIgnore
@@ -633,8 +633,8 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
@Override
public String toString() {
- return "AggregatedPolicyController [name=" + name + ", alive=" + alive +
- ", locked=" + locked + ", droolsController=" + droolsController + "]";
+ return "AggregatedPolicyController [name=" + name + ", alive=" + alive
+ + ", locked=" + locked + ", droolsController=" + droolsController + "]";
}
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
index ce34ec8a..5d6b11dc 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
@@ -117,14 +117,17 @@ public class RestManagerTest {
+ PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
"" + DEFAULT_TELEMETRY_PORT);
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyEndPointProperties.PROPERTY_HTTP_FILTER_CLASSES_SUFFIX,
- TestAafTelemetryAuthFilter.class.getName());
+ + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEndPointProperties.PROPERTY_HTTP_FILTER_CLASSES_SUFFIX,
+ TestAafTelemetryAuthFilter.class.getName());
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX,
- TELEMETRY_USER);
+ + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX,
+ TELEMETRY_USER);
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX,
- TELEMETRY_PASSWORD);
+ + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX,
+ TELEMETRY_PASSWORD);
/* other properties */
engineProps.put(PolicyEndPointProperties.PROPERTY_UEB_SOURCE_TOPICS, UEB_TOPIC);
@@ -288,6 +291,7 @@ public class RestManagerTest {
httpPut.setEntity(new StringEntity("FOOOO"));
response = client.execute(httpPut);
logger.info(httpPut.getRequestLine() + " response code: {}", response.getStatusLine().getStatusCode());
+
assertEquals(404, response.getStatusLine().getStatusCode());
httpPut.releaseConnection();
diff --git a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/TestAafTelemetryAuthFilter.java b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/TestAafTelemetryAuthFilter.java
index c7d52325..67e16183 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/TestAafTelemetryAuthFilter.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/TestAafTelemetryAuthFilter.java
@@ -25,7 +25,7 @@ import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.drools.server.restful.aaf.AafTelemetryAuthFilter;
/**
- * Test AAF Telemetry Authorization Filter for Junits
+ * Test AAF Telemetry Authorization Filter for Junits.
*/
public class TestAafTelemetryAuthFilter extends AafTelemetryAuthFilter {