summaryrefslogtreecommitdiffstats
path: root/dmaap-listener
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-11-13 10:04:11 -0500
committerDan Timoney <dtimoney@att.com>2017-11-13 10:04:11 -0500
commit32a9ecade35bc3e742dfbc9e86d887f25b5f49c9 (patch)
tree188d993b3380246e2ba0da6e2d956ebe3988b96f /dmaap-listener
parent024e6d1689ee38b37ac054636557b5dff8f26270 (diff)
Handle duplicate DHCP event
Handle case where 2 DHCP events received for same mac addr. Should use most recent IP address. Change-Id: I90399ce3c39e07c2472366c78115812a64e9124b Issue-ID: CCSDK-142 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'dmaap-listener')
-rw-r--r--dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java3
-rw-r--r--dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java9
2 files changed, 10 insertions, 2 deletions
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java
index 666ed68e1..03560d309 100644
--- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java
@@ -124,8 +124,7 @@ public class SdncDhcpEventConsumer extends SdncDmaapConsumer {
try {
- jdbcDataSource.writeData("INSERT INTO DHCP_MAP(mac_addr, ip_addr) VALUES('" + macAddr + "','" + ipAddr + "')",
- null, null);
+ jdbcDataSource.writeData("INSERT INTO DHCP_MAP(mac_addr, ip_addr) VALUES('" + macAddr + "','" + ipAddr + "') ON DUPLICATE KEY UPDATE ip_addr = '"+ipAddr+"'", null, null);
} catch (SQLException e) {
LOG.error("Could not insert DHCP event data into the database ", e);
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java
index 8c3a839c2..04f098ade 100644
--- a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java
+++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java
@@ -42,6 +42,9 @@ public class TestSdncDhcpEventConsumer {
private static final String VALID_DHCP_EVENT = "{\"msg_name\":\"DHCPACK\"," +
"\"macaddr\":\"fa:16:3e:8f:ea:68\"," +
"\"yiaddr\":\"10.3.0.2\"}";
+ private static final String SECOND_DHCP_EVENT = "{\"msg_name\":\"DHCPACK\"," +
+ "\"macaddr\":\"fa:16:3e:8f:ea:68\"," +
+ "\"yiaddr\":\"10.3.0.3\"}";
private static final String MISSING_MSG_NAME_DHCP_EVENT = "{\"macaddr\":\"fa:16:3e:8f:ea:68\"," +
"\"yiaddr\":\"10.3.0.2\"}";
private static final String MISSING_MAC_ADDR_DHCP_EVENT = "{\"msg_name\":\"DHCPACK\"," +
@@ -104,11 +107,17 @@ public class TestSdncDhcpEventConsumer {
@Test
public void testValid() throws InvalidMessageException, SQLException {
consumer.processMsg(VALID_DHCP_EVENT);
+ consumer.processMsg(SECOND_DHCP_EVENT);
CachedRowSet results = dblibSvc.getData(GET_DHCP_MAPPING, null, null);
if (!results.next()) {
fail("Test query ["+GET_DHCP_MAPPING+"] returned no data");
+ } else {
+ String ipAddr = results.getString("ip_addr");
+ if (!"10.3.0.3".equals(ipAddr)) {
+ fail("Expecting ipAddr to be 10.3.0.3, but was "+ipAddr);
+ }
}
}