Skip to content
Snippets Groups Projects
Commit ce387c3f authored by Saurav Das's avatar Saurav Das
Browse files

Changes to rest API in debugEvents to prepare for CLI

parent 2ed13973
No related branches found
No related tags found
No related merge requests found
...@@ -2411,7 +2411,7 @@ public class Controller implements IFloodlightProviderService, ...@@ -2411,7 +2411,7 @@ public class Controller implements IFloodlightProviderService,
} }
try { try {
evSwitch = debugEvents.registerEvent( evSwitch = debugEvents.registerEvent(
"controller", "switchevent", Counters.prefix, "switchevent",
"Switch connected, disconnected or port changed", "Switch connected, disconnected or port changed",
EventType.ALWAYS_LOG, SwitchEvent.class, 100); EventType.ALWAYS_LOG, SwitchEvent.class, 100);
} catch (MaxEventsRegistered e) { } catch (MaxEventsRegistered e) {
......
...@@ -364,14 +364,15 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService { ...@@ -364,14 +364,15 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
@Override @Override
public List<DebugEventInfo> getAllEventHistory() { public List<DebugEventInfo> getAllEventHistory() {
ArrayList<DebugEventInfo> moduleEventList = new ArrayList<DebugEventInfo>(); List<DebugEventInfo> moduleEventList = new ArrayList<DebugEventInfo>();
for (Map<String, Integer> modev : moduleEvents.values()) { for (Map<String, Integer> modev : moduleEvents.values()) {
for (int eventId : modev.values()) { for (int eventId : modev.values()) {
DebugEventHistory de = allEvents[eventId]; DebugEventHistory de = allEvents[eventId];
if (de != null) { if (de != null) {
ArrayList<String> ret = new ArrayList<String>(); List<Map<String,String>> ret = new ArrayList<Map<String,String>>();
for (Event e : de.eventBuffer) { for (Event e : de.eventBuffer) {
ret.add(e.toString(de.einfo.eventClass, de.einfo.moduleEventName)); ret.add(e.getFormattedEvent(de.einfo.eventClass,
de.einfo.moduleEventName));
} }
moduleEventList.add(new DebugEventInfo(de.einfo, ret)); moduleEventList.add(new DebugEventInfo(de.einfo, ret));
} }
...@@ -383,13 +384,14 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService { ...@@ -383,13 +384,14 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
@Override @Override
public List<DebugEventInfo> getModuleEventHistory(String moduleName) { public List<DebugEventInfo> getModuleEventHistory(String moduleName) {
if (!moduleEvents.containsKey(moduleName)) return Collections.emptyList(); if (!moduleEvents.containsKey(moduleName)) return Collections.emptyList();
ArrayList<DebugEventInfo> moduleEventList = new ArrayList<DebugEventInfo>(); List<DebugEventInfo> moduleEventList = new ArrayList<DebugEventInfo>();
for (int eventId : moduleEvents.get(moduleName).values()) { for (int eventId : moduleEvents.get(moduleName).values()) {
DebugEventHistory de = allEvents[eventId]; DebugEventHistory de = allEvents[eventId];
if (de != null) { if (de != null) {
ArrayList<String> ret = new ArrayList<String>(); List<Map<String,String>> ret = new ArrayList<Map<String,String>>();
for (Event e : de.eventBuffer) { for (Event e : de.eventBuffer) {
ret.add(e.toString(de.einfo.eventClass, de.einfo.moduleEventName)); ret.add(e.getFormattedEvent(de.einfo.eventClass,
de.einfo.moduleEventName));
} }
moduleEventList.add(new DebugEventInfo(de.einfo, ret)); moduleEventList.add(new DebugEventInfo(de.einfo, ret));
} }
...@@ -404,9 +406,10 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService { ...@@ -404,9 +406,10 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
if (eventId == null) return null; if (eventId == null) return null;
DebugEventHistory de = allEvents[eventId]; DebugEventHistory de = allEvents[eventId];
if (de != null) { if (de != null) {
ArrayList<String> ret = new ArrayList<String>(); List<Map<String,String>> ret = new ArrayList<Map<String,String>>();
for (Event e : de.eventBuffer) { for (Event e : de.eventBuffer) {
ret.add(e.toString(de.einfo.eventClass, de.einfo.moduleEventName)); ret.add(e.getFormattedEvent(de.einfo.eventClass,
de.einfo.moduleEventName));
} }
return new DebugEventInfo(de.einfo, ret); return new DebugEventInfo(de.einfo, ret);
} }
...@@ -443,16 +446,22 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService { ...@@ -443,16 +446,22 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
} }
@Override @Override
public ArrayList<EventInfo> getEventList() { public List<String> getModuleList() {
ArrayList<EventInfo> eil = new ArrayList<EventInfo>(); List<String> el = new ArrayList<String>();
for (Map<String, Integer> eventMap : moduleEvents.values()) { el.addAll(moduleEvents.keySet());
for (Integer evId : eventMap.values()) { return el;
eil.add(allEvents[evId].einfo);
}
}
return eil;
} }
@Override
public List<String> getModuleEventList(String moduleName) {
if (!moduleEvents.containsKey(moduleName))
return Collections.emptyList();
List<String> el = new ArrayList<String>();
el.addAll(moduleEvents.get(moduleName).keySet());
return el;
}
protected void printEvents() { protected void printEvents() {
for (int eventId : currentEvents) { for (int eventId : currentEvents) {
DebugEventHistory de = allEvents[eventId]; DebugEventHistory de = allEvents[eventId];
......
...@@ -2,6 +2,8 @@ package net.floodlightcontroller.debugevent; ...@@ -2,6 +2,8 @@ package net.floodlightcontroller.debugevent;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import net.floodlightcontroller.debugevent.IDebugEventService.EventColumn; import net.floodlightcontroller.debugevent.IDebugEventService.EventColumn;
import net.floodlightcontroller.debugevent.IDebugEventService.EventFieldType; import net.floodlightcontroller.debugevent.IDebugEventService.EventFieldType;
...@@ -14,6 +16,7 @@ public class Event { ...@@ -14,6 +16,7 @@ public class Event {
long threadId; long threadId;
Object eventData; Object eventData;
private String returnString; private String returnString;
private Map<String, String> returnMap;
public Event(long timestamp, long threadId, Object eventData) { public Event(long timestamp, long threadId, Object eventData) {
super(); super();
...@@ -57,13 +60,12 @@ public class Event { ...@@ -57,13 +60,12 @@ public class Event {
eventClass.equals(eventData.getClass())) eventClass.equals(eventData.getClass()))
return this.returnString; return this.returnString;
this.returnString = new StringBuilder().append(moduleEventName) this.returnString = new StringBuilder()
.append(" [")
.append(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") .append(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.format(timestamp)) .format(timestamp))
.append(", threadId=").append(threadId).append(", ") .append(", threadId=").append(threadId).append(", ")
.append(customFormat(eventClass, eventData)) .append(customFormat(eventClass, eventData))
.append("]").toString(); .toString();
return this.returnString; return this.returnString;
} }
...@@ -106,4 +108,44 @@ public class Event { ...@@ -106,4 +108,44 @@ public class Event {
return (index > 0) ? retval.substring(0, index) : retval; return (index > 0) ? retval.substring(0, index) : retval;
} }
public Map<String, String> getFormattedEvent(Class<?> eventClass, String moduleEventName) {
if (returnMap != null && eventClass != null &&
eventClass.equals(eventData.getClass()))
return returnMap;
returnMap = new HashMap<String, String>();
returnMap.put("Timestamp", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.format(timestamp));
returnMap.put("threadId", String.valueOf(threadId));
customFormat(eventClass, eventData, returnMap);
return returnMap;
}
private void customFormat(Class<?> clazz, Object eventData,
Map<String, String> retMap) {
for (Field f : clazz.getDeclaredFields()) {
EventColumn ec = f.getAnnotation(EventColumn.class);
if (ec == null) continue;
f.setAccessible(true);
try {
Object obj = f.get(eventData);
if (ec.description() == EventFieldType.DPID) {
retMap.put(ec.name(), HexString.toHexString((Long) obj));
} else if (ec.description() == EventFieldType.MAC) {
retMap.put(ec.name(), HexString.toHexString((Long) obj, 6));
} else if (ec.description() == EventFieldType.IPv4) {
retMap.put(ec.name(), IPv4.fromIPv4Address((Integer) obj));
} else {
retMap.put(ec.name(), obj.toString());
}
} catch (ClassCastException e) {
retMap.put("Error", e.getMessage());
} catch (IllegalArgumentException e) {
retMap.put("Error", e.getMessage());
} catch (IllegalAccessException e) {
retMap.put("Error", e.getMessage());
}
}
}
} }
...@@ -4,8 +4,8 @@ import java.lang.annotation.ElementType; ...@@ -4,8 +4,8 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.debugevent.DebugEvent.EventInfo; import net.floodlightcontroller.debugevent.DebugEvent.EventInfo;
...@@ -55,9 +55,10 @@ public interface IDebugEventService extends IFloodlightService { ...@@ -55,9 +55,10 @@ public interface IDebugEventService extends IFloodlightService {
*/ */
public class DebugEventInfo { public class DebugEventInfo {
EventInfo eventInfo; EventInfo eventInfo;
ArrayList<String> events; List<Map<String,String>> events;
public DebugEventInfo(EventInfo eventInfo, ArrayList<String> eventHistory) { public DebugEventInfo(EventInfo eventInfo,
List<Map<String, String>> eventHistory) {
this.eventInfo = eventInfo; this.eventInfo = eventInfo;
this.events = eventHistory; this.events = eventHistory;
} }
...@@ -66,7 +67,7 @@ public interface IDebugEventService extends IFloodlightService { ...@@ -66,7 +67,7 @@ public interface IDebugEventService extends IFloodlightService {
return eventInfo; return eventInfo;
} }
public ArrayList<String> getEvents() { public List<Map<String,String>> getEvents() {
return events; return events;
} }
} }
...@@ -171,11 +172,15 @@ public interface IDebugEventService extends IFloodlightService { ...@@ -171,11 +172,15 @@ public interface IDebugEventService extends IFloodlightService {
public void resetSingleEvent(String moduleName, String eventName); public void resetSingleEvent(String moduleName, String eventName);
/** /**
* Retrieve information on all registered events * Retrieve a list of moduleNames registered for debug events or an empty
* * list if no events have been registered in the system
* @return the arraylist of event-info or an empty list if no events are registered
*/ */
public ArrayList<EventInfo> getEventList(); public List<String> getModuleList();
/**
* Returns a list of all events registered for a specific moduleName
* or a empty list
*/
public List<String> getModuleEventList(String moduleName);
} }
...@@ -11,7 +11,6 @@ import net.floodlightcontroller.core.module.FloodlightModuleContext; ...@@ -11,7 +11,6 @@ import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.debugevent.DebugEvent.EventInfo;
public class NullDebugEvent implements IFloodlightModule, IDebugEventService { public class NullDebugEvent implements IFloodlightModule, IDebugEventService {
...@@ -99,11 +98,6 @@ public class NullDebugEvent implements IFloodlightModule, IDebugEventService { ...@@ -99,11 +98,6 @@ public class NullDebugEvent implements IFloodlightModule, IDebugEventService {
} }
@Override
public ArrayList<EventInfo> getEventList() {
return new ArrayList<EventInfo>();
}
@Override @Override
public <T> IEventUpdater<T> public <T> IEventUpdater<T>
registerEvent(String moduleName, String eventName, registerEvent(String moduleName, String eventName,
...@@ -127,4 +121,14 @@ public class NullDebugEvent implements IFloodlightModule, IDebugEventService { ...@@ -127,4 +121,14 @@ public class NullDebugEvent implements IFloodlightModule, IDebugEventService {
} }
@Override
public List<String> getModuleList() {
return Collections.emptyList();
}
@Override
public List<String> getModuleEventList(String moduleName) {
return Collections.emptyList();
}
} }
...@@ -5,8 +5,8 @@ import java.util.HashMap; ...@@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.floodlightcontroller.debugevent.DebugEvent.EventInfo;
import net.floodlightcontroller.debugevent.IDebugEventService.DebugEventInfo; import net.floodlightcontroller.debugevent.IDebugEventService.DebugEventInfo;
import net.floodlightcontroller.debugevent.IDebugEventService.EventType;
import org.restlet.resource.Get; import org.restlet.resource.Get;
import org.restlet.resource.Post; import org.restlet.resource.Post;
...@@ -26,20 +26,67 @@ public class DebugEventResource extends DebugEventResourceBase { ...@@ -26,20 +26,67 @@ public class DebugEventResource extends DebugEventResourceBase {
* The output JSON model that contains the counter information * The output JSON model that contains the counter information
*/ */
public static class DebugEventInfoOutput { public static class DebugEventInfoOutput {
public Map<String, DebugEventInfo> eventMap = null; protected class DEInfo {
public List<EventInfo> eventList = null; private final boolean enabled;
private final int bufferCapacity;
private final EventType eventType;
private final String eventDesc;
private final String eventName;
private final String moduleName;
private final String[] metaData;
private final List<Map<String,String>> eventHistory;
DEInfo(DebugEventInfo dei) {
this.moduleName = dei.getEventInfo().getModuleName();
this.eventName = dei.getEventInfo().getEventName();
this.eventDesc = dei.getEventInfo().getEventDesc();
this.metaData = dei.getEventInfo().getMetaData();
this.enabled = dei.getEventInfo().isEnabled();
this.eventType = dei.getEventInfo().getEtype();
this.bufferCapacity = dei.getEventInfo().getBufferCapacity();
this.eventHistory = dei.getEvents();
}
public boolean isEnabled() {
return enabled;
}
public int getBufferCapacity() {
return bufferCapacity;
}
public String getEventDesc() {
return eventDesc;
}
public String getEventName() {
return eventName;
}
public String getModuleName() {
return moduleName;
}
public String[] getMetaData() {
return metaData;
}
public EventType getEventType() {
return eventType;
}
public List<Map<String,String>> getEventHistory() {
return eventHistory;
}
}
public Map<String, DEInfo> eventMap = null;
public List<String> names = null;
public String error = null; public String error = null;
DebugEventInfoOutput(boolean getList) { DebugEventInfoOutput(boolean getList) {
if (!getList) { if (!getList) {
eventMap = new HashMap<String, DebugEventInfo>(); eventMap = new HashMap<String, DEInfo>();
} }
} }
public Map<String, DebugEventInfo> getEventMap() { public Map<String, DEInfo> getEventMap() {
return eventMap; return eventMap;
} }
public List<EventInfo> getEventList() { public List<String> getNames() {
return eventList; return names;
} }
public String getError() { public String getError() {
return error; return error;
...@@ -177,23 +224,29 @@ public class DebugEventResource extends DebugEventResourceBase { ...@@ -177,23 +224,29 @@ public class DebugEventResource extends DebugEventResourceBase {
String param1 = (String)getRequestAttributes().get("param1"); String param1 = (String)getRequestAttributes().get("param1");
String param2 = (String)getRequestAttributes().get("param2"); String param2 = (String)getRequestAttributes().get("param2");
if (param1 == null && param2 == null) { if (param1 == null) {
output = new DebugEventInfoOutput(true); output = new DebugEventInfoOutput(true);
return listEvents(output); return listEvents(output);
} else if (param1.equals("all")) {
output = new DebugEventInfoOutput(false);
//populateEvents(debugEvent.getAllEventHistory(), output);
output.error = "Cannot retrieve all events - please select a specific event";
return output;
} }
output = new DebugEventInfoOutput(false);
if (param1 == null && param2 != null) { if (param2 == null) {
choice = Option.ERROR_BAD_PARAM; output = new DebugEventInfoOutput(true);
} else if (param1.equals("all")) {
choice = Option.ALL;
} else if (param2 == null) {
boolean isRegistered = debugEvent.containsModuleName(param1); boolean isRegistered = debugEvent.containsModuleName(param1);
if (isRegistered) { if (isRegistered) {
choice = Option.ONE_MODULE; return listEvents(param1, output);
} else { } else {
choice = Option.ERROR_BAD_MODULE_NAME; choice = Option.ERROR_BAD_MODULE_NAME;
} }
} else if (param2.equals("all")) {
output = new DebugEventInfoOutput(false);
//choice = Option.ONE_MODULE;
output.error = "Cannot retrieve all events - please select a specific event";
return output;
} else { } else {
// differentiate between disabled and non-existing events // differentiate between disabled and non-existing events
boolean isRegistered = debugEvent.containsModuleEventName(param1, param2); boolean isRegistered = debugEvent.containsModuleEventName(param1, param2);
...@@ -204,10 +257,8 @@ public class DebugEventResource extends DebugEventResourceBase { ...@@ -204,10 +257,8 @@ public class DebugEventResource extends DebugEventResourceBase {
} }
} }
output = new DebugEventInfoOutput(false);
switch (choice) { switch (choice) {
case ALL:
populateEvents(debugEvent.getAllEventHistory(), output);
break;
case ONE_MODULE: case ONE_MODULE:
populateEvents(debugEvent.getModuleEventHistory(param1), output); populateEvents(debugEvent.getModuleEventHistory(param1), output);
break; break;
...@@ -222,6 +273,7 @@ public class DebugEventResource extends DebugEventResourceBase { ...@@ -222,6 +273,7 @@ public class DebugEventResource extends DebugEventResourceBase {
output.error = "Event not registered"; output.error = "Event not registered";
break; break;
case ERROR_BAD_PARAM: case ERROR_BAD_PARAM:
default:
output.error = "Bad param"; output.error = "Bad param";
} }
...@@ -229,7 +281,13 @@ public class DebugEventResource extends DebugEventResourceBase { ...@@ -229,7 +281,13 @@ public class DebugEventResource extends DebugEventResourceBase {
} }
private DebugEventInfoOutput listEvents(DebugEventInfoOutput output) { private DebugEventInfoOutput listEvents(DebugEventInfoOutput output) {
output.eventList = debugEvent.getEventList(); output.names = debugEvent.getModuleList();
return output;
}
private DebugEventInfoOutput listEvents(String moduleName,
DebugEventInfoOutput output) {
output.names = debugEvent.getModuleEventList(moduleName);
return output; return output;
} }
...@@ -237,7 +295,7 @@ public class DebugEventResource extends DebugEventResourceBase { ...@@ -237,7 +295,7 @@ public class DebugEventResource extends DebugEventResourceBase {
DebugEventInfoOutput output) { DebugEventInfoOutput output) {
if (singleEventHistory != null) { if (singleEventHistory != null) {
output.eventMap.put(singleEventHistory.getEventInfo().getModuleEventName(), output.eventMap.put(singleEventHistory.getEventInfo().getModuleEventName(),
singleEventHistory); output.new DEInfo(singleEventHistory));
} }
} }
......
...@@ -2161,7 +2161,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, ...@@ -2161,7 +2161,7 @@ public class LinkDiscoveryManager implements IOFMessageListener,
try { try {
evDirectLink = debugEvents.registerEvent( evDirectLink = debugEvents.registerEvent(
getName(), "linkevent", PACKAGE, "linkevent",
"Direct OpenFlow links discovered or timed-out", "Direct OpenFlow links discovered or timed-out",
EventType.ALWAYS_LOG, DirectLinkEvent.class, 100); EventType.ALWAYS_LOG, DirectLinkEvent.class, 100);
} catch (MaxEventsRegistered e) { } catch (MaxEventsRegistered e) {
......
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