aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-09-22 21:07:43 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-09-22 21:15:22 +0100
commit6973ec9109fd2651e2284663b6c8039bd830a677 (patch)
treef1f02ef9e5400805e6c2179dc539ad15c3ce5334 /services/services-engine
parenta02548ec2e98a8a13cd76ecc83379b13cd26030b (diff)
Fix sonar problems in Apex
Fixed some easy to resolve Sonar issues. Issue-ID: POLICY-1034 Change-Id: Ia8e4606bd4307daca499b4a74c96135211e572fd Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'services/services-engine')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java22
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java2
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java2
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java34
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java16
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java18
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java1
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java1
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java2
9 files changed, 64 insertions, 34 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
index 5a0d11d4c..368305efa 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
@@ -102,7 +102,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
public static final String SOURCE_REGEXP = "^$|[A-Za-z0-9\\.\\-_:]+";
/** The target of an Apex event must match this regular expression. */
- public static final String TARGET_REGEXP = "^$|[A-Za-z0-9\\.\\-_:]+";
+ public static final String TARGET_REGEXP = SOURCE_REGEXP;
// The fields of the event
// @formatter:off
@@ -121,16 +121,6 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
private String exceptionMessage;
/**
- * Private utility to get the next candidate value for a Execution ID. This value will always be
- * unique in a single JVM
- *
- * @return the next candidate value for a Execution ID
- */
- private static synchronized long getNextExecutionId() {
- return nextExecutionID.getAndIncrement();
- }
-
- /**
* Instantiates a new apex event.
*
* @param name the name of the event
@@ -152,6 +142,16 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
}
/**
+ * Private utility to get the next candidate value for a Execution ID. This value will always be
+ * unique in a single JVM
+ *
+ * @return the next candidate value for a Execution ID
+ */
+ private static synchronized long getNextExecutionId() {
+ return nextExecutionID.getAndIncrement();
+ }
+
+ /**
* Check that a field of the event is valid.
*
* @param fieldName the name of the field to check
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java
index 32f87a7cc..fbb1ec053 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java
@@ -51,7 +51,7 @@ public class ApexPeriodicEventGenerator extends TimerTask {
public static final String PERIODIC_EVENT_SOURCE = "internal";
/** The target of the periodic event. */
- public static final String PERIODIC_EVENT_TARGET = "internal";
+ public static final String PERIODIC_EVENT_TARGET = PERIODIC_EVENT_SOURCE;
/**
* The field name in the periodic event for the delay between occurrences of the periodic event.
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java
index 532fdb9c7..77be038e5 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java
@@ -94,7 +94,7 @@ public class ApexEventMarshaller implements ApexEventListener, Runnable {
* @throws ApexActivatorException on errors initializing the producer
* @throws ApexEventException on errors initializing event handling
*/
- public void init() throws ApexActivatorException, ApexEventException {
+ public void init() throws ApexEventException {
// Create the producer for sending events and the converter for transforming events
producer = new EventProducerFactory().createProducer(name, producerParameters);
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
index 1d1b64e37..97aa25fbe 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
@@ -216,15 +216,10 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable {
try {
final List<ApexEvent> apexEventList = converter.toApexEvent(consumerParameters.getEventName(), event);
for (final ApexEvent apexEvent : apexEventList) {
- // Check if we are filtering events on this unmarshaler, if so check the event name
- // against the filter
- if (consumerParameters.isSetEventNameFilter()
- && !apexEvent.getName().matches(consumerParameters.getEventNameFilter())) {
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("onMessage(): event {} not processed, filtered out by filter", apexEvent,
- consumerParameters.getEventNameFilter());
- }
+ isEventFilteredOut(apexEvent);
+ // Check if this event is filtered out by the incoming filter
+ if (isEventFilteredOut(apexEvent)) {
// Ignore this event
continue;
}
@@ -252,6 +247,29 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable {
}
/**
+ * Check if an event is filtered out and ignored.
+ *
+ * @param apexEvent the event to check
+ */
+ private boolean isEventFilteredOut(final ApexEvent apexEvent) {
+ // Check if we are filtering events on this unmarshaler, if so check the event name
+ // against the filter
+ if (consumerParameters.isSetEventNameFilter()
+ && !apexEvent.getName().matches(consumerParameters.getEventNameFilter())) {
+
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace("onMessage(): event {} not processed, filtered out by filter", apexEvent,
+ consumerParameters.getEventNameFilter());
+ }
+
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ /**
* Run a thread that runs forever (well until system termination anyway) and listens for incoming events on the
* queue.
*/
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
index dc5e91979..56b3b84c4 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
@@ -714,9 +714,8 @@ final class EngineWorker implements EngineService {
try {
if (event != null) {
- if (debugEnabled) {
- LOGGER.debug("Trigger Event {} forwarded to the Apex engine", event);
- }
+ debugEventIfDebugEnabled(event);
+
final EnEvent enevent = apexEnEventConverter.fromApexEvent(event);
engine.handleEvent(enevent);
}
@@ -729,5 +728,16 @@ final class EngineWorker implements EngineService {
}
LOGGER.debug("Engine {} completed processing", engineWorkerKey);
}
+
+ /**
+ * Debug the event if debug is enabled.
+ *
+ * @param event the event to debug
+ */
+ private void debugEventIfDebugEnabled(ApexEvent event) {
+ if (debugEnabled) {
+ LOGGER.debug("Trigger Event {} forwarded to the Apex engine", event);
+ }
+ }
}
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java
index 907baad40..4bbc5fc85 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java
@@ -55,6 +55,15 @@ public class ApexParameters implements ParameterGroup {
private static final String EVENT_OUTPUT_PARAMETERS_STRING = "eventOutputParameters";
private static final String FOR_PEERED_MODE_STRING = " for peered mode ";
+ // Parameters for the engine service and the engine threads in the engine service
+ private EngineServiceParameters engineServiceParameters;
+
+ // Parameters for the event outputs that Apex will use to send events on its outputs
+ private Map<String, EventHandlerParameters> eventOutputParameters = new LinkedHashMap<>();
+
+ // Parameters for the event inputs that Apex will use to receive events on its inputs
+ private Map<String, EventHandlerParameters> eventInputParameters = new LinkedHashMap<>();
+
/**
* Constructor to create an apex parameters instance and register the instance with the parameter service.
*/
@@ -65,15 +74,6 @@ public class ApexParameters implements ParameterGroup {
this.name = ApexParameterConstants.MAIN_GROUP_NAME;
}
- // Parameters for the engine service and the engine threads in the engine service
- private EngineServiceParameters engineServiceParameters;
-
- // Parameters for the event outputs that Apex will use to send events on its outputs
- private Map<String, EventHandlerParameters> eventOutputParameters = new LinkedHashMap<>();
-
- // Parameters for the event inputs that Apex will use to receive events on its inputs
- private Map<String, EventHandlerParameters> eventInputParameters = new LinkedHashMap<>();
-
/**
* Gets the parameters for the Apex engine service.
*
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java
index 471f90425..4dbdc8cce 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java
@@ -33,7 +33,6 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParame
*
*/
public class TestJsonEventConverter {
-
@Test
public void testJsonEventConverter() {
Apex2JsonEventConverter converter = new Apex2JsonEventConverter();
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java
index a9165d792..6e462a3e1 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java
@@ -93,6 +93,7 @@ public class TestJsonEventHandler {
@AfterClass
public static void teardownDefaultSchemaParameters() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
+ ModelService.clear();
}
/**
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java
index 1dae4c0f4..38f6da1b0 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java
@@ -36,6 +36,7 @@ import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
+import org.onap.policy.apex.model.basicmodel.service.ModelService;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter;
@@ -89,6 +90,7 @@ public class TestJsonEventHandlerForPojo {
@AfterClass
public static void teardownDefaultSchemaParameters() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
+ ModelService.clear();
}
/**