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 @@ ...@@ -167,7 +167,8 @@
167 org.onlab.packet.*, 167 org.onlab.packet.*,
168 org.onosproject.*, 168 org.onosproject.*,
169 org.onlab.util.*, 169 org.onlab.util.*,
170 - com.google.common.* 170 + com.google.common.*,
171 + com.google.protobuf.*
171 </Import-Package> 172 </Import-Package>
172 <Web-ContextPath>${web.context}</Web-ContextPath> 173 <Web-ContextPath>${web.context}</Web-ContextPath>
173 </instructions> 174 </instructions>
......
...@@ -40,7 +40,7 @@ class DeviceEventConverter implements EventConverter { ...@@ -40,7 +40,7 @@ class DeviceEventConverter implements EventConverter {
40 40
41 DeviceEvent deviceEvent = (DeviceEvent) event; 41 DeviceEvent deviceEvent = (DeviceEvent) event;
42 42
43 - if (!deviceEventSubtypeSupported(deviceEvent)) { 43 + if (!deviceEventTypeSupported(deviceEvent)) {
44 log.error("Unsupported Onos Device Event {}. There is no matching" 44 log.error("Unsupported Onos Device Event {}. There is no matching"
45 + "proto Device Event type", deviceEvent.type().toString()); 45 + "proto Device Event type", deviceEvent.type().toString());
46 return null; 46 return null;
...@@ -55,7 +55,7 @@ class DeviceEventConverter implements EventConverter { ...@@ -55,7 +55,7 @@ class DeviceEventConverter implements EventConverter {
55 * @param event ONOS Device event 55 * @param event ONOS Device event
56 * @return true if there is a match and false otherwise 56 * @return true if there is a match and false otherwise
57 */ 57 */
58 - private boolean deviceEventSubtypeSupported(DeviceEvent event) { 58 + private boolean deviceEventTypeSupported(DeviceEvent event) {
59 DeviceEventType[] deviceEvents = DeviceEventType.values(); 59 DeviceEventType[] deviceEvents = DeviceEventType.values();
60 for (DeviceEventType deviceEventType : deviceEvents) { 60 for (DeviceEventType deviceEventType : deviceEvents) {
61 if (deviceEventType.name().equals(event.type().name())) { 61 if (deviceEventType.name().equals(event.type().name())) {
...@@ -67,9 +67,11 @@ class DeviceEventConverter implements EventConverter { ...@@ -67,9 +67,11 @@ class DeviceEventConverter implements EventConverter {
67 } 67 }
68 68
69 private DeviceNotification buildDeviceProtoMessage(DeviceEvent deviceEvent) { 69 private DeviceNotification buildDeviceProtoMessage(DeviceEvent deviceEvent) {
70 - DeviceNotification notification = DeviceNotification.newBuilder() 70 + DeviceNotification.Builder notificationBuilder =
71 - .setDeviceEventType(getProtoType(deviceEvent)) 71 + DeviceNotification.newBuilder();
72 - .setDevice(DeviceCore.newBuilder() 72 +
73 + DeviceCore deviceCore =
74 + DeviceCore.newBuilder()
73 .setChassisId(deviceEvent.subject().chassisId().id() 75 .setChassisId(deviceEvent.subject().chassisId().id()
74 .toString()) 76 .toString())
75 .setDeviceId(deviceEvent.subject().id().toString()) 77 .setDeviceId(deviceEvent.subject().id().toString())
...@@ -77,18 +79,29 @@ class DeviceEventConverter implements EventConverter { ...@@ -77,18 +79,29 @@ class DeviceEventConverter implements EventConverter {
77 .setManufacturer(deviceEvent.subject().manufacturer()) 79 .setManufacturer(deviceEvent.subject().manufacturer())
78 .setSerialNumber(deviceEvent.subject().serialNumber()) 80 .setSerialNumber(deviceEvent.subject().serialNumber())
79 .setSwVersion(deviceEvent.subject().swVersion()) 81 .setSwVersion(deviceEvent.subject().swVersion())
80 - .setType(DeviceType.valueOf(deviceEvent.type().name())) 82 + .setType(DeviceType
81 - .build()) 83 + .valueOf(deviceEvent.subject().type().name()))
82 - .setPort(PortCore.newBuilder() 84 + .build();
83 - .setIsEnabled(deviceEvent.port().isEnabled()) 85 +
84 - .setPortNumber(deviceEvent.port().number().toString()) 86 + PortCore portCore = null;
85 - .setPortSpeed(deviceEvent.port().portSpeed()) 87 + if (deviceEvent.port() != null) {
86 - .setType(PortType 88 + portCore =
87 - .valueOf(deviceEvent.port().type().name())) 89 + PortCore.newBuilder()
88 - .build()) 90 + .setIsEnabled(deviceEvent.port().isEnabled())
89 - .build(); 91 + .setPortNumber(deviceEvent.port().number()
90 - 92 + .toString())
91 - return notification; 93 + .setPortSpeed(deviceEvent.port().portSpeed())
94 + .setType(PortType
95 + .valueOf(deviceEvent.port().type().name()))
96 + .build();
97 +
98 + notificationBuilder.setPort(portCore);
99 + }
100 +
101 + notificationBuilder.setDeviceEventType(getProtoType(deviceEvent))
102 + .setDevice(deviceCore);
103 +
104 + return notificationBuilder.build();
92 } 105 }
93 106
94 /** 107 /**
......
...@@ -40,7 +40,7 @@ class LinkEventConverter implements EventConverter { ...@@ -40,7 +40,7 @@ class LinkEventConverter implements EventConverter {
40 40
41 LinkEvent linkEvent = (LinkEvent) event; 41 LinkEvent linkEvent = (LinkEvent) event;
42 42
43 - if (!linkEventSubtypeSupported(linkEvent)) { 43 + if (!linkEventTypeSupported(linkEvent)) {
44 log.error("Unsupported Onos Event {}. There is no matching" 44 log.error("Unsupported Onos Event {}. There is no matching"
45 + "proto Event type", linkEvent.type().toString()); 45 + "proto Event type", linkEvent.type().toString());
46 return null; 46 return null;
...@@ -49,9 +49,9 @@ class LinkEventConverter implements EventConverter { ...@@ -49,9 +49,9 @@ class LinkEventConverter implements EventConverter {
49 return buildDeviceProtoMessage(linkEvent); 49 return buildDeviceProtoMessage(linkEvent);
50 } 50 }
51 51
52 - private boolean linkEventSubtypeSupported(LinkEvent event) { 52 + private boolean linkEventTypeSupported(LinkEvent event) {
53 - LinkType[] kafkaLinkEvents = LinkType.values(); 53 + LinkEventType[] kafkaLinkEvents = LinkEventType.values();
54 - for (LinkType linkEventType : kafkaLinkEvents) { 54 + for (LinkEventType linkEventType : kafkaLinkEvents) {
55 if (linkEventType.name().equals(event.type().name())) { 55 if (linkEventType.name().equals(event.type().name())) {
56 return true; 56 return true;
57 } 57 }
......