Add new message validator interface 29/124529/2
authorRafal Wrzesniak <r.wrzesniak@partner.samsung.com>
Tue, 28 Sep 2021 11:54:41 +0000 (13:54 +0200)
committerRafal Wrzesniak <r.wrzesniak@partner.samsung.com>
Wed, 29 Sep 2021 05:34:20 +0000 (07:34 +0200)
And its simple implementation in basic consumer class

Issue-ID: CCSDK-3465
Signed-off-by: Rafal Wrzesniak <r.wrzesniak@partner.samsung.com>
Change-Id: I84c01ccce48e721ea83756b8081e5a3d57d8bac4

sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerImpl.java
sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgValidator.java [new file with mode: 0644]

index 4dcbfbb..015e3ad 100644 (file)
 
 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
 
-import java.util.List;
 import java.util.Properties;
-import java.util.function.Consumer;
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.JsonNodeType;
 import org.onap.dmaap.mr.client.MRClientFactory;
 import org.onap.dmaap.mr.client.MRConsumer;
 import org.onap.dmaap.mr.client.response.MRConsumerResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public abstract class DMaaPVESMsgConsumerImpl implements DMaaPVESMsgConsumer {
+public abstract class DMaaPVESMsgConsumerImpl implements DMaaPVESMsgConsumer, DMaaPVESMsgValidator {
 
     private static final Logger LOG = LoggerFactory.getLogger(DMaaPVESMsgConsumerImpl.class);
     private static final String DEFAULT_SDNRUSER = "admin";
@@ -68,7 +63,9 @@ public abstract class DMaaPVESMsgConsumerImpl implements DMaaPVESMsgConsumer {
                     for (String msg : consumerResponse.getActualMessages()) {
                         noData = false;
                         LOG.debug("{} received ActualMessage from DMaaP VES Message topic {}", name,msg);
-                        processMsg(msg);
+                        if(isMessageValid(msg)) {
+                            processMsg(msg);
+                        }
                     }
 
                     if (noData) {
@@ -81,6 +78,8 @@ public abstract class DMaaPVESMsgConsumerImpl implements DMaaPVESMsgConsumer {
                         }
                         pauseThread();
                     }
+                } catch (JsonProcessingException jsonProcessingException) {
+                    LOG.warn("Failed to convert message to JsonNode: {}", jsonProcessingException.getMessage());
                 } catch (Exception e) {
                     LOG.error("Caught exception reading from DMaaP VES Message Topic", e);
                     running = false;
@@ -89,6 +88,11 @@ public abstract class DMaaPVESMsgConsumerImpl implements DMaaPVESMsgConsumer {
         }
     }
 
+    @Override
+    public boolean isMessageValid(String message) {
+        return true;
+    }
+
     /*
      * Create a consumer by specifying  properties containing information such as topic name, timeout, URL etc
      */
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgValidator.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgValidator.java
new file mode 100644 (file)
index 0000000..0532334
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt mountpoint-registrar
+ * =================================================================================================
+ * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
+ * =================================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ * ============LICENSE_END==========================================================================
+ */
+
+package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
+
+public interface DMaaPVESMsgValidator {
+
+    boolean isMessageValid(String message);
+
+}