Shravan Ambati
Committed by Gerrit Code Review

Bug Fixes for Kafka Application(patchset #2)

1. Coding Errors in both the Converters
2. Pom file needs an import for com.google.protobuf
3. Port Object can be null in DeviceEvent. Added a check in the DeviceEventConverter

Change-Id: I28fe7e388b31bec7971b4ab1f431a3520162b53e
......@@ -167,7 +167,8 @@
org.onlab.packet.*,
org.onosproject.*,
org.onlab.util.*,
com.google.common.*
com.google.common.*,
com.google.protobuf.*
</Import-Package>
<Web-ContextPath>${web.context}</Web-ContextPath>
</instructions>
......
......@@ -40,7 +40,7 @@ class DeviceEventConverter implements EventConverter {
DeviceEvent deviceEvent = (DeviceEvent) event;
if (!deviceEventSubtypeSupported(deviceEvent)) {
if (!deviceEventTypeSupported(deviceEvent)) {
log.error("Unsupported Onos Device Event {}. There is no matching"
+ "proto Device Event type", deviceEvent.type().toString());
return null;
......@@ -55,7 +55,7 @@ class DeviceEventConverter implements EventConverter {
* @param event ONOS Device event
* @return true if there is a match and false otherwise
*/
private boolean deviceEventSubtypeSupported(DeviceEvent event) {
private boolean deviceEventTypeSupported(DeviceEvent event) {
DeviceEventType[] deviceEvents = DeviceEventType.values();
for (DeviceEventType deviceEventType : deviceEvents) {
if (deviceEventType.name().equals(event.type().name())) {
......@@ -67,9 +67,11 @@ class DeviceEventConverter implements EventConverter {
}
private DeviceNotification buildDeviceProtoMessage(DeviceEvent deviceEvent) {
DeviceNotification notification = DeviceNotification.newBuilder()
.setDeviceEventType(getProtoType(deviceEvent))
.setDevice(DeviceCore.newBuilder()
DeviceNotification.Builder notificationBuilder =
DeviceNotification.newBuilder();
DeviceCore deviceCore =
DeviceCore.newBuilder()
.setChassisId(deviceEvent.subject().chassisId().id()
.toString())
.setDeviceId(deviceEvent.subject().id().toString())
......@@ -77,18 +79,29 @@ class DeviceEventConverter implements EventConverter {
.setManufacturer(deviceEvent.subject().manufacturer())
.setSerialNumber(deviceEvent.subject().serialNumber())
.setSwVersion(deviceEvent.subject().swVersion())
.setType(DeviceType.valueOf(deviceEvent.type().name()))
.build())
.setPort(PortCore.newBuilder()
.setIsEnabled(deviceEvent.port().isEnabled())
.setPortNumber(deviceEvent.port().number().toString())
.setPortSpeed(deviceEvent.port().portSpeed())
.setType(PortType
.valueOf(deviceEvent.port().type().name()))
.build())
.build();
return notification;
.setType(DeviceType
.valueOf(deviceEvent.subject().type().name()))
.build();
PortCore portCore = null;
if (deviceEvent.port() != null) {
portCore =
PortCore.newBuilder()
.setIsEnabled(deviceEvent.port().isEnabled())
.setPortNumber(deviceEvent.port().number()
.toString())
.setPortSpeed(deviceEvent.port().portSpeed())
.setType(PortType
.valueOf(deviceEvent.port().type().name()))
.build();
notificationBuilder.setPort(portCore);
}
notificationBuilder.setDeviceEventType(getProtoType(deviceEvent))
.setDevice(deviceCore);
return notificationBuilder.build();
}
/**
......
......@@ -40,7 +40,7 @@ class LinkEventConverter implements EventConverter {
LinkEvent linkEvent = (LinkEvent) event;
if (!linkEventSubtypeSupported(linkEvent)) {
if (!linkEventTypeSupported(linkEvent)) {
log.error("Unsupported Onos Event {}. There is no matching"
+ "proto Event type", linkEvent.type().toString());
return null;
......@@ -49,9 +49,9 @@ class LinkEventConverter implements EventConverter {
return buildDeviceProtoMessage(linkEvent);
}
private boolean linkEventSubtypeSupported(LinkEvent event) {
LinkType[] kafkaLinkEvents = LinkType.values();
for (LinkType linkEventType : kafkaLinkEvents) {
private boolean linkEventTypeSupported(LinkEvent event) {
LinkEventType[] kafkaLinkEvents = LinkEventType.values();
for (LinkEventType linkEventType : kafkaLinkEvents) {
if (linkEventType.name().equals(event.type().name())) {
return true;
}
......