From 32a9ecade35bc3e742dfbc9e86d887f25b5f49c9 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Mon, 13 Nov 2017 10:04:11 -0500 Subject: 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 --- .../ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java | 3 +-- .../sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'dmaap-listener') 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); + } } } -- cgit 1.2.3-korg