Skip to content
Snippets Groups Projects
Commit 298259b5 authored by Subrata Banerjee's avatar Subrata Banerjee
Browse files

Use Date and SimpleDateFormat instead of TimeStamp for formatting the date string.

Catch illformated event-history count cases.
parent 05a2a2f0
No related branches found
No related tags found
No related merge requests found
......@@ -33,11 +33,18 @@ public class EventHistoryAttachmentPointResource extends ServerResource {
// Get the event history count. Last <count> events would be returned
String evHistCount = (String)getRequestAttributes().get("count");
int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
try {
count = Integer.parseInt(evHistCount);
}
catch(NumberFormatException nFE) {
// Invalid input for event count - use default value
}
DeviceManagerImpl deviceManager =
(DeviceManagerImpl)getContext().getAttributes().get("deviceManager");
return new EventHistory<EventHistoryAttachmentPoint>(deviceManager.evHistDevMgrAttachPt,
Integer.parseInt(evHistCount));
return new EventHistory<EventHistoryAttachmentPoint>(
deviceManager.evHistDevMgrAttachPt, count);
}
}
......@@ -22,12 +22,18 @@ public class EventHistoryPacketInResource extends ServerResource {
EventHistory<OFMatch> ofm = null;
// Get the count (number of latest events requested), zero means all
String evHistCount = (String)getRequestAttributes().get("count");
int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
try {
count = Integer.parseInt(evHistCount);
}
catch(NumberFormatException nFE) {
// Invalid input for event count - use default value
}
DeviceManagerImpl deviceManager =
(DeviceManagerImpl)getContext().getAttributes().get("deviceManager");
ofm = new EventHistory<OFMatch>(deviceManager.evHistDevMgrPktIn,
Integer.parseInt(evHistCount));
ofm = new EventHistory<OFMatch>(deviceManager.evHistDevMgrPktIn,count);
return ofm;
}
......
......@@ -18,12 +18,18 @@ public class EventHistoryTopologyClusterResource extends ServerResource {
// Get the event history count. Last <count> events would be returned
String evHistCount = (String)getRequestAttributes().get("count");
int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
try {
count = Integer.parseInt(evHistCount);
}
catch(NumberFormatException nFE) {
// Invalid input for event count - use default value
}
TopologyImpl topoManager =
(TopologyImpl)getContext().getAttributes().get("topology");
return new EventHistory<EventHistoryTopologyCluster>(
topoManager.evHistTopologyCluster,
Integer.parseInt(evHistCount));
topoManager.evHistTopologyCluster, count);
}
}
......@@ -18,11 +18,18 @@ public class EventHistoryTopologyLinkResource extends ServerResource {
// Get the event history count. Last <count> events would be returned
String evHistCount = (String)getRequestAttributes().get("count");
int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
try {
count = Integer.parseInt(evHistCount);
}
catch(NumberFormatException nFE) {
// Invalid input for event count - use default value
}
TopologyImpl topoManager =
(TopologyImpl)getContext().getAttributes().get("topology");
return new EventHistory<EventHistoryTopologyLink>(
topoManager.evHistTopologyLink, Integer.parseInt(evHistCount));
topoManager.evHistTopologyLink, count);
}
}
......@@ -18,12 +18,18 @@ public class EventHistoryTopologySwitchResource extends ServerResource {
// Get the event history count. Last <count> events would be returned
String evHistCount = (String)getRequestAttributes().get("count");
int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
try {
count = Integer.parseInt(evHistCount);
}
catch(NumberFormatException nFE) {
// Invalid input for event count - use default value
}
TopologyImpl topoManager =
(TopologyImpl)getContext().getAttributes().get("topology");
return new EventHistory<EventHistoryTopologySwitch>(
topoManager.evHistTopologySwitch,
Integer.parseInt(evHistCount));
topoManager.evHistTopologySwitch, count);
}
}
......@@ -18,7 +18,8 @@ package net.floodlightcontroller.core.web.serializers;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.floodlightcontroller.util.EventHistoryBaseInfo;
......@@ -67,14 +68,15 @@ public class EventHistoryBaseInfoJSONSerializer extends
public String convertNanoSecondsToStr(long nanoSeconds) {
long millisecs = nanoSeconds / 1000000;
int remaining_ns = (int)(nanoSeconds % 1000000000);
Timestamp ts = new Timestamp(millisecs);
ts.setNanos(remaining_ns);
// Show up to microseconds resolution
// length of "2012-01-09 14:54:45.067253" is 26
String timeStr = ts.toString();
while (timeStr.length() < 26) {
timeStr = timeStr.concat("0");
int remaining_us = remaining_ns / 1000;
// Show up to microseconds resolution as "2012-01-09 14:54:45.067253"
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeStr = df.format(new Date(millisecs));
String usStr = Integer.toString(remaining_us);
while (usStr.length() < 6) {
usStr = "0".concat(usStr);
}
timeStr = timeStr + "." + usStr;
return timeStr;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment