summaryrefslogtreecommitdiffstats
path: root/policy-management
diff options
context:
space:
mode:
authorkris.jinka <kris.jinka@samsung.com>2018-11-15 09:51:02 +0900
committerkris.jinka <kris.jinka@samsung.com>2018-11-15 09:51:21 +0900
commit96b3a0059c5900f33d8c1b4f4295f6d84177e2bf (patch)
tree3a9983cb9b542a30d4eb00c7e8e8bb06a71b9023 /policy-management
parentf14baf16a435eaa1ed8714741996ed01775572f8 (diff)
Modify event (en)coder to use param objs
Use builder object to send params to event protocol coder and encoder methods to fix sonar issue Issue-ID: POLICY-1251 Change-Id: I6ca5823e1aa35d9aa3a05eb23ac159947efdde23 Signed-off-by: kris.jinka <kris.jinka@samsung.com>
Diffstat (limited to 'policy-management')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java12
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java42
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java158
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java9
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java12
5 files changed, 194 insertions, 39 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
index 707a8e77..ef20b84d 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
@@ -42,6 +42,7 @@ import org.onap.policy.drools.core.PolicySession;
import org.onap.policy.drools.core.jmx.PdpJmx;
import org.onap.policy.drools.features.DroolsControllerFeatureAPI;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolParams;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
@@ -310,11 +311,12 @@ public class MavenDroolsController implements DroolsController {
customJacksonCoder,
this.policyContainer.getClassLoader().hashCode());
} else {
- EventProtocolCoder.manager.addEncoder(this.getGroupId(), this.getArtifactId(),
- topic, potentialCodedClass, protocolFilter,
- customGsonCoder,
- customJacksonCoder,
- this.policyContainer.getClassLoader().hashCode());
+ EventProtocolCoder.manager.addEncoder(
+ EventProtocolParams.builder().groupId(this.getGroupId())
+ .artifactId(this.getArtifactId()).topic(topic)
+ .eventClass(potentialCodedClass).protocolFilter(protocolFilter)
+ .customGsonCoder(customGsonCoder).customJacksonCoder(customJacksonCoder)
+ .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
}
}
}
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 6d752897..b9cb568c 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
@@ -281,21 +281,10 @@ public interface EventProtocolCoder {
/**
* Adds a Encoder class to encode the protocol over this topic.
*
- * @param groupId of the controller
- * @param artifactId of the controller
- * @param topic the topic
- * @param eventClass the event class
- * @param protocolFilter filters to selectively choose a particular decoder
- * when there are multiples
- *
- * @throw IllegalArgumentException if an invalid parameter is passed
+ *
+ * @param eventProtocolParams@throw IllegalArgumentException if an invalid parameter is passed
*/
- public void addEncoder(String groupId, String artifactId, String topic,
- String eventClass,
- JsonProtocolFilter protocolFilter,
- CustomGsonCoder customGsonCoder,
- CustomJacksonCoder customJacksonCoder,
- int modelClassLoaderHash);
+ public void addEncoder(EventProtocolParams eventProtocolParams);
/**
* is there an encoder supported for the controller id and topic.
@@ -428,20 +417,21 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
/**
* {@inheritDoc}.
+ * @param eventProtocolParams parameter object for event encoder
*/
@Override
- public void addEncoder(String groupId, String artifactId, String topic,
- String eventClass,
- JsonProtocolFilter protocolFilter,
- CustomGsonCoder customGsonCoder,
- CustomJacksonCoder customJacksonCoder,
- int modelClassLoaderHash) {
- logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this,
- groupId, artifactId, topic, eventClass,
- protocolFilter, customGsonCoder, customJacksonCoder,
- modelClassLoaderHash);
- this.encoders.add(groupId, artifactId, topic, eventClass, protocolFilter,
- customGsonCoder, customJacksonCoder, modelClassLoaderHash);
+ public void addEncoder(EventProtocolParams eventProtocolParams) {
+ logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this,
+ eventProtocolParams.getGroupId(), eventProtocolParams.getArtifactId(), eventProtocolParams.getTopic(),
+ eventProtocolParams.getEventClass(),
+ eventProtocolParams.getProtocolFilter(), eventProtocolParams.getCustomGsonCoder(),
+ eventProtocolParams.getCustomJacksonCoder(),
+ eventProtocolParams.getModelClassLoaderHash());
+ this.encoders.add(eventProtocolParams.getGroupId(), eventProtocolParams.getArtifactId(),
+ eventProtocolParams.getTopic(), eventProtocolParams.getEventClass(),
+ eventProtocolParams.getProtocolFilter(),
+ eventProtocolParams.getCustomGsonCoder(), eventProtocolParams.getCustomJacksonCoder(),
+ eventProtocolParams.getModelClassLoaderHash());
}
/**
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java
new file mode 100644
index 00000000..89d22481
--- /dev/null
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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=========================================================
+ */
+
+package org.onap.policy.drools.protocol.coders;
+
+public class EventProtocolParams {
+ private String groupId;
+ private String artifactId;
+ private String topic;
+ private String eventClass;
+ private JsonProtocolFilter protocolFilter;
+ private TopicCoderFilterConfiguration.CustomGsonCoder customGsonCoder;
+ private TopicCoderFilterConfiguration.CustomJacksonCoder customJacksonCoder;
+ private int modelClassLoaderHash;
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public String getArtifactId() {
+ return artifactId;
+ }
+
+ public String getTopic() {
+ return topic;
+ }
+
+ public String getEventClass() {
+ return eventClass;
+ }
+
+ public JsonProtocolFilter getProtocolFilter() {
+ return protocolFilter;
+ }
+
+ public TopicCoderFilterConfiguration.CustomGsonCoder getCustomGsonCoder() {
+ return customGsonCoder;
+ }
+
+ public TopicCoderFilterConfiguration.CustomJacksonCoder getCustomJacksonCoder() {
+ return customJacksonCoder;
+ }
+
+ public int getModelClassLoaderHash() {
+ return modelClassLoaderHash;
+ }
+
+ public static EventProtocolParams builder() {
+ return new EventProtocolParams();
+ }
+
+ /**
+ * Setter method.
+ *
+ * @param groupId of the controller
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams groupId(String groupId) {
+ this.groupId = groupId;
+ return this;
+ }
+
+ /**
+ * Setter method.
+ *
+ * @param artifactId of the controller
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams artifactId(String artifactId) {
+ this.artifactId = artifactId;
+ return this;
+ }
+
+ /**
+ * Setter method.
+ *
+ * @param topic the topic
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams topic(String topic) {
+ this.topic = topic;
+ return this;
+ }
+
+ /**
+ * Setter method.
+ *
+ * @param eventClass the event class
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams eventClass(String eventClass) {
+ this.eventClass = eventClass;
+ return this;
+ }
+
+ /**
+ * Setter method.
+ *
+ * @param protocolFilter filters to selectively choose a particular decoder
+ * when there are multiples
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams protocolFilter(JsonProtocolFilter protocolFilter) {
+ this.protocolFilter = protocolFilter;
+ return this;
+ }
+
+ /**
+ * Setter method.
+ *
+ * @param customGsonCoder custom gscon coder
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams customGsonCoder(
+ TopicCoderFilterConfiguration.CustomGsonCoder customGsonCoder) {
+ this.customGsonCoder = customGsonCoder;
+ return this;
+ }
+
+ /**
+ * Setter method.
+ *
+ * @param customJacksonCoder custom Jackson coder
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams customJacksonCoder(
+ TopicCoderFilterConfiguration.CustomJacksonCoder customJacksonCoder) {
+ this.customJacksonCoder = customJacksonCoder;
+ return this;
+ }
+
+ /**
+ * Setter method.
+ * @param modelClassLoaderHash integer representing model hash
+ * @return EventProtocolParams
+ */
+ public EventProtocolParams modelClassLoaderHash(int modelClassLoaderHash) {
+ this.modelClassLoaderHash = modelClassLoaderHash;
+ return this;
+ }
+}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
index d6330cd5..ec1b9994 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
@@ -84,9 +84,12 @@ public class EventProtocolCoderTest {
TopicEndpoint.manager.addTopicSinks(noopSinkProperties);
- EventProtocolCoder.manager.addEncoder(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC,
- DroolsConfiguration.class.getCanonicalName(), new JsonProtocolFilter(), null, null,
- DroolsConfiguration.class.getName().hashCode());
+ EventProtocolCoder.manager.addEncoder(
+ EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
+ .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName())
+ .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
+ .customJacksonCoder(null)
+ .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
final String json = EventProtocolCoder.manager.encode(NOOP_TOPIC,
new DroolsConfiguration(ENCODER_GROUP, ENCODER_ARTIFACT, ENCODER_VERSION));
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
index cd93d94c..4a2767a8 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
@@ -41,10 +41,9 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.DroolsProperties;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolParams;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
-import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.drools.system.PolicyEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -205,9 +204,12 @@ public class PolicyEngineTest {
TopicEndpoint.manager.addTopicSinks(noopSinkProperties).get(0).start();
- EventProtocolCoder.manager.addEncoder(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC,
- DroolsConfiguration.class.getCanonicalName(), new JsonProtocolFilter(), null, null,
- DroolsConfiguration.class.getName().hashCode());
+ EventProtocolCoder.manager.addEncoder(
+ EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
+ .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName())
+ .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
+ .customJacksonCoder(null)
+ .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
assertTrue(PolicyEngine.manager.deliver(NOOP_TOPIC,
new DroolsConfiguration(ENCODER_GROUP, ENCODER_ARTIFACT, ENCODER_VERSION)));