Sanjana Agarwal
Committed by Gerrit Code Review

Made changes as per comments.

kafkaProducer is now non-static.

TODO: KafkaPublisherManager Service and not Singleton.
Kafka event publishing.

Change-Id: I5ec20a6e4950c38e822468d343521ab77475b7d3
Showing 36 changed files with 710 additions and 284 deletions
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
38 <artifactId>protobuf-java</artifactId> 38 <artifactId>protobuf-java</artifactId>
39 <version>3.0.0-beta-2</version> 39 <version>3.0.0-beta-2</version>
40 </dependency> 40 </dependency>
41 +
41 </dependencies> 42 </dependencies>
42 43
43 <build> 44 <build>
......
1 +/**
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.kafkaintegration.api;
18 +
19 +import org.onosproject.event.Event;
20 +import org.onosproject.kafkaintegration.api.dto.OnosEvent;
21 +
22 +/**
23 + * API for conversion of various ONOS events to Protobuf.
24 + *
25 + */
26 +public interface EventConversionService {
27 + OnosEvent convertEvent(Event<?, ?> event);
28 +}
...@@ -16,16 +16,19 @@ package org.onosproject.kafkaintegration.api; ...@@ -16,16 +16,19 @@ package org.onosproject.kafkaintegration.api;
16 16
17 import org.onosproject.kafkaintegration.api.dto.EventSubscriber; 17 import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
18 import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId; 18 import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId;
19 +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
19 import org.onosproject.kafkaintegration.errors.InvalidApplicationException; 20 import org.onosproject.kafkaintegration.errors.InvalidApplicationException;
20 import org.onosproject.kafkaintegration.errors.InvalidGroupIdException; 21 import org.onosproject.kafkaintegration.errors.InvalidGroupIdException;
21 22
22 import com.google.common.annotations.Beta; 23 import com.google.common.annotations.Beta;
23 24
25 +import java.util.List;
26 +
24 /** 27 /**
25 * APIs for subscribing to Onos Event Messages. 28 * APIs for subscribing to Onos Event Messages.
26 */ 29 */
27 @Beta 30 @Beta
28 -public interface EventExporterService { 31 +public interface EventSubscriptionService {
29 32
30 /** 33 /**
31 * Registers the external application to receive events generated in ONOS. 34 * Registers the external application to receive events generated in ONOS.
...@@ -61,4 +64,12 @@ public interface EventExporterService { ...@@ -61,4 +64,12 @@ public interface EventExporterService {
61 */ 64 */
62 void unsubscribe(EventSubscriber subscriber) 65 void unsubscribe(EventSubscriber subscriber)
63 throws InvalidGroupIdException, InvalidApplicationException; 66 throws InvalidGroupIdException, InvalidApplicationException;
67 +
68 + /**
69 + * Returns the event subscriber for various event types.
70 + *
71 + * @param type ONOS event type.
72 + * @return List of event subscribers
73 + */
74 + List<EventSubscriber> getEventSubscribers(Type type);
64 } 75 }
......
1 +/**
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.kafkaintegration.api;
18 +
19 +import com.google.protobuf.GeneratedMessage;
20 +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
21 +
22 +/**
23 + * API for dispatching ONOS events.
24 + */
25 +public interface KafkaPublisherService {
26 +
27 + /**
28 + * Publish the ONOS Event to all listeners.
29 + *
30 + * @param eventType the ONOS eventtype
31 + * @param message generated Protocol buffer message from ONOS event data
32 + */
33 + void publish(Type eventType, GeneratedMessage message);
34 +}
...@@ -19,7 +19,7 @@ import org.onosproject.event.AbstractEvent; ...@@ -19,7 +19,7 @@ import org.onosproject.event.AbstractEvent;
19 import com.google.protobuf.GeneratedMessage; 19 import com.google.protobuf.GeneratedMessage;
20 20
21 /** 21 /**
22 - * Represents the converted Onos Event data into GPB format. 22 + * Represents the converted Onos Event data into protobuf format.
23 * 23 *
24 */ 24 */
25 public class OnosEvent extends AbstractEvent<OnosEvent.Type, GeneratedMessage> { 25 public class OnosEvent extends AbstractEvent<OnosEvent.Type, GeneratedMessage> {
...@@ -38,6 +38,19 @@ public class OnosEvent extends AbstractEvent<OnosEvent.Type, GeneratedMessage> { ...@@ -38,6 +38,19 @@ public class OnosEvent extends AbstractEvent<OnosEvent.Type, GeneratedMessage> {
38 * List of Event Types supported. 38 * List of Event Types supported.
39 */ 39 */
40 public enum Type { 40 public enum Type {
41 - DEVICE, LINK; 41 + /**
42 + * Signifies Device events.
43 + */
44 + DEVICE("DEVICE"),
45 +
46 + /**
47 + * Signifies Link events.
48 + */
49 + LINK("LINK");
50 + public String typeName;
51 +
52 + Type(String name) {
53 + typeName = name;
54 + }
42 } 55 }
43 } 56 }
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
19 featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" 19 featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
20 features="${project.artifactId}" apps="org.onosproject.incubator.protobuf"> 20 features="${project.artifactId}" apps="org.onosproject.incubator.protobuf">
21 <description>${project.description}</description> 21 <description>${project.description}</description>
22 - <artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact> 22 +
23 <artifact>mvn:${project.groupId}/onos-app-kafka-api/${project.version}</artifact> 23 <artifact>mvn:${project.groupId}/onos-app-kafka-api/${project.version}</artifact>
24 + <artifact>mvn:${project.groupId}/onos-app-kafka-core/${project.version}</artifact>
25 + <artifact>mvn:${project.groupId}/onos-app-kafka-web/${project.version}</artifact>
26 + <artifact>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.kafka-clients/0.8.2.2_1</artifact>
24 </app> 27 </app>
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
19 description="${project.description}"> 19 description="${project.description}">
20 <feature>onos-api</feature> 20 <feature>onos-api</feature>
21 <bundle>mvn:${project.groupId}/onos-app-kafka-api/${project.version}</bundle> 21 <bundle>mvn:${project.groupId}/onos-app-kafka-api/${project.version}</bundle>
22 - <bundle>mvn:${project.groupId}/onos-app-kafka/${project.version}</bundle> 22 + <bundle>mvn:${project.groupId}/onos-app-kafka-core/${project.version}</bundle>
23 + <bundle>mvn:${project.groupId}/onos-app-kafka-web/${project.version}</bundle>
24 + <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.kafka-clients/0.8.2.2_1</bundle>
23 </feature> 25 </feature>
24 </features> 26 </features>
......
...@@ -26,12 +26,6 @@ ...@@ -26,12 +26,6 @@
26 26
27 <artifactId>onos-app-kafka</artifactId> 27 <artifactId>onos-app-kafka</artifactId>
28 28
29 - <packaging>bundle</packaging>
30 - <description>
31 - Kafka Integration Application.
32 - This will export ONOS Events to Northbound Kafka Server.
33 - </description>
34 -
35 <properties> 29 <properties>
36 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 30 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
37 <onos.version>${project.version}</onos.version> 31 <onos.version>${project.version}</onos.version>
...@@ -41,21 +35,18 @@ ...@@ -41,21 +35,18 @@
41 <web.context>/onos/kafka</web.context> 35 <web.context>/onos/kafka</web.context>
42 <api.version>1.0.0</api.version> 36 <api.version>1.0.0</api.version>
43 <api.package>org.onosproject.kafkaintegration.rest</api.package> 37 <api.package>org.onosproject.kafkaintegration.rest</api.package>
44 - <api.title>Kafka Integration Application REST API</api.title>
45 - <api.description>
46 - APIs for subscribing to Events generated by ONOS
47 - </api.description>
48 <onos.app.category>Utility</onos.app.category> 38 <onos.app.category>Utility</onos.app.category>
49 <onos.app.url>https://wiki.onosproject.org/display/ONOS/Kafka+Integration</onos.app.url> 39 <onos.app.url>https://wiki.onosproject.org/display/ONOS/Kafka+Integration</onos.app.url>
50 - <onos.app.readme>Export ONOS events to a Northbound Kafka server</onos.app.readme>
51 <onos.app.requires>org.onosproject.incubator.protobuf</onos.app.requires> 40 <onos.app.requires>org.onosproject.incubator.protobuf</onos.app.requires>
52 </properties> 41 </properties>
53 42
54 - <dependencies> 43 + <packaging>pom</packaging>
55 - <dependency> 44 + <description>
56 - <groupId>org.onosproject</groupId> 45 + Kafka Integration Application.
57 - <artifactId>onos-api</artifactId> 46 + This will export ONOS Events to Northbound Kafka Server.
58 - </dependency> 47 + </description>
48 +
49 + <dependencies>
59 50
60 <dependency> 51 <dependency>
61 <groupId>org.onosproject</groupId> 52 <groupId>org.onosproject</groupId>
...@@ -65,168 +56,22 @@ ...@@ -65,168 +56,22 @@
65 56
66 <dependency> 57 <dependency>
67 <groupId>org.onosproject</groupId> 58 <groupId>org.onosproject</groupId>
68 - <artifactId>onos-incubator-protobuf</artifactId> 59 + <artifactId>onos-app-kafka-core</artifactId>
69 <version>${project.version}</version> 60 <version>${project.version}</version>
70 </dependency> 61 </dependency>
71 62
72 <dependency> 63 <dependency>
73 <groupId>org.onosproject</groupId> 64 <groupId>org.onosproject</groupId>
74 - <artifactId>onlab-osgi</artifactId> 65 + <artifactId>onos-app-kafka-web</artifactId>
75 - </dependency>
76 -
77 - <dependency>
78 - <groupId>org.onosproject</groupId>
79 - <artifactId>onos-rest</artifactId>
80 <version>${project.version}</version> 66 <version>${project.version}</version>
81 </dependency> 67 </dependency>
82 68
69 + <!--Also need to update the app.xml and the features.xml -->
83 <dependency> 70 <dependency>
84 - <groupId>junit</groupId> 71 + <groupId>org.apache.servicemix.bundles</groupId>
85 - <artifactId>junit</artifactId> 72 + <artifactId>org.apache.servicemix.bundles.kafka-clients</artifactId>
86 - <scope>test</scope> 73 + <version>0.8.2.2_1</version>
87 - </dependency>
88 -
89 - <dependency>
90 - <groupId>org.onosproject</groupId>
91 - <artifactId>onos-api</artifactId>
92 - <scope>test</scope>
93 - <classifier>tests</classifier>
94 </dependency> 74 </dependency>
95 75
96 - <dependency>
97 - <groupId>javax.ws.rs</groupId>
98 - <artifactId>javax.ws.rs-api</artifactId>
99 - <version>2.0.1</version>
100 - </dependency>
101 -
102 - <dependency>
103 - <groupId>com.google.protobuf</groupId>
104 - <artifactId>protobuf-java</artifactId>
105 - <version>3.0.0-beta-2</version>
106 - </dependency>
107 -
108 - <dependency>
109 - <groupId>org.codehaus.jackson</groupId>
110 - <artifactId>jackson-core-asl</artifactId>
111 - <version>1.9.13</version>
112 - </dependency>
113 -
114 - <dependency>
115 - <groupId>org.codehaus.jackson</groupId>
116 - <artifactId>jackson-mapper-asl</artifactId>
117 - <version>1.9.13</version>
118 - </dependency>
119 -
120 - <dependency>
121 - <groupId>org.glassfish.jersey.containers</groupId>
122 - <artifactId>jersey-container-servlet</artifactId>
123 - </dependency>
124 - <dependency>
125 - <groupId>com.fasterxml.jackson.core</groupId>
126 - <artifactId>jackson-annotations</artifactId>
127 - </dependency>
128 -
129 - <dependency>
130 - <groupId>org.onosproject</groupId>
131 - <artifactId>onos-core-serializers</artifactId>
132 - <version>${project.version}</version>
133 - </dependency>
134 -
135 - <dependency>
136 - <groupId>org.apache.felix</groupId>
137 - <artifactId>org.apache.felix.scr.annotations</artifactId>
138 - <scope>provided</scope>
139 - </dependency>
140 </dependencies> 76 </dependencies>
141 - 77 +</project>
142 - <build>
143 - <plugins>
144 - <plugin>
145 - <groupId>org.apache.felix</groupId>
146 - <artifactId>maven-bundle-plugin</artifactId>
147 - <extensions>true</extensions>
148 - <configuration>
149 - <instructions>
150 - <Bundle-SymbolicName>
151 - ${project.groupId}.${project.artifactId}
152 - </Bundle-SymbolicName>
153 - <_wab>src/main/webapp/</_wab>
154 - <Include-Resource>
155 - WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
156 - {maven-resources}
157 - </Include-Resource>
158 - <Import-Package>
159 - org.slf4j,
160 - org.osgi.framework,
161 - javax.ws.rs,
162 - javax.ws.rs.core,
163 - org.glassfish.jersey.servlet,
164 - com.fasterxml.jackson.databind,
165 - com.fasterxml.jackson.databind.node,
166 - com.fasterxml.jackson.core,
167 - org.onlab.packet.*,
168 - org.onosproject.*,
169 - org.onlab.util.*,
170 - com.google.common.*,
171 - com.google.protobuf.*
172 - </Import-Package>
173 - <Web-ContextPath>${web.context}</Web-ContextPath>
174 - </instructions>
175 - </configuration>
176 - </plugin>
177 - <plugin>
178 - <groupId>org.apache.maven.plugins</groupId>
179 - <artifactId>maven-compiler-plugin</artifactId>
180 - <configuration>
181 - <source>1.8</source>
182 - <target>1.8</target>
183 - </configuration>
184 - </plugin>
185 - <plugin>
186 - <groupId>org.apache.felix</groupId>
187 - <artifactId>maven-scr-plugin</artifactId>
188 - <executions>
189 - <execution>
190 - <id>generate-scr-srcdescriptor</id>
191 - <goals>
192 - <goal>scr</goal>
193 - </goals>
194 - </execution>
195 - </executions>
196 - <configuration>
197 - <supportedProjectTypes>
198 - <supportedProjectType>bundle</supportedProjectType>
199 - <supportedProjectType>war</supportedProjectType>
200 - </supportedProjectTypes>
201 - </configuration>
202 - </plugin>
203 - <plugin>
204 - <groupId>org.onosproject</groupId>
205 - <artifactId>onos-maven-plugin</artifactId>
206 - <executions>
207 - <execution>
208 - <id>cfg</id>
209 - <phase>generate-resources</phase>
210 - <goals>
211 - <goal>cfg</goal>
212 - </goals>
213 - </execution>
214 - <execution>
215 - <id>swagger</id>
216 - <goals>
217 - <goal>swagger</goal>
218 - </goals>
219 - </execution>
220 - <execution>
221 - <id>app</id>
222 - <phase>package</phase>
223 - <goals>
224 - <goal>app</goal>
225 - </goals>
226 - </execution>
227 - </executions>
228 - </plugin>
229 - </plugins>
230 - </build>
231 -
232 -</project>
...\ No newline at end of file ...\ No newline at end of file
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20 +
21 + <parent>
22 + <groupId>org.onosproject</groupId>
23 + <artifactId>onos-kafka</artifactId>
24 + <version>1.7.0-SNAPSHOT</version>
25 + </parent>
26 + <modelVersion>4.0.0</modelVersion>
27 +
28 + <artifactId>onos-app-kafka-core</artifactId>
29 +
30 + <packaging>bundle</packaging>
31 + <description>
32 + Kafka Integration Application.
33 + This module is exclusive of REST calls and is only for the implementation of Apache Kafka.
34 + </description>
35 +
36 + <dependencies>
37 +
38 + <dependency>
39 + <groupId>org.onosproject</groupId>
40 + <artifactId>onos-api</artifactId>
41 + </dependency>
42 +
43 + <dependency>
44 + <groupId>org.onosproject</groupId>
45 + <artifactId>onos-app-kafka-api</artifactId>
46 + <version>${project.version}</version>
47 + </dependency>
48 +
49 + <dependency>
50 + <groupId>org.osgi</groupId>
51 + <artifactId>org.osgi.core</artifactId>
52 + <version>4.3.1</version>
53 + </dependency>
54 +
55 + <dependency>
56 + <groupId>org.apache.servicemix.bundles</groupId>
57 + <artifactId>org.apache.servicemix.bundles.kafka-clients</artifactId>
58 + <version>0.8.2.2_1</version>
59 + </dependency>
60 +
61 + <dependency>
62 + <groupId>org.apache.felix</groupId>
63 + <artifactId>org.apache.felix.scr.annotations</artifactId>
64 + <scope>provided</scope>
65 + </dependency>
66 +
67 + <dependency>
68 + <groupId>org.onosproject</groupId>
69 + <artifactId>onos-incubator-protobuf</artifactId>
70 + <version>${project.version}</version>
71 + </dependency>
72 +
73 + <dependency>
74 + <groupId>com.google.protobuf</groupId>
75 + <artifactId>protobuf-java</artifactId>
76 + <version>3.0.0-beta-2</version>
77 + </dependency>
78 + <dependency>
79 + <groupId>org.onosproject</groupId>
80 + <artifactId>onos-app-kafka-web</artifactId>
81 + <version>${project.version}</version>
82 + </dependency>
83 +
84 + <dependency>
85 + <groupId>org.osgi</groupId>
86 + <artifactId>org.osgi.compendium</artifactId>
87 + </dependency>
88 +
89 + </dependencies>
90 +
91 + <build>
92 + <plugins>
93 + <plugin>
94 + <groupId>org.apache.felix</groupId>
95 + <artifactId>maven-bundle-plugin</artifactId>
96 + <extensions>true</extensions>
97 + </plugin>
98 +
99 + <plugin>
100 + <groupId>org.apache.felix</groupId>
101 + <artifactId>maven-scr-plugin</artifactId>
102 + <executions>
103 + <execution>
104 + <id>generate-scr-srcdescriptor</id>
105 + <goals>
106 + <goal>scr</goal>
107 + </goals>
108 + </execution>
109 + </executions>
110 + <configuration>
111 + <supportedProjectTypes>
112 + <supportedProjectType>bundle</supportedProjectType>
113 + <supportedProjectType>war</supportedProjectType>
114 + </supportedProjectTypes>
115 + </configuration>
116 + </plugin>
117 + </plugins>
118 + </build>
119 +</project>
...\ No newline at end of file ...\ No newline at end of file
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
14 */ 14 */
15 package org.onosproject.kafkaintegration.converter; 15 package org.onosproject.kafkaintegration.converter;
16 16
17 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; 17 +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
18 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
19 18
20 import java.util.HashMap; 19 import java.util.HashMap;
21 import java.util.Map; 20 import java.util.Map;
22 21
23 -import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;; 22 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
23 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
24 24
25 /** 25 /**
26 * Returns the appropriate converter object based on the ONOS event type. 26 * Returns the appropriate converter object based on the ONOS event type.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
14 */ 14 */
15 package org.onosproject.kafkaintegration.converter; 15 package org.onosproject.kafkaintegration.converter;
16 16
17 +import com.google.protobuf.GeneratedMessage;
17 import org.onosproject.event.Event; 18 import org.onosproject.event.Event;
18 import org.onosproject.grpc.net.Device.DeviceCore; 19 import org.onosproject.grpc.net.Device.DeviceCore;
19 import org.onosproject.grpc.net.Device.DeviceType; 20 import org.onosproject.grpc.net.Device.DeviceType;
...@@ -25,13 +26,10 @@ import org.onosproject.net.device.DeviceEvent; ...@@ -25,13 +26,10 @@ import org.onosproject.net.device.DeviceEvent;
25 import org.slf4j.Logger; 26 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory; 27 import org.slf4j.LoggerFactory;
27 28
28 -import com.google.protobuf.GeneratedMessage;
29 -
30 /** 29 /**
31 - * Converts ONOS Device event message to GPB format. 30 + * Converts ONOS Device event message to protobuf format.
32 - *
33 */ 31 */
34 -class DeviceEventConverter implements EventConverter { 32 +public class DeviceEventConverter implements EventConverter {
35 33
36 private final Logger log = LoggerFactory.getLogger(getClass()); 34 private final Logger log = LoggerFactory.getLogger(getClass());
37 35
...@@ -73,14 +71,14 @@ class DeviceEventConverter implements EventConverter { ...@@ -73,14 +71,14 @@ class DeviceEventConverter implements EventConverter {
73 DeviceCore deviceCore = 71 DeviceCore deviceCore =
74 DeviceCore.newBuilder() 72 DeviceCore.newBuilder()
75 .setChassisId(deviceEvent.subject().chassisId().id() 73 .setChassisId(deviceEvent.subject().chassisId().id()
76 - .toString()) 74 + .toString())
77 .setDeviceId(deviceEvent.subject().id().toString()) 75 .setDeviceId(deviceEvent.subject().id().toString())
78 .setHwVersion(deviceEvent.subject().hwVersion()) 76 .setHwVersion(deviceEvent.subject().hwVersion())
79 .setManufacturer(deviceEvent.subject().manufacturer()) 77 .setManufacturer(deviceEvent.subject().manufacturer())
80 .setSerialNumber(deviceEvent.subject().serialNumber()) 78 .setSerialNumber(deviceEvent.subject().serialNumber())
81 .setSwVersion(deviceEvent.subject().swVersion()) 79 .setSwVersion(deviceEvent.subject().swVersion())
82 .setType(DeviceType 80 .setType(DeviceType
83 - .valueOf(deviceEvent.subject().type().name())) 81 + .valueOf(deviceEvent.subject().type().name()))
84 .build(); 82 .build();
85 83
86 PortCore portCore = null; 84 PortCore portCore = null;
...@@ -89,10 +87,10 @@ class DeviceEventConverter implements EventConverter { ...@@ -89,10 +87,10 @@ class DeviceEventConverter implements EventConverter {
89 PortCore.newBuilder() 87 PortCore.newBuilder()
90 .setIsEnabled(deviceEvent.port().isEnabled()) 88 .setIsEnabled(deviceEvent.port().isEnabled())
91 .setPortNumber(deviceEvent.port().number() 89 .setPortNumber(deviceEvent.port().number()
92 - .toString()) 90 + .toString())
93 .setPortSpeed(deviceEvent.port().portSpeed()) 91 .setPortSpeed(deviceEvent.port().portSpeed())
94 .setType(PortType 92 .setType(PortType
95 - .valueOf(deviceEvent.port().type().name())) 93 + .valueOf(deviceEvent.port().type().name()))
96 .build(); 94 .build();
97 95
98 notificationBuilder.setPort(portCore); 96 notificationBuilder.setPort(portCore);
......
...@@ -20,7 +20,7 @@ import com.google.protobuf.GeneratedMessage; ...@@ -20,7 +20,7 @@ import com.google.protobuf.GeneratedMessage;
20 20
21 /** 21 /**
22 * 22 *
23 - * APIs for converting between ONOS event objects and GPB data objects. 23 + * APIs for converting between ONOS event objects and protobuf data objects.
24 * 24 *
25 */ 25 */
26 public interface EventConverter { 26 public interface EventConverter {
...@@ -30,7 +30,7 @@ public interface EventConverter { ...@@ -30,7 +30,7 @@ public interface EventConverter {
30 * to Kafka. 30 * to Kafka.
31 * 31 *
32 * @param event ONOS Event object 32 * @param event ONOS Event object
33 - * @return converted data in GPB format. 33 + * @return converted data in protobuf format.
34 */ 34 */
35 - public GeneratedMessage convertToProtoMessage(Event<?, ?> event); 35 + GeneratedMessage convertToProtoMessage(Event<?, ?> event);
36 } 36 }
......
...@@ -28,10 +28,9 @@ import org.slf4j.LoggerFactory; ...@@ -28,10 +28,9 @@ import org.slf4j.LoggerFactory;
28 import com.google.protobuf.GeneratedMessage; 28 import com.google.protobuf.GeneratedMessage;
29 29
30 /** 30 /**
31 - * Converts for ONOS Link event message to GPB format. 31 + * Converts for ONOS Link event message to protobuf format.
32 - *
33 */ 32 */
34 -class LinkEventConverter implements EventConverter { 33 +public class LinkEventConverter implements EventConverter {
35 34
36 private final Logger log = LoggerFactory.getLogger(getClass()); 35 private final Logger log = LoggerFactory.getLogger(getClass());
37 36
...@@ -41,7 +40,7 @@ class LinkEventConverter implements EventConverter { ...@@ -41,7 +40,7 @@ class LinkEventConverter implements EventConverter {
41 LinkEvent linkEvent = (LinkEvent) event; 40 LinkEvent linkEvent = (LinkEvent) event;
42 41
43 if (!linkEventTypeSupported(linkEvent)) { 42 if (!linkEventTypeSupported(linkEvent)) {
44 - log.error("Unsupported Onos Event {}. There is no matching" 43 + log.error("Unsupported Onos Event {}. There is no matching "
45 + "proto Event type", linkEvent.type().toString()); 44 + "proto Event type", linkEvent.type().toString());
46 return null; 45 return null;
47 } 46 }
...@@ -56,7 +55,6 @@ class LinkEventConverter implements EventConverter { ...@@ -56,7 +55,6 @@ class LinkEventConverter implements EventConverter {
56 return true; 55 return true;
57 } 56 }
58 } 57 }
59 -
60 return false; 58 return false;
61 } 59 }
62 60
...@@ -66,8 +64,7 @@ class LinkEventConverter implements EventConverter { ...@@ -66,8 +64,7 @@ class LinkEventConverter implements EventConverter {
66 .setLink(LinkCore.newBuilder() 64 .setLink(LinkCore.newBuilder()
67 .setState(LinkState 65 .setState(LinkState
68 .valueOf(linkEvent.subject().state().name())) 66 .valueOf(linkEvent.subject().state().name()))
69 - .setType(LinkType 67 + .setType(LinkType.valueOf(linkEvent.subject().type().name()))
70 - .valueOf(linkEvent.subject().type().name()))
71 .setDst(ConnectPoint.newBuilder() 68 .setDst(ConnectPoint.newBuilder()
72 .setDeviceId(linkEvent.subject().dst() 69 .setDeviceId(linkEvent.subject().dst()
73 .deviceId().toString()) 70 .deviceId().toString())
......
1 +/**
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.kafkaintegration.impl;
18 +
19 +import org.apache.felix.scr.annotations.Activate;
20 +import org.apache.felix.scr.annotations.Component;
21 +import org.apache.felix.scr.annotations.Deactivate;
22 +import org.apache.felix.scr.annotations.Service;
23 +import org.onosproject.event.Event;
24 +import org.onosproject.kafkaintegration.api.EventConversionService;
25 +import org.onosproject.kafkaintegration.api.dto.OnosEvent;
26 +import org.onosproject.kafkaintegration.converter.DeviceEventConverter;
27 +import org.onosproject.kafkaintegration.converter.EventConverter;
28 +import org.onosproject.kafkaintegration.converter.LinkEventConverter;
29 +import org.onosproject.net.device.DeviceEvent;
30 +import org.onosproject.net.link.LinkEvent;
31 +import org.slf4j.Logger;
32 +import org.slf4j.LoggerFactory;
33 +
34 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
35 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
36 +
37 +/**
38 + * Implementation of Event Conversion Service.
39 + *
40 + */
41 +@Component(immediate = true)
42 +@Service
43 +public class EventConversionManager implements EventConversionService {
44 +
45 + private final Logger log = LoggerFactory.getLogger(getClass());
46 + private EventConverter deviceEventConverter;
47 + private EventConverter linkEventConverter;
48 +
49 + @Activate
50 + protected void activate() {
51 + deviceEventConverter = new DeviceEventConverter();
52 + linkEventConverter = new LinkEventConverter();
53 +
54 + log.info("Started");
55 + }
56 +
57 + @Deactivate
58 + protected void deactivate() {
59 + log.info("Stopped");
60 + }
61 +
62 + @Override
63 + public OnosEvent convertEvent(Event<?, ?> event) {
64 + if (event instanceof DeviceEvent) {
65 + return new OnosEvent(DEVICE, deviceEventConverter.convertToProtoMessage(event));
66 + } else if (event instanceof LinkEvent) {
67 + return new OnosEvent(LINK, linkEventConverter.convertToProtoMessage(event));
68 + } else {
69 + throw new IllegalArgumentException("Unsupported event type");
70 + }
71 + }
72 +}
1 -/* 1 +/**
2 * Copyright 2016-present Open Networking Laboratory 2 * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -15,18 +15,7 @@ ...@@ -15,18 +15,7 @@
15 */ 15 */
16 package org.onosproject.kafkaintegration.impl; 16 package org.onosproject.kafkaintegration.impl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import com.google.common.collect.ImmutableList;
19 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
20 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
21 -
22 -import org.onosproject.kafkaintegration.api.dto.DefaultEventSubscriber;
23 -import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
24 -
25 -import java.util.ArrayList;
26 -import java.util.List;
27 -import java.util.Map;
28 -import java.util.UUID;
29 -
30 import org.apache.felix.scr.annotations.Activate; 19 import org.apache.felix.scr.annotations.Activate;
31 import org.apache.felix.scr.annotations.Component; 20 import org.apache.felix.scr.annotations.Component;
32 import org.apache.felix.scr.annotations.Deactivate; 21 import org.apache.felix.scr.annotations.Deactivate;
...@@ -35,7 +24,9 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -35,7 +24,9 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
35 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
36 import org.onosproject.core.ApplicationId; 25 import org.onosproject.core.ApplicationId;
37 import org.onosproject.core.CoreService; 26 import org.onosproject.core.CoreService;
38 -import org.onosproject.kafkaintegration.api.EventExporterService; 27 +import org.onosproject.kafkaintegration.api.EventSubscriptionService;
28 +import org.onosproject.kafkaintegration.api.dto.DefaultEventSubscriber;
29 +import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
39 import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId; 30 import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId;
40 import org.onosproject.kafkaintegration.api.dto.OnosEvent; 31 import org.onosproject.kafkaintegration.api.dto.OnosEvent;
41 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; 32 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
...@@ -51,13 +42,22 @@ import org.onosproject.store.service.StorageService; ...@@ -51,13 +42,22 @@ import org.onosproject.store.service.StorageService;
51 import org.slf4j.Logger; 42 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory; 43 import org.slf4j.LoggerFactory;
53 44
45 +import java.util.ArrayList;
46 +import java.util.List;
47 +import java.util.Map;
48 +import java.util.UUID;
49 +
50 +import static com.google.common.base.Preconditions.checkNotNull;
51 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
52 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
53 +
54 /** 54 /**
55 - * Implementation of Event Exporter Service. 55 + * Implementation of Event Subscription Manager.
56 * 56 *
57 */ 57 */
58 @Component(immediate = true) 58 @Component(immediate = true)
59 @Service 59 @Service
60 -public class EventExporterManager implements EventExporterService { 60 +public class EventSubscriptionManager implements EventSubscriptionService {
61 61
62 private final Logger log = LoggerFactory.getLogger(getClass()); 62 private final Logger log = LoggerFactory.getLogger(getClass());
63 63
...@@ -147,15 +147,12 @@ public class EventExporterManager implements EventExporterService { ...@@ -147,15 +147,12 @@ public class EventExporterManager implements EventExporterService {
147 + "registered to make this request."); 147 + "registered to make this request.");
148 } 148 }
149 149
150 - if (!validGroupId(subscriber.subscriberGroupId(), 150 + if (!validGroupId(subscriber.subscriberGroupId(), subscriber.appName())) {
151 - subscriber.appName())) {
152 throw new InvalidGroupIdException("Incorrect group id in the request"); 151 throw new InvalidGroupIdException("Incorrect group id in the request");
153 } 152 }
154 153
155 OnosEventListener onosListener = getListener(subscriber.eventType()); 154 OnosEventListener onosListener = getListener(subscriber.eventType());
156 - checkNotNull(onosListener, 155 + checkNotNull(onosListener, "No listener for the supported event type - {}", subscriber.eventType());
157 - "No listener for the supported event type - {}",
158 - subscriber.eventType());
159 156
160 applyListenerAction(subscriber.eventType(), onosListener, 157 applyListenerAction(subscriber.eventType(), onosListener,
161 ListenerAction.START); 158 ListenerAction.START);
...@@ -169,7 +166,7 @@ public class EventExporterManager implements EventExporterService { ...@@ -169,7 +166,7 @@ public class EventExporterManager implements EventExporterService {
169 subscriptionList.add(subscriber); 166 subscriptionList.add(subscriber);
170 subscriptions.put(subscriber.eventType(), subscriptionList); 167 subscriptions.put(subscriber.eventType(), subscriptionList);
171 168
172 - log.info("Subscription for {} event by {} successfull", 169 + log.info("Subscription for {} event by {} successful",
173 subscriber.eventType(), subscriber.appName()); 170 subscriber.eventType(), subscriber.appName());
174 } 171 }
175 172
...@@ -308,6 +305,12 @@ public class EventExporterManager implements EventExporterService { ...@@ -308,6 +305,12 @@ public class EventExporterManager implements EventExporterService {
308 subscriber.eventType()); 305 subscriber.eventType());
309 } 306 }
310 307
308 + @Override
309 + public List<EventSubscriber> getEventSubscribers(Type type) {
310 + return subscriptions.getOrDefault(type, ImmutableList.of());
311 +
312 + }
313 +
311 /** 314 /**
312 * Checks if the subscriber has already subscribed to the requested event 315 * Checks if the subscriber has already subscribed to the requested event
313 * type. 316 * type.
......
...@@ -21,7 +21,6 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -21,7 +21,6 @@ import org.apache.felix.scr.annotations.Reference;
21 import org.apache.felix.scr.annotations.ReferenceCardinality; 21 import org.apache.felix.scr.annotations.ReferenceCardinality;
22 import org.onosproject.codec.CodecService; 22 import org.onosproject.codec.CodecService;
23 import org.onosproject.kafkaintegration.api.dto.EventSubscriber; 23 import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
24 -import org.onosproject.kafkaintegration.rest.SubscriberCodec;
25 import org.slf4j.Logger; 24 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory; 25 import org.slf4j.LoggerFactory;
27 26
......
...@@ -16,6 +16,7 @@ package org.onosproject.kafkaintegration.impl; ...@@ -16,6 +16,7 @@ package org.onosproject.kafkaintegration.impl;
16 16
17 import org.onosproject.event.AbstractListenerManager; 17 import org.onosproject.event.AbstractListenerManager;
18 import org.onosproject.kafkaintegration.api.ExportableEventListener; 18 import org.onosproject.kafkaintegration.api.ExportableEventListener;
19 +import org.onosproject.kafkaintegration.api.KafkaPublisherService;
19 import org.onosproject.kafkaintegration.api.dto.OnosEvent; 20 import org.onosproject.kafkaintegration.api.dto.OnosEvent;
20 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; 21 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
21 import org.slf4j.Logger; 22 import org.slf4j.Logger;
...@@ -27,17 +28,19 @@ import com.google.protobuf.GeneratedMessage; ...@@ -27,17 +28,19 @@ import com.google.protobuf.GeneratedMessage;
27 * Dispatch ONOS Events to all interested Listeners. 28 * Dispatch ONOS Events to all interested Listeners.
28 * 29 *
29 */ 30 */
30 -public final class Dispatcher 31 +
31 - extends AbstractListenerManager<OnosEvent, ExportableEventListener> { 32 +public final class KafkaPublisherManager
33 + extends AbstractListenerManager<OnosEvent, ExportableEventListener> implements KafkaPublisherService {
32 34
33 private final Logger log = LoggerFactory.getLogger(getClass()); 35 private final Logger log = LoggerFactory.getLogger(getClass());
34 36
35 // Exists to defeat instantiation 37 // Exists to defeat instantiation
36 - private Dispatcher() { 38 + private KafkaPublisherManager() {
37 } 39 }
38 40
41 + //TODO: If possible, get rid of Singleton implementation.
39 private static class SingletonHolder { 42 private static class SingletonHolder {
40 - private static final Dispatcher INSTANCE = new Dispatcher(); 43 + private static final KafkaPublisherManager INSTANCE = new KafkaPublisherManager();
41 } 44 }
42 45
43 /** 46 /**
...@@ -45,16 +48,11 @@ public final class Dispatcher ...@@ -45,16 +48,11 @@ public final class Dispatcher
45 * 48 *
46 * @return singleton object 49 * @return singleton object
47 */ 50 */
48 - public static Dispatcher getInstance() { 51 + public static KafkaPublisherManager getInstance() {
49 return SingletonHolder.INSTANCE; 52 return SingletonHolder.INSTANCE;
50 } 53 }
51 54
52 - /** 55 + @Override
53 - * Publish the ONOS Event to all listeners.
54 - *
55 - * @param eventType the ONOS eventtype
56 - * @param message generated Protocol buffer message from ONOS event data
57 - */
58 public void publish(Type eventType, GeneratedMessage message) { 56 public void publish(Type eventType, GeneratedMessage message) {
59 log.debug("Dispatching ONOS Event {}", eventType); 57 log.debug("Dispatching ONOS Event {}", eventType);
60 post(new OnosEvent(eventType, message)); 58 post(new OnosEvent(eventType, message));
......
...@@ -14,11 +14,6 @@ ...@@ -14,11 +14,6 @@
14 */ 14 */
15 package org.onosproject.kafkaintegration.impl; 15 package org.onosproject.kafkaintegration.impl;
16 16
17 -import java.util.TreeMap;
18 -import java.util.concurrent.Executors;
19 -import java.util.concurrent.ScheduledExecutorService;
20 -import java.util.concurrent.TimeUnit;
21 -
22 import org.apache.felix.scr.annotations.Activate; 17 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 18 import org.apache.felix.scr.annotations.Component;
24 import org.apache.felix.scr.annotations.Deactivate; 19 import org.apache.felix.scr.annotations.Deactivate;
...@@ -31,6 +26,11 @@ import org.onosproject.store.service.StorageService; ...@@ -31,6 +26,11 @@ import org.onosproject.store.service.StorageService;
31 import org.slf4j.Logger; 26 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory; 27 import org.slf4j.LoggerFactory;
33 28
29 +import java.util.TreeMap;
30 +import java.util.concurrent.Executors;
31 +import java.util.concurrent.ScheduledExecutorService;
32 +import java.util.concurrent.TimeUnit;
33 +
34 @Component(immediate = true) 34 @Component(immediate = true)
35 public class KafkaStorageManager implements KafkaEventStorageService { 35 public class KafkaStorageManager implements KafkaEventStorageService {
36 36
......
...@@ -12,19 +12,19 @@ ...@@ -12,19 +12,19 @@
12 * See the License for the specific language governing permissions and 12 * See the License for the specific language governing permissions and
13 * limitations under the License. 13 * limitations under the License.
14 */ 14 */
15 -package org.onosproject.kafkaintegration.rest; 15 +package org.onosproject.kafkaintegration.impl;
16 -
17 -import static com.google.common.base.Preconditions.checkNotNull;
18 -
19 -import java.util.UUID;
20 16
17 +import com.fasterxml.jackson.databind.node.ObjectNode;
21 import org.onosproject.codec.CodecContext; 18 import org.onosproject.codec.CodecContext;
22 import org.onosproject.codec.JsonCodec; 19 import org.onosproject.codec.JsonCodec;
23 import org.onosproject.kafkaintegration.api.dto.DefaultEventSubscriber; 20 import org.onosproject.kafkaintegration.api.dto.DefaultEventSubscriber;
24 import org.onosproject.kafkaintegration.api.dto.EventSubscriber; 21 import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
25 import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId; 22 import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId;
26 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; 23 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
27 -import com.fasterxml.jackson.databind.node.ObjectNode; 24 +
25 +import java.util.UUID;
26 +
27 +import static com.google.common.base.Preconditions.checkNotNull;
28 28
29 /** 29 /**
30 * Codec for encoding/decoding a Subscriber object to/from JSON. 30 * Codec for encoding/decoding a Subscriber object to/from JSON.
......
1 +/**
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.kafkaintegration.kafka;
18 +
19 +import org.apache.kafka.clients.producer.KafkaProducer;
20 +import org.apache.kafka.clients.producer.ProducerRecord;
21 +import org.apache.kafka.clients.producer.RecordMetadata;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import java.util.Properties;
26 +import java.util.concurrent.Future;
27 +
28 +/**
29 + * Implementation of Kafka Producer.
30 + */
31 +public class Producer {
32 + private KafkaProducer<String, byte[]> kafkaProducer = null;
33 +
34 + private final Logger log = LoggerFactory.getLogger(getClass());
35 +
36 + Producer(String bootstrapServers, int retries, int maxInFlightRequestsPerConnection,
37 + int requestRequiredAcks, String keySerializer, String valueSerializer) {
38 +
39 + Properties prop = new Properties();
40 + prop.put("bootstrap.servers", bootstrapServers);
41 + prop.put("retries", retries);
42 + prop.put("max.in.flight.requests.per.connection", maxInFlightRequestsPerConnection);
43 + prop.put("request.required.acks", requestRequiredAcks);
44 + prop.put("key.serializer", keySerializer);
45 + prop.put("value.serializer", valueSerializer);
46 +
47 + kafkaProducer = new KafkaProducer<>(prop);
48 + }
49 +
50 + public void start() {
51 + log.info("Started");
52 + }
53 +
54 + public void stop() {
55 + if (kafkaProducer != null) {
56 + kafkaProducer.close();
57 + kafkaProducer = null;
58 + }
59 +
60 + log.info("Stopped");
61 + }
62 +
63 + public Future<RecordMetadata> send(ProducerRecord<String, byte[]> record) {
64 + return kafkaProducer.send(record);
65 + }
66 +}
1 +/**
2 + * Copyright 2016-present Open Networking Laboratory Licensed under the Apache
3 + * License, Version 2.0 (the "License"); you may not use this file except in
4 + * compliance with the License. You may obtain a copy of the License at
5 + *
6 + * http://www.apache.org/licenses/LICENSE-2.0
7 + *
8 + * Unless required by applicable law or agreed to in writing, software
9 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 + * License for the specific language governing permissions and limitations under
12 + * the License.
13 + */
14 +
15 +/**
16 + * API implementation classes.
17 + */
18 +package org.onosproject.kafkaintegration.kafka;
...@@ -14,29 +14,31 @@ ...@@ -14,29 +14,31 @@
14 */ 14 */
15 package org.onosproject.kafkaintegration.listener; 15 package org.onosproject.kafkaintegration.listener;
16 16
17 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; 17 +import com.google.protobuf.GeneratedMessage;
18 -
19 import org.onosproject.event.ListenerService; 18 import org.onosproject.event.ListenerService;
20 -import org.onosproject.kafkaintegration.impl.Dispatcher;
21 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; 19 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
22 import org.onosproject.kafkaintegration.converter.ConversionFactory; 20 import org.onosproject.kafkaintegration.converter.ConversionFactory;
23 import org.onosproject.kafkaintegration.converter.EventConverter; 21 import org.onosproject.kafkaintegration.converter.EventConverter;
22 +import org.onosproject.kafkaintegration.impl.KafkaPublisherManager;
24 import org.onosproject.net.device.DeviceEvent; 23 import org.onosproject.net.device.DeviceEvent;
25 import org.onosproject.net.device.DeviceListener; 24 import org.onosproject.net.device.DeviceListener;
26 import org.onosproject.net.device.DeviceService; 25 import org.onosproject.net.device.DeviceService;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
27 28
28 -import com.google.protobuf.GeneratedMessage; 29 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
29 30
30 /** 31 /**
31 * Listens for ONOS Device events. 32 * Listens for ONOS Device events.
32 * 33 *
33 */ 34 */
34 -final class DeviceEventsListener implements OnosEventListener { 35 +public final class DeviceEventsListener implements OnosEventListener {
36 +
37 + private final Logger log = LoggerFactory.getLogger(getClass());
35 38
36 private boolean listenerRunning = false; 39 private boolean listenerRunning = false;
37 40
38 private InnerListener listener = null; 41 private InnerListener listener = null;
39 -
40 // Exists to defeat instantiation 42 // Exists to defeat instantiation
41 private DeviceEventsListener() { 43 private DeviceEventsListener() {
42 } 44 }
...@@ -70,14 +72,14 @@ final class DeviceEventsListener implements OnosEventListener { ...@@ -70,14 +72,14 @@ final class DeviceEventsListener implements OnosEventListener {
70 @Override 72 @Override
71 public void event(DeviceEvent arg0) { 73 public void event(DeviceEvent arg0) {
72 74
73 - // Convert the event to GPB format 75 + // Convert the event to protobuf format
74 ConversionFactory conversionFactory = 76 ConversionFactory conversionFactory =
75 ConversionFactory.getInstance(); 77 ConversionFactory.getInstance();
76 EventConverter converter = conversionFactory.getConverter(DEVICE); 78 EventConverter converter = conversionFactory.getConverter(DEVICE);
77 GeneratedMessage message = converter.convertToProtoMessage(arg0); 79 GeneratedMessage message = converter.convertToProtoMessage(arg0);
78 80
79 // Call Dispatcher and publish event 81 // Call Dispatcher and publish event
80 - Dispatcher.getInstance().publish(DEVICE, message); 82 + KafkaPublisherManager.getInstance().publish(DEVICE, message);
81 } 83 }
82 } 84 }
83 85
...@@ -91,4 +93,4 @@ final class DeviceEventsListener implements OnosEventListener { ...@@ -91,4 +93,4 @@ final class DeviceEventsListener implements OnosEventListener {
91 } 93 }
92 } 94 }
93 95
94 -} 96 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -14,29 +14,27 @@ ...@@ -14,29 +14,27 @@
14 */ 14 */
15 package org.onosproject.kafkaintegration.listener; 15 package org.onosproject.kafkaintegration.listener;
16 16
17 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK; 17 +import com.google.protobuf.GeneratedMessage;
18 -
19 import org.onosproject.event.ListenerService; 18 import org.onosproject.event.ListenerService;
20 -import org.onosproject.kafkaintegration.impl.Dispatcher;
21 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; 19 import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
22 import org.onosproject.kafkaintegration.converter.ConversionFactory; 20 import org.onosproject.kafkaintegration.converter.ConversionFactory;
23 import org.onosproject.kafkaintegration.converter.EventConverter; 21 import org.onosproject.kafkaintegration.converter.EventConverter;
22 +import org.onosproject.kafkaintegration.impl.KafkaPublisherManager;
24 import org.onosproject.net.link.LinkEvent; 23 import org.onosproject.net.link.LinkEvent;
25 import org.onosproject.net.link.LinkListener; 24 import org.onosproject.net.link.LinkListener;
26 import org.onosproject.net.link.LinkService; 25 import org.onosproject.net.link.LinkService;
27 26
28 -import com.google.protobuf.GeneratedMessage; 27 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
29 28
30 /** 29 /**
31 * Listens for ONOS Link Events. 30 * Listens for ONOS Link Events.
32 * 31 *
33 */ 32 */
34 -final class LinkEventsListener implements OnosEventListener { 33 +public final class LinkEventsListener implements OnosEventListener {
35 34
36 private boolean listenerRunning = false; 35 private boolean listenerRunning = false;
37 36
38 private InnerListener listener = null; 37 private InnerListener listener = null;
39 -
40 // Exists to defeat instantiation 38 // Exists to defeat instantiation
41 private LinkEventsListener() { 39 private LinkEventsListener() {
42 } 40 }
...@@ -70,14 +68,14 @@ final class LinkEventsListener implements OnosEventListener { ...@@ -70,14 +68,14 @@ final class LinkEventsListener implements OnosEventListener {
70 @Override 68 @Override
71 public void event(LinkEvent arg0) { 69 public void event(LinkEvent arg0) {
72 70
73 - // Convert the event to GPB format 71 + // Convert the event to protobuf format
74 ConversionFactory conversionFactory = 72 ConversionFactory conversionFactory =
75 ConversionFactory.getInstance(); 73 ConversionFactory.getInstance();
76 EventConverter converter = conversionFactory.getConverter(LINK); 74 EventConverter converter = conversionFactory.getConverter(LINK);
77 GeneratedMessage message = converter.convertToProtoMessage(arg0); 75 GeneratedMessage message = converter.convertToProtoMessage(arg0);
78 76
79 // Call Dispatcher and publish event 77 // Call Dispatcher and publish event
80 - Dispatcher.getInstance().publish(LINK, message); 78 + KafkaPublisherManager.getInstance().publish(LINK, message);
81 } 79 }
82 } 80 }
83 81
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
14 */ 14 */
15 package org.onosproject.kafkaintegration.listener; 15 package org.onosproject.kafkaintegration.listener;
16 16
17 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; 17 +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
18 -import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
19 18
20 import java.util.HashMap; 19 import java.util.HashMap;
21 import java.util.Map; 20 import java.util.Map;
22 21
23 -import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; 22 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
23 +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
24 24
25 /** 25 /**
26 * Returns the appropriate listener object based on the ONOS event type. 26 * Returns the appropriate listener object based on the ONOS event type.
......
...@@ -30,7 +30,6 @@ public interface OnosEventListener { ...@@ -30,7 +30,6 @@ public interface OnosEventListener {
30 * @param service ONOS event listener for the specific event type 30 * @param service ONOS event listener for the specific event type
31 */ 31 */
32 void startListener(Type event, ListenerService<?, ?> service); 32 void startListener(Type event, ListenerService<?, ?> service);
33 -
34 /** 33 /**
35 * Stop the Listener for the specific ONOS event type. 34 * Stop the Listener for the specific ONOS event type.
36 * 35 *
......
...@@ -31,8 +31,9 @@ ...@@ -31,8 +31,9 @@
31 31
32 <modules> 32 <modules>
33 <module>api</module> 33 <module>api</module>
34 + <module>core</module>
35 + <module>web</module>
34 <module>app</module> 36 <module>app</module>
35 </modules> 37 </modules>
36 38
37 -</project> 39 +</project>
38 -
...\ No newline at end of file ...\ No newline at end of file
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20 + <parent>
21 + <groupId>org.onosproject</groupId>
22 + <artifactId>onos-kafka</artifactId>
23 + <version>1.7.0-SNAPSHOT</version>
24 + </parent>
25 + <modelVersion>4.0.0</modelVersion>
26 +
27 + <artifactId>onos-app-kafka-web</artifactId>
28 +
29 + <properties>
30 + <web.context>/onos/kafka</web.context>
31 + <api.version>1.0.0</api.version>
32 + <api.package>org.onosproject.kafkaintegration.rest</api.package>
33 + <api.title>Kafka Integration Application REST API</api.title>
34 + <api.description>
35 + APIs for subscribing to Events generated by ONOS
36 + </api.description>
37 + </properties>
38 +
39 + <packaging>bundle</packaging>
40 +
41 + <dependencies>
42 + <dependency>
43 + <groupId>org.onosproject</groupId>
44 + <artifactId>onos-api</artifactId>
45 + </dependency>
46 +
47 + <dependency>
48 + <groupId>org.onosproject</groupId>
49 + <artifactId>onos-app-kafka-api</artifactId>
50 + <version>${project.version}</version>
51 + </dependency>
52 +
53 + <dependency>
54 + <groupId>org.onosproject</groupId>
55 + <artifactId>onos-incubator-protobuf</artifactId>
56 + <version>${project.version}</version>
57 + </dependency>
58 +
59 + <dependency>
60 + <groupId>org.onosproject</groupId>
61 + <artifactId>onlab-osgi</artifactId>
62 + </dependency>
63 +
64 + <dependency>
65 + <groupId>org.onosproject</groupId>
66 + <artifactId>onos-rest</artifactId>
67 + <version>${project.version}</version>
68 + </dependency>
69 +
70 + <dependency>
71 + <groupId>junit</groupId>
72 + <artifactId>junit</artifactId>
73 + </dependency>
74 +
75 + <dependency>
76 + <groupId>org.onosproject</groupId>
77 + <artifactId>onos-api</artifactId>
78 + <classifier>tests</classifier>
79 + </dependency>
80 +
81 + <dependency>
82 + <groupId>javax.ws.rs</groupId>
83 + <artifactId>javax.ws.rs-api</artifactId>
84 + <version>2.0.1</version>
85 + </dependency>
86 +
87 + <dependency>
88 + <groupId>com.google.protobuf</groupId>
89 + <artifactId>protobuf-java</artifactId>
90 + <version>3.0.0-beta-2</version>
91 + </dependency>
92 +
93 + <dependency>
94 + <groupId>org.codehaus.jackson</groupId>
95 + <artifactId>jackson-core-asl</artifactId>
96 + <version>1.9.13</version>
97 + </dependency>
98 +
99 + <dependency>
100 + <groupId>org.codehaus.jackson</groupId>
101 + <artifactId>jackson-mapper-asl</artifactId>
102 + <version>1.9.13</version>
103 + </dependency>
104 +
105 + <dependency>
106 + <groupId>org.glassfish.jersey.containers</groupId>
107 + <artifactId>jersey-container-servlet</artifactId>
108 + </dependency>
109 + <dependency>
110 + <groupId>com.fasterxml.jackson.core</groupId>
111 + <artifactId>jackson-annotations</artifactId>
112 + </dependency>
113 +
114 + <dependency>
115 + <groupId>org.onosproject</groupId>
116 + <artifactId>onos-core-serializers</artifactId>
117 + <version>${project.version}</version>
118 + </dependency>
119 +
120 + <dependency>
121 + <groupId>org.apache.felix</groupId>
122 + <artifactId>org.apache.felix.scr.annotations</artifactId>
123 + </dependency>
124 +
125 + </dependencies>
126 +
127 + <build>
128 + <plugins>
129 + <plugin>
130 + <groupId>org.apache.felix</groupId>
131 + <artifactId>maven-bundle-plugin</artifactId>
132 + <extensions>true</extensions>
133 + <configuration>
134 + <instructions>
135 + <Bundle-SymbolicName>
136 + ${project.groupId}.${project.artifactId}
137 + </Bundle-SymbolicName>
138 + <_wab>src/main/webapp/</_wab>
139 + <Include-Resource>
140 + WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
141 + {maven-resources}
142 + </Include-Resource>
143 + <Import-Package>
144 + org.slf4j,
145 + org.osgi.framework,
146 + javax.ws.rs,
147 + javax.ws.rs.core,
148 + org.glassfish.jersey.servlet,
149 + com.fasterxml.jackson.databind,
150 + com.fasterxml.jackson.databind.node,
151 + com.fasterxml.jackson.core,
152 + org.onlab.packet.*,
153 + org.onosproject.*,
154 + org.onlab.util.*,
155 + com.google.common.*,
156 + com.google.protobuf.*
157 + </Import-Package>
158 + <Web-ContextPath>${web.context}</Web-ContextPath>
159 + </instructions>
160 + </configuration>
161 + </plugin>
162 +
163 + <plugin>
164 + <groupId>org.apache.maven.plugins</groupId>
165 + <artifactId>maven-compiler-plugin</artifactId>
166 + <configuration>
167 + <source>1.8</source>
168 + <target>1.8</target>
169 + </configuration>
170 + </plugin>
171 + <plugin>
172 + <groupId>org.apache.felix</groupId>
173 + <artifactId>maven-scr-plugin</artifactId>
174 + <executions>
175 + <execution>
176 + <id>generate-scr-srcdescriptor</id>
177 + <goals>
178 + <goal>scr</goal>
179 + </goals>
180 + </execution>
181 + </executions>
182 + <configuration>
183 + <supportedProjectTypes>
184 + <supportedProjectType>bundle</supportedProjectType>
185 + <supportedProjectType>war</supportedProjectType>
186 + </supportedProjectTypes>
187 + </configuration>
188 + </plugin>
189 +
190 + <plugin>
191 + <groupId>org.onosproject</groupId>
192 + <artifactId>onos-maven-plugin</artifactId>
193 + <executions>
194 + <execution>
195 + <id>cfg</id>
196 + <phase>generate-resources</phase>
197 + <goals>
198 + <goal>cfg</goal>
199 + </goals>
200 + </execution>
201 + <execution>
202 + <id>swagger</id>
203 + <goals>
204 + <goal>swagger</goal>
205 + </goals>
206 + </execution>
207 + <execution>
208 + <id>app</id>
209 + <phase>package</phase>
210 + <goals>
211 + <goal>app</goal>
212 + </goals>
213 + </execution>
214 + </executions>
215 + </plugin>
216 + </plugins>
217 + </build>
218 +
219 +</project>
...@@ -14,11 +14,15 @@ ...@@ -14,11 +14,15 @@
14 */ 14 */
15 package org.onosproject.kafkaintegration.rest; 15 package org.onosproject.kafkaintegration.rest;
16 16
17 -import static com.google.common.base.Preconditions.checkNotNull; 17 +import com.fasterxml.jackson.databind.ObjectMapper;
18 -import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 18 +import com.fasterxml.jackson.databind.node.ObjectNode;
19 +import org.onosproject.kafkaintegration.api.EventSubscriptionService;
20 +import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
21 +import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId;
22 +import org.onosproject.rest.AbstractWebResource;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
19 25
20 -import java.io.IOException;
21 -import java.io.InputStream;
22 26
23 import javax.ws.rs.Consumes; 27 import javax.ws.rs.Consumes;
24 import javax.ws.rs.DELETE; 28 import javax.ws.rs.DELETE;
...@@ -27,16 +31,11 @@ import javax.ws.rs.Path; ...@@ -27,16 +31,11 @@ import javax.ws.rs.Path;
27 import javax.ws.rs.Produces; 31 import javax.ws.rs.Produces;
28 import javax.ws.rs.core.MediaType; 32 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response; 33 import javax.ws.rs.core.Response;
34 +import java.io.IOException;
35 +import java.io.InputStream;
30 36
31 -import org.onosproject.kafkaintegration.api.EventExporterService; 37 +import static com.google.common.base.Preconditions.checkNotNull;
32 -import org.onosproject.kafkaintegration.api.dto.EventSubscriber; 38 +import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
33 -import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId;
34 -import org.onosproject.rest.AbstractWebResource;
35 -import org.slf4j.Logger;
36 -import org.slf4j.LoggerFactory;
37 -
38 -import com.fasterxml.jackson.databind.ObjectMapper;
39 -import com.fasterxml.jackson.databind.node.ObjectNode;
40 39
41 /** 40 /**
42 * Rest Interfaces for subscribing/unsubscribing to event notifications. 41 * Rest Interfaces for subscribing/unsubscribing to event notifications.
...@@ -52,11 +51,12 @@ public class EventExporterWebResource extends AbstractWebResource { ...@@ -52,11 +51,12 @@ public class EventExporterWebResource extends AbstractWebResource {
52 public static final String DEREGISTRATION_SUCCESSFUL = 51 public static final String DEREGISTRATION_SUCCESSFUL =
53 "De-Registered Listener successfully"; 52 "De-Registered Listener successfully";
54 public static final String EVENT_SUBSCRIPTION_SUCCESSFUL = 53 public static final String EVENT_SUBSCRIPTION_SUCCESSFUL =
55 - "Event Registration successfull"; 54 + "Event Registration successful";
56 public static final String EVENT_SUBSCRIPTION_UNSUCCESSFUL = 55 public static final String EVENT_SUBSCRIPTION_UNSUCCESSFUL =
57 "Event subscription unsuccessful"; 56 "Event subscription unsuccessful";
58 public static final String EVENT_SUBSCRIPTION_REMOVED = 57 public static final String EVENT_SUBSCRIPTION_REMOVED =
59 - "Event De-Registration successfull"; 58 + "Event De-Registration successful";
59 +
60 /** 60 /**
61 * Registers a listener for ONOS Events. 61 * Registers a listener for ONOS Events.
62 * 62 *
...@@ -71,12 +71,11 @@ public class EventExporterWebResource extends AbstractWebResource { ...@@ -71,12 +71,11 @@ public class EventExporterWebResource extends AbstractWebResource {
71 @Path("register") 71 @Path("register")
72 public Response registerKafkaListener(String appName) { 72 public Response registerKafkaListener(String appName) {
73 73
74 - EventExporterService service = get(EventExporterService.class); 74 + EventSubscriptionService service = get(EventSubscriptionService.class);
75 75
76 EventSubscriberGroupId groupId = service.registerListener(appName); 76 EventSubscriberGroupId groupId = service.registerListener(appName);
77 77
78 log.info("Registered app {}", appName); 78 log.info("Registered app {}", appName);
79 -
80 // TODO: Should also return Kafka server information. 79 // TODO: Should also return Kafka server information.
81 // Will glue this in when we have the config and Kafka modules ready 80 // Will glue this in when we have the config and Kafka modules ready
82 return ok(groupId.getId().toString()).build(); 81 return ok(groupId.getId().toString()).build();
...@@ -92,7 +91,7 @@ public class EventExporterWebResource extends AbstractWebResource { ...@@ -92,7 +91,7 @@ public class EventExporterWebResource extends AbstractWebResource {
92 @DELETE 91 @DELETE
93 @Path("unregister") 92 @Path("unregister")
94 public Response removeKafkaListener(String appName) { 93 public Response removeKafkaListener(String appName) {
95 - EventExporterService service = get(EventExporterService.class); 94 + EventSubscriptionService service = get(EventSubscriptionService.class);
96 95
97 service.unregisterListener(appName); 96 service.unregisterListener(appName);
98 log.info("Unregistered app {}", appName); 97 log.info("Unregistered app {}", appName);
...@@ -112,11 +111,12 @@ public class EventExporterWebResource extends AbstractWebResource { ...@@ -112,11 +111,12 @@ public class EventExporterWebResource extends AbstractWebResource {
112 @Path("subscribe") 111 @Path("subscribe")
113 public Response subscribe(InputStream input) { 112 public Response subscribe(InputStream input) {
114 113
115 - EventExporterService service = get(EventExporterService.class); 114 + EventSubscriptionService service = get(EventSubscriptionService.class);
116 115
117 try { 116 try {
118 EventSubscriber sub = parseSubscriptionData(input); 117 EventSubscriber sub = parseSubscriptionData(input);
119 service.subscribe(sub); 118 service.subscribe(sub);
119 + // It will subscribe to all the topics. Not only the one that is sent by the consumer.
120 } catch (Exception e) { 120 } catch (Exception e) {
121 log.error(e.getMessage()); 121 log.error(e.getMessage());
122 return Response.status(BAD_REQUEST).entity(e.getMessage()).build(); 122 return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
...@@ -155,7 +155,7 @@ public class EventExporterWebResource extends AbstractWebResource { ...@@ -155,7 +155,7 @@ public class EventExporterWebResource extends AbstractWebResource {
155 @Path("unsubscribe") 155 @Path("unsubscribe")
156 public Response unsubscribe(InputStream input) { 156 public Response unsubscribe(InputStream input) {
157 157
158 - EventExporterService service = get(EventExporterService.class); 158 + EventSubscriptionService service = get(EventSubscriptionService.class);
159 159
160 try { 160 try {
161 EventSubscriber sub = parseSubscriptionData(input); 161 EventSubscriber sub = parseSubscriptionData(input);
......