Kafka Integration Application (Fix Javadoc errors + review comments)
1. Refactored the application into two java projects api and app as per convention 2. Deleted the onos-app-gpb project. The proto files are consolidated in the incubator-protobuf project as per suggestions. 3. Some code to translate ONOS Event pojo messages to GPB format. 4. Implementation of Subscribe and Unsubscribe APIs. 5. Minor changes due to review comments from 9212 and 9053 6. Refactored the proto fileso that its a 1:1 mapping between the core type to proto message. Change-Id: I2bcc0de96150f838ccfe9e49293fe61d94062628
Showing
40 changed files
with
1431 additions
and
256 deletions
apps/kafka-integration/api/pom.xml
0 → 100644
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 | + <modelVersion>4.0.0</modelVersion> | ||
21 | + | ||
22 | + <parent> | ||
23 | + <artifactId>onos-kafka</artifactId> | ||
24 | + <groupId>org.onosproject</groupId> | ||
25 | + <version>1.7.0-SNAPSHOT</version> | ||
26 | + <relativePath>../pom.xml</relativePath> | ||
27 | + </parent> | ||
28 | + | ||
29 | + <artifactId>onos-app-kafka-api</artifactId> | ||
30 | + <packaging>bundle</packaging> | ||
31 | + | ||
32 | + <url>http://onosproject.org</url> | ||
33 | + | ||
34 | + <description>Kafka Integration Application</description> | ||
35 | + | ||
36 | + <dependencies> | ||
37 | + <dependency> | ||
38 | + <groupId>com.google.protobuf</groupId> | ||
39 | + <artifactId>protobuf-java</artifactId> | ||
40 | + <version>3.0.0-beta-2</version> | ||
41 | + </dependency> | ||
42 | + </dependencies> | ||
43 | + | ||
44 | + <build> | ||
45 | + <plugins> | ||
46 | + <plugin> | ||
47 | + <groupId>org.apache.felix</groupId> | ||
48 | + <artifactId>maven-bundle-plugin</artifactId> | ||
49 | + <extensions>true</extensions> | ||
50 | + <configuration> | ||
51 | + <instructions> | ||
52 | + </instructions> | ||
53 | + </configuration> | ||
54 | + </plugin> | ||
55 | + </plugins> | ||
56 | + </build> | ||
57 | +</project> | ||
58 | + |
... | @@ -18,11 +18,13 @@ import org.onosproject.kafkaintegration.api.dto.EventSubscriber; | ... | @@ -18,11 +18,13 @@ 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.errors.InvalidApplicationException; | 19 | import org.onosproject.kafkaintegration.errors.InvalidApplicationException; |
20 | import org.onosproject.kafkaintegration.errors.InvalidGroupIdException; | 20 | import org.onosproject.kafkaintegration.errors.InvalidGroupIdException; |
21 | -import org.onosproject.kafkaintegration.errors.UnsupportedEventException; | 21 | + |
22 | +import com.google.common.annotations.Beta; | ||
22 | 23 | ||
23 | /** | 24 | /** |
24 | * APIs for subscribing to Onos Event Messages. | 25 | * APIs for subscribing to Onos Event Messages. |
25 | */ | 26 | */ |
27 | +@Beta | ||
26 | public interface EventExporterService { | 28 | public interface EventExporterService { |
27 | 29 | ||
28 | /** | 30 | /** |
... | @@ -44,13 +46,11 @@ public interface EventExporterService { | ... | @@ -44,13 +46,11 @@ public interface EventExporterService { |
44 | * Allows registered listener to subscribe for a specific event type. | 46 | * Allows registered listener to subscribe for a specific event type. |
45 | * | 47 | * |
46 | * @param subscriber Subscription data containing the event type | 48 | * @param subscriber Subscription data containing the event type |
47 | - * @throws UnsupportedEventException | ||
48 | * @throws InvalidGroupIdException | 49 | * @throws InvalidGroupIdException |
49 | * @throws InvalidApplicationException | 50 | * @throws InvalidApplicationException |
50 | */ | 51 | */ |
51 | void subscribe(EventSubscriber subscriber) | 52 | void subscribe(EventSubscriber subscriber) |
52 | - throws UnsupportedEventException, InvalidGroupIdException, | 53 | + throws InvalidGroupIdException, InvalidApplicationException; |
53 | - InvalidApplicationException; | ||
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Allows the registered listener to unsubscribe for a specific event. | 56 | * Allows the registered listener to unsubscribe for a specific event. | ... | ... |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.api; | ||
16 | + | ||
17 | +import org.onosproject.event.EventListener; | ||
18 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent; | ||
19 | + | ||
20 | +import com.google.common.annotations.Beta; | ||
21 | + | ||
22 | +/** | ||
23 | + * API for listeners to listen for Events generated by the ONOS event listener. | ||
24 | + * At present the only listener will be a Kafka Manager or Module whose sole | ||
25 | + * purpose is to publish the received data to a Kafka message bus. | ||
26 | + * | ||
27 | + */ | ||
28 | +@Beta | ||
29 | +public interface ExportableEventListener extends EventListener<OnosEvent> { | ||
30 | + | ||
31 | +} |
apps/kafka-integration/app/app.xml
0 → 100644
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 | +<app name="org.onosproject.kafkaintegration" origin="Calix" version="${project.version}" | ||
18 | + category="Utility" url="http://onosproject.org" title="Kafka Integration Application" | ||
19 | + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | ||
20 | + features="${project.artifactId}" apps="org.onosproject.incubator.protobuf"> | ||
21 | + <description>${project.description}</description> | ||
22 | + <artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact> | ||
23 | + <artifact>mvn:${project.groupId}/onos-app-kafka-api/${project.version}</artifact> | ||
24 | +</app> |
apps/kafka-integration/app/features.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
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 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
18 | + <feature name="${project.artifactId}" version="${project.version}" | ||
19 | + description="${project.description}"> | ||
20 | + <feature>onos-api</feature> | ||
21 | + <bundle>mvn:${project.groupId}/onos-app-kafka-api/${project.version}</bundle> | ||
22 | + <bundle>mvn:${project.groupId}/onos-app-kafka/${project.version}</bundle> | ||
23 | + </feature> | ||
24 | +</features> |
apps/kafka-integration/app/pom.xml
0 → 100644
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 | + <relativePath>../pom.xml</relativePath> | ||
25 | + </parent> | ||
26 | + <modelVersion>4.0.0</modelVersion> | ||
27 | + | ||
28 | + <artifactId>onos-app-kafka</artifactId> | ||
29 | + | ||
30 | + <packaging>bundle</packaging> | ||
31 | + <description> | ||
32 | + Kafka Integration Application. | ||
33 | + This will export ONOS Events to Northbound Kafka Server. | ||
34 | + </description> | ||
35 | + | ||
36 | + <properties> | ||
37 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
38 | + <onos.version>${project.version}</onos.version> | ||
39 | + <onos.app.name>org.onosproject.kafkaintegration</onos.app.name> | ||
40 | + <onos.app.title>Kafka Integration Application</onos.app.title> | ||
41 | + <onos.app.origin>Calix, Inc.</onos.app.origin> | ||
42 | + <web.context>/onos/kafka</web.context> | ||
43 | + <api.version>1.0.0</api.version> | ||
44 | + <api.package>org.onosproject.kafkaintegration.rest</api.package> | ||
45 | + <api.title>Kafka Integration Application REST API</api.title> | ||
46 | + <api.description> | ||
47 | + APIs for subscribing to Events generated by ONOS | ||
48 | + </api.description> | ||
49 | + <onos.app.category>Utility</onos.app.category> | ||
50 | + <onos.app.url>https://wiki.onosproject.org/display/ONOS/Kafka+Integration</onos.app.url> | ||
51 | + <onos.app.readme>Export ONOS events to a Northbound Kafka server</onos.app.readme> | ||
52 | + <onos.app.requires>org.onosproject.incubator.protobuf</onos.app.requires> | ||
53 | + </properties> | ||
54 | + | ||
55 | + <dependencies> | ||
56 | + <dependency> | ||
57 | + <groupId>org.onosproject</groupId> | ||
58 | + <artifactId>onos-api</artifactId> | ||
59 | + </dependency> | ||
60 | + | ||
61 | + <dependency> | ||
62 | + <groupId>org.onosproject</groupId> | ||
63 | + <artifactId>onos-app-kafka-api</artifactId> | ||
64 | + <version>${project.version}</version> | ||
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>org.onosproject</groupId> | ||
75 | + <artifactId>onlab-osgi</artifactId> | ||
76 | + </dependency> | ||
77 | + | ||
78 | + <dependency> | ||
79 | + <groupId>org.onosproject</groupId> | ||
80 | + <artifactId>onos-rest</artifactId> | ||
81 | + <version>${project.version}</version> | ||
82 | + </dependency> | ||
83 | + | ||
84 | + <dependency> | ||
85 | + <groupId>junit</groupId> | ||
86 | + <artifactId>junit</artifactId> | ||
87 | + <scope>test</scope> | ||
88 | + </dependency> | ||
89 | + | ||
90 | + <dependency> | ||
91 | + <groupId>org.onosproject</groupId> | ||
92 | + <artifactId>onos-api</artifactId> | ||
93 | + <scope>test</scope> | ||
94 | + <classifier>tests</classifier> | ||
95 | + </dependency> | ||
96 | + | ||
97 | + <dependency> | ||
98 | + <groupId>javax.ws.rs</groupId> | ||
99 | + <artifactId>javax.ws.rs-api</artifactId> | ||
100 | + <version>2.0.1</version> | ||
101 | + </dependency> | ||
102 | + | ||
103 | + <dependency> | ||
104 | + <groupId>com.google.protobuf</groupId> | ||
105 | + <artifactId>protobuf-java</artifactId> | ||
106 | + <version>3.0.0-beta-2</version> | ||
107 | + </dependency> | ||
108 | + | ||
109 | + <dependency> | ||
110 | + <groupId>org.codehaus.jackson</groupId> | ||
111 | + <artifactId>jackson-core-asl</artifactId> | ||
112 | + <version>1.9.13</version> | ||
113 | + </dependency> | ||
114 | + | ||
115 | + <dependency> | ||
116 | + <groupId>org.codehaus.jackson</groupId> | ||
117 | + <artifactId>jackson-mapper-asl</artifactId> | ||
118 | + <version>1.9.13</version> | ||
119 | + </dependency> | ||
120 | + | ||
121 | + <dependency> | ||
122 | + <groupId>org.glassfish.jersey.containers</groupId> | ||
123 | + <artifactId>jersey-container-servlet</artifactId> | ||
124 | + </dependency> | ||
125 | + <dependency> | ||
126 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
127 | + <artifactId>jackson-annotations</artifactId> | ||
128 | + </dependency> | ||
129 | + | ||
130 | + <dependency> | ||
131 | + <groupId>org.onosproject</groupId> | ||
132 | + <artifactId>onos-core-serializers</artifactId> | ||
133 | + <version>${project.version}</version> | ||
134 | + </dependency> | ||
135 | + | ||
136 | + <dependency> | ||
137 | + <groupId>org.apache.felix</groupId> | ||
138 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
139 | + <scope>provided</scope> | ||
140 | + </dependency> | ||
141 | + </dependencies> | ||
142 | + | ||
143 | + <build> | ||
144 | + <plugins> | ||
145 | + <plugin> | ||
146 | + <groupId>org.apache.felix</groupId> | ||
147 | + <artifactId>maven-bundle-plugin</artifactId> | ||
148 | + <extensions>true</extensions> | ||
149 | + <configuration> | ||
150 | + <instructions> | ||
151 | + <Bundle-SymbolicName> | ||
152 | + ${project.groupId}.${project.artifactId} | ||
153 | + </Bundle-SymbolicName> | ||
154 | + <_wab>src/main/webapp/</_wab> | ||
155 | + <Include-Resource> | ||
156 | + WEB-INF/classes/apidoc/swagger.json=target/swagger.json, | ||
157 | + {maven-resources} | ||
158 | + </Include-Resource> | ||
159 | + <Import-Package> | ||
160 | + org.slf4j, | ||
161 | + org.osgi.framework, | ||
162 | + javax.ws.rs, | ||
163 | + javax.ws.rs.core, | ||
164 | + org.glassfish.jersey.servlet, | ||
165 | + com.fasterxml.jackson.databind, | ||
166 | + com.fasterxml.jackson.databind.node, | ||
167 | + com.fasterxml.jackson.core, | ||
168 | + org.onlab.packet.*, | ||
169 | + org.onosproject.*, | ||
170 | + com.google.common.* | ||
171 | + </Import-Package> | ||
172 | + <Web-ContextPath>${web.context}</Web-ContextPath> | ||
173 | + </instructions> | ||
174 | + </configuration> | ||
175 | + </plugin> | ||
176 | + <plugin> | ||
177 | + <groupId>org.apache.maven.plugins</groupId> | ||
178 | + <artifactId>maven-compiler-plugin</artifactId> | ||
179 | + <configuration> | ||
180 | + <source>1.8</source> | ||
181 | + <target>1.8</target> | ||
182 | + </configuration> | ||
183 | + </plugin> | ||
184 | + <plugin> | ||
185 | + <groupId>org.apache.felix</groupId> | ||
186 | + <artifactId>maven-scr-plugin</artifactId> | ||
187 | + <executions> | ||
188 | + <execution> | ||
189 | + <id>generate-scr-srcdescriptor</id> | ||
190 | + <goals> | ||
191 | + <goal>scr</goal> | ||
192 | + </goals> | ||
193 | + </execution> | ||
194 | + </executions> | ||
195 | + <configuration> | ||
196 | + <supportedProjectTypes> | ||
197 | + <supportedProjectType>bundle</supportedProjectType> | ||
198 | + <supportedProjectType>war</supportedProjectType> | ||
199 | + </supportedProjectTypes> | ||
200 | + </configuration> | ||
201 | + </plugin> | ||
202 | + <plugin> | ||
203 | + <groupId>org.onosproject</groupId> | ||
204 | + <artifactId>onos-maven-plugin</artifactId> | ||
205 | + <executions> | ||
206 | + <execution> | ||
207 | + <id>cfg</id> | ||
208 | + <phase>generate-resources</phase> | ||
209 | + <goals> | ||
210 | + <goal>cfg</goal> | ||
211 | + </goals> | ||
212 | + </execution> | ||
213 | + <execution> | ||
214 | + <id>swagger</id> | ||
215 | + <goals> | ||
216 | + <goal>swagger</goal> | ||
217 | + </goals> | ||
218 | + </execution> | ||
219 | + <execution> | ||
220 | + <id>app</id> | ||
221 | + <phase>package</phase> | ||
222 | + <goals> | ||
223 | + <goal>app</goal> | ||
224 | + </goals> | ||
225 | + </execution> | ||
226 | + </executions> | ||
227 | + </plugin> | ||
228 | + </plugins> | ||
229 | + </build> | ||
230 | + | ||
231 | +</project> |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.converter; | ||
16 | + | ||
17 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; | ||
18 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK; | ||
19 | + | ||
20 | +import java.util.HashMap; | ||
21 | +import java.util.Map; | ||
22 | + | ||
23 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;; | ||
24 | + | ||
25 | +/** | ||
26 | + * Returns the appropriate converter object based on the ONOS event type. | ||
27 | + * | ||
28 | + */ | ||
29 | +public final class ConversionFactory { | ||
30 | + | ||
31 | + // Store converters for all supported events | ||
32 | + private Map<Type, EventConverter> converters = | ||
33 | + new HashMap<Type, EventConverter>() { | ||
34 | + { | ||
35 | + put(DEVICE, new DeviceEventConverter()); | ||
36 | + put(LINK, new LinkEventConverter()); | ||
37 | + } | ||
38 | + }; | ||
39 | + | ||
40 | + // Exists to defeat instantiation | ||
41 | + private ConversionFactory() { | ||
42 | + } | ||
43 | + | ||
44 | + private static class SingletonHolder { | ||
45 | + private static final ConversionFactory INSTANCE = | ||
46 | + new ConversionFactory(); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Returns a static reference to the Conversion Factory. | ||
51 | + * | ||
52 | + * @return singleton object | ||
53 | + */ | ||
54 | + public static ConversionFactory getInstance() { | ||
55 | + return SingletonHolder.INSTANCE; | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Returns an Event converter object for the specified ONOS event type. | ||
60 | + * | ||
61 | + * @param event ONOS event type | ||
62 | + * @return Event Converter object | ||
63 | + */ | ||
64 | + public EventConverter getConverter(Type event) { | ||
65 | + return converters.get(event); | ||
66 | + } | ||
67 | + | ||
68 | +} |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.converter; | ||
16 | + | ||
17 | +import org.onosproject.event.Event; | ||
18 | +import org.onosproject.grpc.net.Device.DeviceCore; | ||
19 | +import org.onosproject.grpc.net.Device.DeviceType; | ||
20 | +import org.onosproject.grpc.net.DeviceEvent.DeviceEventType; | ||
21 | +import org.onosproject.grpc.net.DeviceEvent.DeviceNotification; | ||
22 | +import org.onosproject.grpc.net.Port.PortCore; | ||
23 | +import org.onosproject.grpc.net.Port.PortType; | ||
24 | +import org.onosproject.net.device.DeviceEvent; | ||
25 | +import org.slf4j.Logger; | ||
26 | +import org.slf4j.LoggerFactory; | ||
27 | + | ||
28 | +import com.google.protobuf.GeneratedMessage; | ||
29 | + | ||
30 | +/** | ||
31 | + * Converts ONOS Device event message to GPB format. | ||
32 | + * | ||
33 | + */ | ||
34 | +class DeviceEventConverter implements EventConverter { | ||
35 | + | ||
36 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
37 | + | ||
38 | + @Override | ||
39 | + public GeneratedMessage convertToProtoMessage(Event<?, ?> event) { | ||
40 | + | ||
41 | + DeviceEvent deviceEvent = (DeviceEvent) event; | ||
42 | + | ||
43 | + if (!deviceEventSubtypeSupported(deviceEvent)) { | ||
44 | + log.error("Unsupported Onos Device Event {}. There is no matching" | ||
45 | + + "proto Device Event type", deviceEvent.type().toString()); | ||
46 | + return null; | ||
47 | + } | ||
48 | + | ||
49 | + return buildDeviceProtoMessage(deviceEvent); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Checks if the ONOS Device Event type is supported. | ||
54 | + * | ||
55 | + * @param event ONOS Device event | ||
56 | + * @return true if there is a match and false otherwise | ||
57 | + */ | ||
58 | + private boolean deviceEventSubtypeSupported(DeviceEvent event) { | ||
59 | + DeviceEventType[] deviceEvents = DeviceEventType.values(); | ||
60 | + for (DeviceEventType deviceEventType : deviceEvents) { | ||
61 | + if (deviceEventType.name().equals(event.type().name())) { | ||
62 | + return true; | ||
63 | + } | ||
64 | + } | ||
65 | + | ||
66 | + return false; | ||
67 | + } | ||
68 | + | ||
69 | + private DeviceNotification buildDeviceProtoMessage(DeviceEvent deviceEvent) { | ||
70 | + DeviceNotification notification = DeviceNotification.newBuilder() | ||
71 | + .setDeviceEventType(getProtoType(deviceEvent)) | ||
72 | + .setDevice(DeviceCore.newBuilder() | ||
73 | + .setChassisId(deviceEvent.subject().chassisId().id() | ||
74 | + .toString()) | ||
75 | + .setDeviceId(deviceEvent.subject().id().toString()) | ||
76 | + .setHwVersion(deviceEvent.subject().hwVersion()) | ||
77 | + .setManufacturer(deviceEvent.subject().manufacturer()) | ||
78 | + .setSerialNumber(deviceEvent.subject().serialNumber()) | ||
79 | + .setSwVersion(deviceEvent.subject().swVersion()) | ||
80 | + .setType(DeviceType.valueOf(deviceEvent.type().name())) | ||
81 | + .build()) | ||
82 | + .setPort(PortCore.newBuilder() | ||
83 | + .setIsEnabled(deviceEvent.port().isEnabled()) | ||
84 | + .setPortNumber(deviceEvent.port().number().toString()) | ||
85 | + .setPortSpeed(deviceEvent.port().portSpeed()) | ||
86 | + .setType(PortType | ||
87 | + .valueOf(deviceEvent.port().type().name())) | ||
88 | + .build()) | ||
89 | + .build(); | ||
90 | + | ||
91 | + return notification; | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Retrieves the protobuf generated device event type. | ||
96 | + * | ||
97 | + * @param event ONOS Device Event | ||
98 | + * @return generated Device Event Type | ||
99 | + */ | ||
100 | + private DeviceEventType getProtoType(DeviceEvent event) { | ||
101 | + DeviceEventType protobufEventType = null; | ||
102 | + DeviceEventType[] deviceEvents = DeviceEventType.values(); | ||
103 | + for (DeviceEventType deviceEventType : deviceEvents) { | ||
104 | + if (deviceEventType.name().equals(event.type().name())) { | ||
105 | + protobufEventType = deviceEventType; | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + return protobufEventType; | ||
110 | + } | ||
111 | +} |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.converter; | ||
16 | + | ||
17 | +import org.onosproject.event.Event; | ||
18 | + | ||
19 | +import com.google.protobuf.GeneratedMessage; | ||
20 | + | ||
21 | +/** | ||
22 | + * | ||
23 | + * APIs for converting between ONOS event objects and GPB data objects. | ||
24 | + * | ||
25 | + */ | ||
26 | +public interface EventConverter { | ||
27 | + | ||
28 | + /** | ||
29 | + * Converts ONOS specific event data to a format that is suitable for export | ||
30 | + * to Kafka. | ||
31 | + * | ||
32 | + * @param event ONOS Event object | ||
33 | + * @return converted data in GPB format. | ||
34 | + */ | ||
35 | + public GeneratedMessage convertToProtoMessage(Event<?, ?> event); | ||
36 | +} |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.converter; | ||
16 | + | ||
17 | +import org.onosproject.event.Event; | ||
18 | +import org.onosproject.grpc.net.Link.ConnectPoint; | ||
19 | +import org.onosproject.grpc.net.Link.LinkCore; | ||
20 | +import org.onosproject.grpc.net.Link.LinkState; | ||
21 | +import org.onosproject.grpc.net.Link.LinkType; | ||
22 | +import org.onosproject.grpc.net.LinkEvent.LinkEventType; | ||
23 | +import org.onosproject.grpc.net.LinkEvent.LinkNotification; | ||
24 | +import org.onosproject.net.link.LinkEvent; | ||
25 | +import org.slf4j.Logger; | ||
26 | +import org.slf4j.LoggerFactory; | ||
27 | + | ||
28 | +import com.google.protobuf.GeneratedMessage; | ||
29 | + | ||
30 | +/** | ||
31 | + * Converts for ONOS Link event message to GPB format. | ||
32 | + * | ||
33 | + */ | ||
34 | +class LinkEventConverter implements EventConverter { | ||
35 | + | ||
36 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
37 | + | ||
38 | + @Override | ||
39 | + public GeneratedMessage convertToProtoMessage(Event<?, ?> event) { | ||
40 | + | ||
41 | + LinkEvent linkEvent = (LinkEvent) event; | ||
42 | + | ||
43 | + if (!linkEventSubtypeSupported(linkEvent)) { | ||
44 | + log.error("Unsupported Onos Event {}. There is no matching" | ||
45 | + + "proto Event type", linkEvent.type().toString()); | ||
46 | + return null; | ||
47 | + } | ||
48 | + | ||
49 | + return buildDeviceProtoMessage(linkEvent); | ||
50 | + } | ||
51 | + | ||
52 | + private boolean linkEventSubtypeSupported(LinkEvent event) { | ||
53 | + LinkType[] kafkaLinkEvents = LinkType.values(); | ||
54 | + for (LinkType linkEventType : kafkaLinkEvents) { | ||
55 | + if (linkEventType.name().equals(event.type().name())) { | ||
56 | + return true; | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | + return false; | ||
61 | + } | ||
62 | + | ||
63 | + private LinkNotification buildDeviceProtoMessage(LinkEvent linkEvent) { | ||
64 | + LinkNotification notification = LinkNotification.newBuilder() | ||
65 | + .setLinkEventType(getProtoType(linkEvent)) | ||
66 | + .setLink(LinkCore.newBuilder() | ||
67 | + .setState(LinkState | ||
68 | + .valueOf(linkEvent.subject().state().name())) | ||
69 | + .setType(LinkType | ||
70 | + .valueOf(linkEvent.subject().type().name())) | ||
71 | + .setDst(ConnectPoint.newBuilder() | ||
72 | + .setDeviceId(linkEvent.subject().dst() | ||
73 | + .deviceId().toString()) | ||
74 | + .setPortNumber(linkEvent.subject().dst().port() | ||
75 | + .toString())) | ||
76 | + .setSrc(ConnectPoint.newBuilder() | ||
77 | + .setDeviceId(linkEvent.subject().src() | ||
78 | + .deviceId().toString()) | ||
79 | + .setPortNumber(linkEvent.subject().src().port() | ||
80 | + .toString()))) | ||
81 | + .build(); | ||
82 | + | ||
83 | + return notification; | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Returns the specific Kafka Device Event Type for the corresponding ONOS | ||
88 | + * Device Event Type. | ||
89 | + * | ||
90 | + * @param event ONOS Device Event | ||
91 | + * @return Kafka Device Event Type | ||
92 | + */ | ||
93 | + private LinkEventType getProtoType(LinkEvent event) { | ||
94 | + LinkEventType generatedEventType = null; | ||
95 | + LinkEventType[] kafkaEvents = LinkEventType.values(); | ||
96 | + for (LinkEventType linkEventType : kafkaEvents) { | ||
97 | + if (linkEventType.name().equals(event.type().name())) { | ||
98 | + generatedEventType = linkEventType; | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + return generatedEventType; | ||
103 | + } | ||
104 | +} |
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 | + * Converters for converting various ONOS events to their corresponding Protocol | ||
17 | + * Buffer format. | ||
18 | + * | ||
19 | + */ | ||
20 | +package org.onosproject.kafkaintegration.converter; |
apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/impl/Dispatcher.java
0 → 100644
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.impl; | ||
16 | + | ||
17 | +import org.onosproject.event.AbstractListenerManager; | ||
18 | +import org.onosproject.kafkaintegration.api.ExportableEventListener; | ||
19 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent; | ||
20 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; | ||
21 | +import org.slf4j.Logger; | ||
22 | +import org.slf4j.LoggerFactory; | ||
23 | + | ||
24 | +import com.google.protobuf.GeneratedMessage; | ||
25 | + | ||
26 | +/** | ||
27 | + * Dispatch ONOS Events to all interested Listeners. | ||
28 | + * | ||
29 | + */ | ||
30 | +public final class Dispatcher | ||
31 | + extends AbstractListenerManager<OnosEvent, ExportableEventListener> { | ||
32 | + | ||
33 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
34 | + | ||
35 | + // Exists to defeat instantiation | ||
36 | + private Dispatcher() { | ||
37 | + } | ||
38 | + | ||
39 | + private static class SingletonHolder { | ||
40 | + private static final Dispatcher INSTANCE = new Dispatcher(); | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Returns a static reference to the Listener Factory. | ||
45 | + * | ||
46 | + * @return singleton object | ||
47 | + */ | ||
48 | + public static Dispatcher getInstance() { | ||
49 | + return SingletonHolder.INSTANCE; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
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) { | ||
59 | + log.debug("Dispatching ONOS Event {}", eventType); | ||
60 | + post(new OnosEvent(eventType, message)); | ||
61 | + } | ||
62 | +} |
... | @@ -13,10 +13,14 @@ | ... | @@ -13,10 +13,14 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.kafkaintegration; | 16 | +package org.onosproject.kafkaintegration.impl; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
19 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; | ||
20 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK; | ||
19 | 21 | ||
22 | +import java.util.ArrayList; | ||
23 | +import java.util.List; | ||
20 | import java.util.Map; | 24 | import java.util.Map; |
21 | import java.util.UUID; | 25 | import java.util.UUID; |
22 | 26 | ||
... | @@ -31,9 +35,11 @@ import org.onosproject.core.CoreService; | ... | @@ -31,9 +35,11 @@ import org.onosproject.core.CoreService; |
31 | import org.onosproject.kafkaintegration.api.EventExporterService; | 35 | import org.onosproject.kafkaintegration.api.EventExporterService; |
32 | import org.onosproject.kafkaintegration.api.dto.EventSubscriber; | 36 | import org.onosproject.kafkaintegration.api.dto.EventSubscriber; |
33 | import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId; | 37 | import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId; |
38 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; | ||
34 | import org.onosproject.kafkaintegration.errors.InvalidApplicationException; | 39 | import org.onosproject.kafkaintegration.errors.InvalidApplicationException; |
35 | import org.onosproject.kafkaintegration.errors.InvalidGroupIdException; | 40 | import org.onosproject.kafkaintegration.errors.InvalidGroupIdException; |
36 | -import org.onosproject.kafkaintegration.errors.UnsupportedEventException; | 41 | +import org.onosproject.kafkaintegration.listener.ListenerFactory; |
42 | +import org.onosproject.kafkaintegration.listener.OnosEventListener; | ||
37 | import org.onosproject.net.device.DeviceService; | 43 | import org.onosproject.net.device.DeviceService; |
38 | import org.onosproject.net.link.LinkService; | 44 | import org.onosproject.net.link.LinkService; |
39 | import org.onosproject.store.serializers.KryoNamespaces; | 45 | import org.onosproject.store.serializers.KryoNamespaces; |
... | @@ -53,11 +59,14 @@ public class EventExporterManager implements EventExporterService { | ... | @@ -53,11 +59,14 @@ public class EventExporterManager implements EventExporterService { |
53 | private final Logger log = LoggerFactory.getLogger(getClass()); | 59 | private final Logger log = LoggerFactory.getLogger(getClass()); |
54 | 60 | ||
55 | // Stores the currently registered applications for event export service. | 61 | // Stores the currently registered applications for event export service. |
56 | - // Map of Appname to groupId | ||
57 | private Map<ApplicationId, EventSubscriberGroupId> registeredApps; | 62 | private Map<ApplicationId, EventSubscriberGroupId> registeredApps; |
58 | 63 | ||
64 | + private Map<Type, List<EventSubscriber>> subscriptions; | ||
65 | + | ||
59 | private static final String REGISTERED_APPS = "registered-applications"; | 66 | private static final String REGISTERED_APPS = "registered-applications"; |
60 | 67 | ||
68 | + private static final String SUBSCRIBED_APPS = "event-subscriptions"; | ||
69 | + | ||
61 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 70 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
62 | protected DeviceService deviceService; | 71 | protected DeviceService deviceService; |
63 | 72 | ||
... | @@ -70,8 +79,6 @@ public class EventExporterManager implements EventExporterService { | ... | @@ -70,8 +79,6 @@ public class EventExporterManager implements EventExporterService { |
70 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
71 | protected StorageService storageService; | 80 | protected StorageService storageService; |
72 | 81 | ||
73 | - private static final String NOT_YET_SUPPORTED = "Not yet supported."; | ||
74 | - | ||
75 | private ApplicationId appId; | 82 | private ApplicationId appId; |
76 | 83 | ||
77 | @Activate | 84 | @Activate |
... | @@ -87,6 +94,13 @@ public class EventExporterManager implements EventExporterService { | ... | @@ -87,6 +94,13 @@ public class EventExporterManager implements EventExporterService { |
87 | UUID.class)) | 94 | UUID.class)) |
88 | .build().asJavaMap(); | 95 | .build().asJavaMap(); |
89 | 96 | ||
97 | + subscriptions = storageService | ||
98 | + .<Type, List<EventSubscriber>>consistentMapBuilder() | ||
99 | + .withName(SUBSCRIBED_APPS) | ||
100 | + .withSerializer(Serializer.using(KryoNamespaces.API, | ||
101 | + EventSubscriber.class)) | ||
102 | + .build().asJavaMap(); | ||
103 | + | ||
90 | log.info("Started"); | 104 | log.info("Started"); |
91 | } | 105 | } |
92 | 106 | ||
... | @@ -117,16 +131,193 @@ public class EventExporterManager implements EventExporterService { | ... | @@ -117,16 +131,193 @@ public class EventExporterManager implements EventExporterService { |
117 | 131 | ||
118 | @Override | 132 | @Override |
119 | public void subscribe(EventSubscriber subscriber) | 133 | public void subscribe(EventSubscriber subscriber) |
120 | - throws UnsupportedEventException, InvalidGroupIdException, | 134 | + throws InvalidGroupIdException, InvalidApplicationException { |
121 | - InvalidApplicationException { | 135 | + |
136 | + checkNotNull(subscriber); | ||
137 | + | ||
138 | + if (!registeredApplication(subscriber.appName())) { | ||
139 | + throw new InvalidApplicationException("Application is not " | ||
140 | + + "registered to make this request."); | ||
141 | + } | ||
142 | + | ||
143 | + if (!validGroupId(subscriber.subscriberGroupId(), | ||
144 | + subscriber.appName())) { | ||
145 | + throw new InvalidGroupIdException("Incorrect group id in the request"); | ||
146 | + } | ||
147 | + | ||
148 | + OnosEventListener onosListener = getListener(subscriber.eventType()); | ||
149 | + checkNotNull(onosListener, | ||
150 | + "No listener for the supported event type - {}", | ||
151 | + subscriber.eventType()); | ||
152 | + | ||
153 | + applyListenerAction(subscriber.eventType(), onosListener, | ||
154 | + ListenerAction.START); | ||
155 | + | ||
156 | + // update internal state | ||
157 | + List<EventSubscriber> subscriptionList = | ||
158 | + subscriptions.get(subscriber.eventType()); | ||
159 | + if (subscriptionList == null) { | ||
160 | + subscriptionList = new ArrayList<EventSubscriber>(); | ||
161 | + } | ||
162 | + subscriptionList.add(subscriber); | ||
163 | + subscriptions.put(subscriber.eventType(), subscriptionList); | ||
164 | + | ||
165 | + log.info("Subscription for {} event by {} successfull", | ||
166 | + subscriber.eventType(), subscriber.appName()); | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * Checks if the application has registered. | ||
171 | + * | ||
172 | + * @param appName application name | ||
173 | + * @return true if application has registered | ||
174 | + */ | ||
175 | + private boolean registeredApplication(String appName) { | ||
176 | + | ||
177 | + checkNotNull(appName); | ||
178 | + ApplicationId appId = checkNotNull(coreService.getAppId(appName)); | ||
179 | + if (registeredApps.containsKey(appId)) { | ||
180 | + return true; | ||
181 | + } | ||
182 | + | ||
183 | + log.debug("{} is not registered", appName); | ||
184 | + return false; | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Actions that can be performed on the ONOS Event Listeners. | ||
189 | + * | ||
190 | + */ | ||
191 | + private enum ListenerAction { | ||
192 | + START, STOP; | ||
193 | + } | ||
194 | + | ||
195 | + /** | ||
196 | + * Applies the specified action on the Listener. | ||
197 | + * | ||
198 | + * @param eventType the ONOS Event type registered by the application | ||
199 | + * @param onosListener ONOS event listener | ||
200 | + * @param action to be performed on the listener | ||
201 | + */ | ||
202 | + private void applyListenerAction(Type eventType, | ||
203 | + OnosEventListener onosListener, | ||
204 | + ListenerAction action) { | ||
205 | + switch (eventType) { | ||
206 | + case DEVICE: | ||
207 | + if (action == ListenerAction.START) { | ||
208 | + onosListener.startListener(DEVICE, deviceService); | ||
209 | + } else { | ||
210 | + onosListener.stopListener(DEVICE, deviceService); | ||
211 | + } | ||
212 | + break; | ||
213 | + case LINK: | ||
214 | + if (action == ListenerAction.START) { | ||
215 | + onosListener.startListener(LINK, linkService); | ||
216 | + } else { | ||
217 | + onosListener.stopListener(LINK, linkService); | ||
218 | + } | ||
219 | + break; | ||
220 | + default: | ||
221 | + log.error("Cannot {} listener. Unsupported event type {} ", | ||
222 | + action.toString(), eventType.toString()); | ||
223 | + } | ||
224 | + } | ||
225 | + | ||
226 | + /** | ||
227 | + * Returns the ONOS event listener corresponding to the ONOS Event type. | ||
228 | + * | ||
229 | + * @param eventType ONOS event type | ||
230 | + * @return ONOS event listener | ||
231 | + */ | ||
232 | + private OnosEventListener getListener(Type eventType) { | ||
233 | + checkNotNull(eventType); | ||
234 | + ListenerFactory factory = ListenerFactory.getInstance(); | ||
235 | + OnosEventListener onosListener = factory.getListener(eventType); | ||
236 | + return onosListener; | ||
237 | + } | ||
122 | 238 | ||
123 | - throw new UnsupportedOperationException(NOT_YET_SUPPORTED); | 239 | + /** |
240 | + * Checks if the group id is valid for this registered application. | ||
241 | + * | ||
242 | + * @param groupId GroupId assigned to the subscriber | ||
243 | + * @param appName Registered Application name | ||
244 | + * @return true if valid groupId and false otherwise | ||
245 | + */ | ||
246 | + private boolean validGroupId(EventSubscriberGroupId groupId, | ||
247 | + String appName) { | ||
248 | + | ||
249 | + checkNotNull(groupId); | ||
250 | + | ||
251 | + ApplicationId appId = coreService.getAppId(appName); | ||
252 | + EventSubscriberGroupId registeredGroupId = registeredApps.get(appId); | ||
253 | + if (registeredGroupId.equals(groupId)) { | ||
254 | + return true; | ||
255 | + } | ||
256 | + | ||
257 | + return false; | ||
124 | } | 258 | } |
125 | 259 | ||
126 | @Override | 260 | @Override |
127 | public void unsubscribe(EventSubscriber subscriber) | 261 | public void unsubscribe(EventSubscriber subscriber) |
128 | throws InvalidGroupIdException, InvalidApplicationException { | 262 | throws InvalidGroupIdException, InvalidApplicationException { |
129 | 263 | ||
130 | - throw new UnsupportedOperationException(NOT_YET_SUPPORTED); | 264 | + checkNotNull(subscriber); |
265 | + | ||
266 | + if (!registeredApplication(subscriber.appName())) { | ||
267 | + throw new InvalidApplicationException("Application is not " | ||
268 | + + "registered to make this request."); | ||
269 | + } | ||
270 | + | ||
271 | + if (!validGroupId(subscriber.subscriberGroupId(), | ||
272 | + subscriber.appName())) { | ||
273 | + throw new InvalidGroupIdException("Incorrect group id in the request"); | ||
274 | + } | ||
275 | + | ||
276 | + if (!eventSubscribed(subscriber)) { | ||
277 | + log.error("No subscription to {} was found", | ||
278 | + subscriber.eventType()); | ||
279 | + return; | ||
280 | + } | ||
281 | + | ||
282 | + // If this is the only subscriber listening for this event, | ||
283 | + // stop the listener. | ||
284 | + List<EventSubscriber> subscribers = | ||
285 | + subscriptions.get(subscriber.eventType()); | ||
286 | + if (subscribers.size() == 1) { | ||
287 | + OnosEventListener onosListener = | ||
288 | + getListener(subscriber.eventType()); | ||
289 | + checkNotNull(onosListener, | ||
290 | + "No listener for the supported event type - {}", | ||
291 | + subscriber.eventType()); | ||
292 | + applyListenerAction(subscriber.eventType(), onosListener, | ||
293 | + ListenerAction.STOP); | ||
294 | + } | ||
295 | + | ||
296 | + // update internal state. | ||
297 | + subscribers.remove(subscriber); | ||
298 | + subscriptions.put(subscriber.eventType(), subscribers); | ||
299 | + | ||
300 | + log.info("Unsubscribed {} for {} events", subscriber.appName(), | ||
301 | + subscriber.eventType()); | ||
302 | + } | ||
303 | + | ||
304 | + /** | ||
305 | + * Checks if the subscriber has already subscribed to the requested event | ||
306 | + * type. | ||
307 | + * | ||
308 | + * @param subscriber the subscriber to a specific ONOS event | ||
309 | + * @return true if subscriber has subscribed to the ONOS event | ||
310 | + */ | ||
311 | + private boolean eventSubscribed(EventSubscriber subscriber) { | ||
312 | + | ||
313 | + List<EventSubscriber> subscriberList = | ||
314 | + subscriptions.get(subscriber.eventType()); | ||
315 | + | ||
316 | + if (subscriberList == null) { | ||
317 | + return false; | ||
318 | + } | ||
319 | + | ||
320 | + return subscriberList.contains(subscriber); | ||
131 | } | 321 | } |
322 | + | ||
132 | } | 323 | } | ... | ... |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.listener; | ||
16 | + | ||
17 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; | ||
18 | + | ||
19 | +import org.onosproject.event.ListenerService; | ||
20 | +import org.onosproject.kafkaintegration.impl.Dispatcher; | ||
21 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; | ||
22 | +import org.onosproject.kafkaintegration.converter.ConversionFactory; | ||
23 | +import org.onosproject.kafkaintegration.converter.EventConverter; | ||
24 | +import org.onosproject.net.device.DeviceEvent; | ||
25 | +import org.onosproject.net.device.DeviceListener; | ||
26 | +import org.onosproject.net.device.DeviceService; | ||
27 | + | ||
28 | +import com.google.protobuf.GeneratedMessage; | ||
29 | + | ||
30 | +/** | ||
31 | + * Listens for ONOS Device events. | ||
32 | + * | ||
33 | + */ | ||
34 | +final class DeviceEventsListener implements OnosEventListener { | ||
35 | + | ||
36 | + private boolean listenerRunning = false; | ||
37 | + | ||
38 | + private InnerListener listener = null; | ||
39 | + | ||
40 | + // Exists to defeat instantiation | ||
41 | + private DeviceEventsListener() { | ||
42 | + } | ||
43 | + | ||
44 | + private static class SingletonHolder { | ||
45 | + private static final DeviceEventsListener INSTANCE = | ||
46 | + new DeviceEventsListener(); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Returns a static reference to the Listener Factory. | ||
51 | + * | ||
52 | + * @return singleton object | ||
53 | + */ | ||
54 | + public static DeviceEventsListener getInstance() { | ||
55 | + return SingletonHolder.INSTANCE; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public void startListener(Type e, ListenerService<?, ?> service) { | ||
60 | + if (!listenerRunning) { | ||
61 | + listener = new InnerListener(); | ||
62 | + DeviceService deviceService = (DeviceService) service; | ||
63 | + deviceService.addListener(listener); | ||
64 | + listenerRunning = true; | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + private class InnerListener implements DeviceListener { | ||
69 | + | ||
70 | + @Override | ||
71 | + public void event(DeviceEvent arg0) { | ||
72 | + | ||
73 | + // Convert the event to GPB format | ||
74 | + ConversionFactory conversionFactory = | ||
75 | + ConversionFactory.getInstance(); | ||
76 | + EventConverter converter = conversionFactory.getConverter(DEVICE); | ||
77 | + GeneratedMessage message = converter.convertToProtoMessage(arg0); | ||
78 | + | ||
79 | + // Call Dispatcher and publish event | ||
80 | + Dispatcher.getInstance().publish(DEVICE, message); | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public void stopListener(Type e, ListenerService<?, ?> service) { | ||
86 | + if (listenerRunning) { | ||
87 | + DeviceService deviceService = (DeviceService) service; | ||
88 | + deviceService.removeListener(listener); | ||
89 | + listener = null; | ||
90 | + listenerRunning = false; | ||
91 | + } | ||
92 | + } | ||
93 | + | ||
94 | +} |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.listener; | ||
16 | + | ||
17 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK; | ||
18 | + | ||
19 | +import org.onosproject.event.ListenerService; | ||
20 | +import org.onosproject.kafkaintegration.impl.Dispatcher; | ||
21 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; | ||
22 | +import org.onosproject.kafkaintegration.converter.ConversionFactory; | ||
23 | +import org.onosproject.kafkaintegration.converter.EventConverter; | ||
24 | +import org.onosproject.net.link.LinkEvent; | ||
25 | +import org.onosproject.net.link.LinkListener; | ||
26 | +import org.onosproject.net.link.LinkService; | ||
27 | + | ||
28 | +import com.google.protobuf.GeneratedMessage; | ||
29 | + | ||
30 | +/** | ||
31 | + * Listens for ONOS Link Events. | ||
32 | + * | ||
33 | + */ | ||
34 | +final class LinkEventsListener implements OnosEventListener { | ||
35 | + | ||
36 | + private boolean listenerRunning = false; | ||
37 | + | ||
38 | + private InnerListener listener = null; | ||
39 | + | ||
40 | + // Exists to defeat instantiation | ||
41 | + private LinkEventsListener() { | ||
42 | + } | ||
43 | + | ||
44 | + private static class SingletonHolder { | ||
45 | + private static final LinkEventsListener INSTANCE = | ||
46 | + new LinkEventsListener(); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Returns a static reference to the Listener Factory. | ||
51 | + * | ||
52 | + * @return singleton object | ||
53 | + */ | ||
54 | + public static LinkEventsListener getInstance() { | ||
55 | + return SingletonHolder.INSTANCE; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public void startListener(Type e, ListenerService<?, ?> service) { | ||
60 | + if (!listenerRunning) { | ||
61 | + listener = new InnerListener(); | ||
62 | + LinkService linkService = (LinkService) service; | ||
63 | + linkService.addListener(listener); | ||
64 | + listenerRunning = true; | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + private class InnerListener implements LinkListener { | ||
69 | + | ||
70 | + @Override | ||
71 | + public void event(LinkEvent arg0) { | ||
72 | + | ||
73 | + // Convert the event to GPB format | ||
74 | + ConversionFactory conversionFactory = | ||
75 | + ConversionFactory.getInstance(); | ||
76 | + EventConverter converter = conversionFactory.getConverter(LINK); | ||
77 | + GeneratedMessage message = converter.convertToProtoMessage(arg0); | ||
78 | + | ||
79 | + // Call Dispatcher and publish event | ||
80 | + Dispatcher.getInstance().publish(LINK, message); | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public void stopListener(Type e, ListenerService<?, ?> service) { | ||
86 | + if (listenerRunning) { | ||
87 | + LinkService linkService = (LinkService) service; | ||
88 | + linkService.removeListener(listener); | ||
89 | + listenerRunning = false; | ||
90 | + } | ||
91 | + } | ||
92 | +} |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.listener; | ||
16 | + | ||
17 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; | ||
18 | +import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK; | ||
19 | + | ||
20 | +import java.util.HashMap; | ||
21 | +import java.util.Map; | ||
22 | + | ||
23 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; | ||
24 | + | ||
25 | +/** | ||
26 | + * Returns the appropriate listener object based on the ONOS event type. | ||
27 | + * | ||
28 | + */ | ||
29 | +public final class ListenerFactory { | ||
30 | + | ||
31 | + // Store listeners for all supported events | ||
32 | + private Map<Type, OnosEventListener> listeners = | ||
33 | + new HashMap<Type, OnosEventListener>() { | ||
34 | + { | ||
35 | + put(DEVICE, DeviceEventsListener.getInstance()); | ||
36 | + put(LINK, LinkEventsListener.getInstance()); | ||
37 | + } | ||
38 | + }; | ||
39 | + | ||
40 | + // Exists to defeat instantiation | ||
41 | + private ListenerFactory() { | ||
42 | + } | ||
43 | + | ||
44 | + private static class SingletonHolder { | ||
45 | + private static final ListenerFactory INSTANCE = new ListenerFactory(); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Returns a static reference to the Listener Factory. | ||
50 | + * | ||
51 | + * @return singleton object | ||
52 | + */ | ||
53 | + public static ListenerFactory getInstance() { | ||
54 | + return SingletonHolder.INSTANCE; | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the listener object for the specified ONOS event type. | ||
59 | + * | ||
60 | + * @param event ONOS Event type | ||
61 | + * @return return listener object | ||
62 | + */ | ||
63 | + public OnosEventListener getListener(Type event) { | ||
64 | + return listeners.get(event); | ||
65 | + } | ||
66 | + | ||
67 | +} |
1 | +/** | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | + * you may not use this file except in compliance with the License. | ||
5 | + * You may obtain a copy of the License at | ||
6 | + | ||
7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | + * Unless required by applicable law or agreed to in writing, software | ||
10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | + * See the License for the specific language governing permissions and | ||
13 | + * limitations under the License. | ||
14 | + */ | ||
15 | +package org.onosproject.kafkaintegration.listener; | ||
16 | + | ||
17 | +import org.onosproject.event.ListenerService; | ||
18 | +import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; | ||
19 | + | ||
20 | +/** | ||
21 | + * APIs for starting and stopping a ONOS Event listener. | ||
22 | + * | ||
23 | + */ | ||
24 | +public interface OnosEventListener { | ||
25 | + | ||
26 | + /** | ||
27 | + * Start the listener for the specific ONOS event type. | ||
28 | + * | ||
29 | + * @param event ONOS event type | ||
30 | + * @param service ONOS event listener for the specific event type | ||
31 | + */ | ||
32 | + void startListener(Type event, ListenerService<?, ?> service); | ||
33 | + | ||
34 | + /** | ||
35 | + * Stop the Listener for the specific ONOS event type. | ||
36 | + * | ||
37 | + * @param event ONOS event type | ||
38 | + * @param service ONOS event listener for the specific event type | ||
39 | + */ | ||
40 | + void stopListener(Type event, ListenerService<?, ?> service); | ||
41 | + | ||
42 | +} |
apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/listener/package-info.java
0 → 100644
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 | + * Listeners for listening to various ONOS events. | ||
17 | + * | ||
18 | + */ | ||
19 | +package org.onosproject.kafkaintegration.listener; |
... | @@ -14,15 +14,11 @@ | ... | @@ -14,15 +14,11 @@ |
14 | */ | 14 | */ |
15 | package org.onosproject.kafkaintegration.rest; | 15 | package org.onosproject.kafkaintegration.rest; |
16 | 16 | ||
17 | -import com.fasterxml.jackson.databind.ObjectMapper; | 17 | +import static com.google.common.base.Preconditions.checkNotNull; |
18 | -import com.fasterxml.jackson.databind.node.ObjectNode; | 18 | +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; |
19 | -import org.onosproject.codec.JsonCodec; | 19 | + |
20 | -import org.onosproject.kafkaintegration.api.EventExporterService; | 20 | +import java.io.IOException; |
21 | -import org.onosproject.kafkaintegration.api.dto.EventSubscriber; | 21 | +import java.io.InputStream; |
22 | -import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId; | ||
23 | -import org.onosproject.rest.AbstractWebResource; | ||
24 | -import org.slf4j.Logger; | ||
25 | -import org.slf4j.LoggerFactory; | ||
26 | 22 | ||
27 | import javax.ws.rs.Consumes; | 23 | import javax.ws.rs.Consumes; |
28 | import javax.ws.rs.DELETE; | 24 | import javax.ws.rs.DELETE; |
... | @@ -31,11 +27,17 @@ import javax.ws.rs.Path; | ... | @@ -31,11 +27,17 @@ import javax.ws.rs.Path; |
31 | import javax.ws.rs.Produces; | 27 | import javax.ws.rs.Produces; |
32 | import javax.ws.rs.core.MediaType; | 28 | import javax.ws.rs.core.MediaType; |
33 | import javax.ws.rs.core.Response; | 29 | import javax.ws.rs.core.Response; |
34 | -import java.io.IOException; | ||
35 | -import java.io.InputStream; | ||
36 | 30 | ||
37 | -import static com.google.common.base.Preconditions.checkNotNull; | 31 | +import org.onosproject.codec.JsonCodec; |
38 | -import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | 32 | +import org.onosproject.kafkaintegration.api.EventExporterService; |
33 | +import org.onosproject.kafkaintegration.api.dto.EventSubscriber; | ||
34 | +import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId; | ||
35 | +import org.onosproject.rest.AbstractWebResource; | ||
36 | +import org.slf4j.Logger; | ||
37 | +import org.slf4j.LoggerFactory; | ||
38 | + | ||
39 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
40 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
39 | 41 | ||
40 | /** | 42 | /** |
41 | * Rest Interfaces for subscribing/unsubscribing to event notifications. | 43 | * Rest Interfaces for subscribing/unsubscribing to event notifications. |
... | @@ -44,14 +46,19 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ... | @@ -44,14 +46,19 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST; |
44 | public class EventExporterWebResource extends AbstractWebResource { | 46 | public class EventExporterWebResource extends AbstractWebResource { |
45 | 47 | ||
46 | private final Logger log = LoggerFactory.getLogger(getClass()); | 48 | private final Logger log = LoggerFactory.getLogger(getClass()); |
47 | - public static final String JSON_NOT_NULL = "Registration Data cannot be empty"; | 49 | + public static final String JSON_NOT_NULL = |
48 | - public static final String REGISTRATION_SUCCESSFUL = "Registered Listener successfully"; | 50 | + "Registration Data cannot be empty"; |
49 | - public static final String DEREGISTRATION_SUCCESSFUL = "De-Registered Listener successfully"; | 51 | + public static final String REGISTRATION_SUCCESSFUL = |
50 | - public static final String EVENT_SUBSCRIPTION_SUCCESSFUL = "Event Registration successfull"; | 52 | + "Registered Listener successfully"; |
51 | - public static final String EVENT_SUBSCRIPTION_REMOVED = "Event De-Registration successfull"; | 53 | + public static final String DEREGISTRATION_SUCCESSFUL = |
54 | + "De-Registered Listener successfully"; | ||
55 | + public static final String EVENT_SUBSCRIPTION_SUCCESSFUL = | ||
56 | + "Event Registration successfull"; | ||
57 | + public static final String EVENT_SUBSCRIPTION_REMOVED = | ||
58 | + "Event De-Registration successfull"; | ||
52 | 59 | ||
53 | /** | 60 | /** |
54 | - * Registers a listener for Onos Events. | 61 | + * Registers a listener for ONOS Events. |
55 | * | 62 | * |
56 | * @param appName The application trying to register | 63 | * @param appName The application trying to register |
57 | * @return 200 OK with UUID string which should be used as Kafka Consumer | 64 | * @return 200 OK with UUID string which should be used as Kafka Consumer |
... | @@ -76,7 +83,7 @@ public class EventExporterWebResource extends AbstractWebResource { | ... | @@ -76,7 +83,7 @@ public class EventExporterWebResource extends AbstractWebResource { |
76 | } | 83 | } |
77 | 84 | ||
78 | /** | 85 | /** |
79 | - * Unregisters a listener for Onos Events. | 86 | + * Unregisters a listener for ONOS Events. |
80 | * | 87 | * |
81 | * @param appName The application trying to unregister | 88 | * @param appName The application trying to unregister |
82 | * @return 200 OK | 89 | * @return 200 OK |
... | @@ -93,9 +100,9 @@ public class EventExporterWebResource extends AbstractWebResource { | ... | @@ -93,9 +100,9 @@ public class EventExporterWebResource extends AbstractWebResource { |
93 | } | 100 | } |
94 | 101 | ||
95 | /** | 102 | /** |
96 | - * Creates subscription to a specific Onos event. | 103 | + * Creates subscription to a specific ONOS event. |
97 | * | 104 | * |
98 | - * @param input Subscription Data in Json format | 105 | + * @param input Subscription Data in JSON format |
99 | * @return 200 OK if successful or 400 BAD REQUEST | 106 | * @return 200 OK if successful or 400 BAD REQUEST |
100 | * @onos.rsModel KafkaSubscription | 107 | * @onos.rsModel KafkaSubscription |
101 | */ | 108 | */ |
... | @@ -118,9 +125,9 @@ public class EventExporterWebResource extends AbstractWebResource { | ... | @@ -118,9 +125,9 @@ public class EventExporterWebResource extends AbstractWebResource { |
118 | } | 125 | } |
119 | 126 | ||
120 | /** | 127 | /** |
121 | - * Parses Json Subscription Data from the external application. | 128 | + * Parses JSON Subscription Data from the external application. |
122 | * | 129 | * |
123 | - * @param node node within the parsed json tree. | 130 | + * @param input Subscription Data in JSON format |
124 | * @return parsed DTO object | 131 | * @return parsed DTO object |
125 | * @throws IOException | 132 | * @throws IOException |
126 | */ | 133 | */ |
... | @@ -137,9 +144,9 @@ public class EventExporterWebResource extends AbstractWebResource { | ... | @@ -137,9 +144,9 @@ public class EventExporterWebResource extends AbstractWebResource { |
137 | } | 144 | } |
138 | 145 | ||
139 | /** | 146 | /** |
140 | - * Deletes subscription from a specific Onos event. | 147 | + * Deletes subscription from a specific ONOS event. |
141 | * | 148 | * |
142 | - * @param input data in json format | 149 | + * @param input data in JSON format |
143 | * @return 200 OK if successful or 400 BAD REQUEST | 150 | * @return 200 OK if successful or 400 BAD REQUEST |
144 | * @onos.rsModel KafkaSubscription | 151 | * @onos.rsModel KafkaSubscription |
145 | */ | 152 | */ |
... | @@ -152,7 +159,7 @@ public class EventExporterWebResource extends AbstractWebResource { | ... | @@ -152,7 +159,7 @@ public class EventExporterWebResource extends AbstractWebResource { |
152 | 159 | ||
153 | try { | 160 | try { |
154 | EventSubscriber sub = parseSubscriptionData(input); | 161 | EventSubscriber sub = parseSubscriptionData(input); |
155 | - service.subscribe(sub); | 162 | + service.unsubscribe(sub); |
156 | } catch (Exception e) { | 163 | } catch (Exception e) { |
157 | log.error(e.getMessage()); | 164 | log.error(e.getMessage()); |
158 | return Response.status(BAD_REQUEST).entity(e.getMessage()).build(); | 165 | return Response.status(BAD_REQUEST).entity(e.getMessage()).build(); | ... | ... |
1 | -<?sxml version="1.0" encoding="UTF-8"?> | 1 | +<?xml version="1.0" encoding="UTF-8"?> |
2 | <!-- | 2 | <!-- |
3 | - ~ Copyright 2016 Open Networking Laboratory | 3 | + ~ Copyright 2016-present Open Networking Laboratory |
4 | ~ | 4 | ~ |
5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); | 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); |
6 | ~ you may not use this file except in compliance with the License. | 6 | ~ you may not use this file except in compliance with the License. |
... | @@ -14,218 +14,26 @@ | ... | @@ -14,218 +14,26 @@ |
14 | ~ See the License for the specific language governing permissions and | 14 | ~ See the License for the specific language governing permissions and |
15 | ~ limitations under the License. | 15 | ~ limitations under the License. |
16 | --> | 16 | --> |
17 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | 17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" |
18 | - <modelVersion>4.0.0</modelVersion> | 18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
19 | - | 19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
20 | <parent> | 20 | <parent> |
21 | <groupId>org.onosproject</groupId> | 21 | <groupId>org.onosproject</groupId> |
22 | <artifactId>onos-apps</artifactId> | 22 | <artifactId>onos-apps</artifactId> |
23 | <version>1.7.0-SNAPSHOT</version> | 23 | <version>1.7.0-SNAPSHOT</version> |
24 | <relativePath>../pom.xml</relativePath> | 24 | <relativePath>../pom.xml</relativePath> |
25 | </parent> | 25 | </parent> |
26 | + <modelVersion>4.0.0</modelVersion> | ||
26 | 27 | ||
27 | - <artifactId>onos-app-kafka</artifactId> | 28 | + <artifactId>onos-kafka</artifactId> |
28 | - <packaging>bundle</packaging> | ||
29 | - | ||
30 | - <description> | ||
31 | - ONOS Kafka Integration Application. | ||
32 | - This will export ONOS events to an external Kafka Server | ||
33 | - </description> | ||
34 | - <url>http://onosproject.org</url> | ||
35 | - | ||
36 | - <properties> | ||
37 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
38 | - <onos.version>1.6.0-SNAPSHOT</onos.version> | ||
39 | - <onos.app.name>org.onosproject.kafkaintegration</onos.app.name> | ||
40 | - <onos.app.title>Kafka Integration Application</onos.app.title> | ||
41 | - <onos.app.origin>Calix, Inc.</onos.app.origin> | ||
42 | - <web.context>/onos/kafka</web.context> | ||
43 | - <api.version>1.0.0</api.version> | ||
44 | - <api.package>org.onosproject.kafkaintegration.rest</api.package> | ||
45 | - <api.title>Kafka Integration Application REST API</api.title> | ||
46 | - <api.description> | ||
47 | - APIs for subscribing to Events generated by onos | ||
48 | - </api.description> | ||
49 | - <onos.app.category>Utility</onos.app.category> | ||
50 | - <onos.app.url>https://wiki.onosproject.org/display/ONOS/Kafka+Integration</onos.app.url> | ||
51 | - <onos.app.readme>Export onos events to a Northbound Kafka server</onos.app.readme> | ||
52 | - </properties> | ||
53 | - | ||
54 | - <dependencies> | ||
55 | - <dependency> | ||
56 | - <groupId>org.onosproject</groupId> | ||
57 | - <artifactId>onos-api</artifactId> | ||
58 | - <version>${onos.version}</version> | ||
59 | - </dependency> | ||
60 | - | ||
61 | - <dependency> | ||
62 | - <groupId>org.onosproject</groupId> | ||
63 | - <artifactId>onlab-osgi</artifactId> | ||
64 | - <version>${onos.version}</version> | ||
65 | - </dependency> | ||
66 | - | ||
67 | - <dependency> | ||
68 | - <groupId>org.onosproject</groupId> | ||
69 | - <artifactId>onos-rest</artifactId> | ||
70 | - <version>${onos.version}</version> | ||
71 | - </dependency> | ||
72 | - | ||
73 | - <dependency> | ||
74 | - <groupId>junit</groupId> | ||
75 | - <artifactId>junit</artifactId> | ||
76 | - <version>4.12</version> | ||
77 | - <scope>test</scope> | ||
78 | - </dependency> | ||
79 | - | ||
80 | - <dependency> | ||
81 | - <groupId>org.onosproject</groupId> | ||
82 | - <artifactId>onos-api</artifactId> | ||
83 | - <version>${onos.version}</version> | ||
84 | - <scope>test</scope> | ||
85 | - <classifier>tests</classifier> | ||
86 | - </dependency> | ||
87 | - | ||
88 | - <dependency> | ||
89 | - <groupId>javax.ws.rs</groupId> | ||
90 | - <artifactId>javax.ws.rs-api</artifactId> | ||
91 | - <version>2.0.1</version> | ||
92 | - </dependency> | ||
93 | - | ||
94 | - <dependency> | ||
95 | - <groupId>com.google.protobuf</groupId> | ||
96 | - <artifactId>protobuf-java</artifactId> | ||
97 | - <version>2.5.0</version> | ||
98 | - </dependency> | ||
99 | - | ||
100 | - <dependency> | ||
101 | - <groupId>org.codehaus.jackson</groupId> | ||
102 | - <artifactId>jackson-core-asl</artifactId> | ||
103 | - <version>1.9.13</version> | ||
104 | - </dependency> | ||
105 | - | ||
106 | - <dependency> | ||
107 | - <groupId>org.codehaus.jackson</groupId> | ||
108 | - <artifactId>jackson-mapper-asl</artifactId> | ||
109 | - <version>1.9.13</version> | ||
110 | - </dependency> | ||
111 | - | ||
112 | - <dependency> | ||
113 | - <groupId>org.glassfish.jersey.containers</groupId> | ||
114 | - <artifactId>jersey-container-servlet</artifactId> | ||
115 | - <version>2.22.2</version> | ||
116 | - </dependency> | ||
117 | - | ||
118 | - <dependency> | ||
119 | - <groupId>com.fasterxml.jackson.core</groupId> | ||
120 | - <artifactId>jackson-annotations</artifactId> | ||
121 | - <version>2.6.4</version> | ||
122 | - </dependency> | ||
123 | - | ||
124 | - <dependency> | ||
125 | - <groupId>org.onosproject</groupId> | ||
126 | - <artifactId>onos-core-serializers</artifactId> | ||
127 | - <version>${onos.version}</version> | ||
128 | - </dependency> | ||
129 | 29 | ||
130 | - <dependency> | 30 | + <packaging>pom</packaging> |
131 | - <groupId>org.apache.felix</groupId> | 31 | + <description>Kafka Integration Application</description> |
132 | - <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
133 | - <version>1.9.12</version> | ||
134 | - <scope>provided</scope> | ||
135 | - </dependency> | ||
136 | - </dependencies> | ||
137 | 32 | ||
138 | - <build> | 33 | + <modules> |
139 | - <plugins> | 34 | + <module>api</module> |
140 | - <plugin> | 35 | + <module>app</module> |
141 | - <groupId>org.apache.felix</groupId> | 36 | + </modules> |
142 | - <artifactId>maven-bundle-plugin</artifactId> | ||
143 | - <version>3.0.1</version> | ||
144 | - <extensions>true</extensions> | ||
145 | - <configuration> | ||
146 | - <instructions> | ||
147 | - <Bundle-SymbolicName> | ||
148 | - ${project.groupId}.${project.artifactId} | ||
149 | - </Bundle-SymbolicName> | ||
150 | - <_wab>src/main/webapp/</_wab> | ||
151 | - <Include-Resource> | ||
152 | - WEB-INF/classes/apidoc/swagger.json=target/swagger.json, | ||
153 | - {maven-resources} | ||
154 | - </Include-Resource> | ||
155 | - <Import-Package> | ||
156 | - org.slf4j, | ||
157 | - org.osgi.framework, | ||
158 | - javax.ws.rs, | ||
159 | - javax.ws.rs.core, | ||
160 | - org.glassfish.jersey.servlet, | ||
161 | - com.fasterxml.jackson.databind, | ||
162 | - com.fasterxml.jackson.databind.node, | ||
163 | - com.fasterxml.jackson.core, | ||
164 | - org.onlab.packet.*, | ||
165 | - org.onosproject.*, | ||
166 | - com.google.common.* | ||
167 | - </Import-Package> | ||
168 | - <Web-ContextPath>${web.context}</Web-ContextPath> | ||
169 | - </instructions> | ||
170 | - </configuration> | ||
171 | - </plugin> | ||
172 | - <plugin> | ||
173 | - <groupId>org.apache.maven.plugins</groupId> | ||
174 | - <artifactId>maven-compiler-plugin</artifactId> | ||
175 | - <version>2.5.1</version> | ||
176 | - <configuration> | ||
177 | - <source>1.8</source> | ||
178 | - <target>1.8</target> | ||
179 | - </configuration> | ||
180 | - </plugin> | ||
181 | - <plugin> | ||
182 | - <groupId>org.apache.felix</groupId> | ||
183 | - <artifactId>maven-scr-plugin</artifactId> | ||
184 | - <version>1.21.0</version> | ||
185 | - <executions> | ||
186 | - <execution> | ||
187 | - <id>generate-scr-srcdescriptor</id> | ||
188 | - <goals> | ||
189 | - <goal>scr</goal> | ||
190 | - </goals> | ||
191 | - </execution> | ||
192 | - </executions> | ||
193 | - <configuration> | ||
194 | - <supportedProjectTypes> | ||
195 | - <supportedProjectType>bundle</supportedProjectType> | ||
196 | - <supportedProjectType>war</supportedProjectType> | ||
197 | - </supportedProjectTypes> | ||
198 | - </configuration> | ||
199 | - </plugin> | ||
200 | - <plugin> | ||
201 | - <groupId>org.onosproject</groupId> | ||
202 | - <artifactId>onos-maven-plugin</artifactId> | ||
203 | - <version>1.9</version> | ||
204 | - <executions> | ||
205 | - <execution> | ||
206 | - <id>cfg</id> | ||
207 | - <phase>generate-resources</phase> | ||
208 | - <goals> | ||
209 | - <goal>cfg</goal> | ||
210 | - </goals> | ||
211 | - </execution> | ||
212 | - <execution> | ||
213 | - <id>swagger</id> | ||
214 | - <phase>generate-sources</phase> | ||
215 | - <goals> | ||
216 | - <goal>swagger</goal> | ||
217 | - </goals> | ||
218 | - </execution> | ||
219 | - <execution> | ||
220 | - <id>app</id> | ||
221 | - <phase>package</phase> | ||
222 | - <goals> | ||
223 | - <goal>app</goal> | ||
224 | - </goals> | ||
225 | - </execution> | ||
226 | - </executions> | ||
227 | - </plugin> | ||
228 | - </plugins> | ||
229 | - </build> | ||
230 | 37 | ||
231 | </project> | 38 | </project> |
39 | + | ... | ... |
... | @@ -3,6 +3,23 @@ option java_package = "org.onosproject.grpc.net"; | ... | @@ -3,6 +3,23 @@ option java_package = "org.onosproject.grpc.net"; |
3 | 3 | ||
4 | package Device; | 4 | package Device; |
5 | 5 | ||
6 | +message DeviceDescription { | ||
7 | + string device_Uri = 1; | ||
8 | + DeviceType type = 2; | ||
9 | + string manufacturer = 3; | ||
10 | + string hw_version = 4; | ||
11 | + string sw_version = 5; | ||
12 | + string serial_number = 6; | ||
13 | + string chassis_id = 7; | ||
14 | + map<string, string> annotations = 8; | ||
15 | +} | ||
16 | + | ||
17 | +enum MastershipRole { | ||
18 | + NONE = 0; | ||
19 | + MASTER = 1; | ||
20 | + STANDBY = 2; | ||
21 | +} | ||
22 | + | ||
6 | enum DeviceType { | 23 | enum DeviceType { |
7 | OTHER = 0; | 24 | OTHER = 0; |
8 | SWITCH = 1; | 25 | SWITCH = 1; |
... | @@ -20,8 +37,9 @@ enum DeviceType { | ... | @@ -20,8 +37,9 @@ enum DeviceType { |
20 | MICROWAVE = 13; | 37 | MICROWAVE = 13; |
21 | } | 38 | } |
22 | 39 | ||
23 | -message DeviceDescription { | 40 | +// Corresponds to org.onosproject.net.Device. |
24 | - string device_Uri = 1; | 41 | +message DeviceCore { |
42 | + string deviceId = 1; | ||
25 | DeviceType type = 2; | 43 | DeviceType type = 2; |
26 | string manufacturer = 3; | 44 | string manufacturer = 3; |
27 | string hw_version = 4; | 45 | string hw_version = 4; |
... | @@ -29,10 +47,4 @@ message DeviceDescription { | ... | @@ -29,10 +47,4 @@ message DeviceDescription { |
29 | string serial_number = 6; | 47 | string serial_number = 6; |
30 | string chassis_id = 7; | 48 | string chassis_id = 7; |
31 | map<string, string> annotations = 8; | 49 | map<string, string> annotations = 8; |
32 | -} | 50 | +} |
33 | - | ||
34 | -enum MastershipRole { | ||
35 | - NONE = 0; | ||
36 | - MASTER = 1; | ||
37 | - STANDBY = 2; | ||
38 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +syntax = "proto3"; | ||
2 | +option java_package = "org.onosproject.grpc.net"; | ||
3 | + | ||
4 | + | ||
5 | +import "Device.proto"; | ||
6 | +import "Port.proto"; | ||
7 | + | ||
8 | +package DeviceEvent; | ||
9 | + | ||
10 | +// Corresponds to org.onosproject.net.device.DeviceEvent. | ||
11 | +message DeviceNotification { | ||
12 | + Device.DeviceCore device = 1; | ||
13 | + DeviceEventType deviceEventType = 2; | ||
14 | + Port.PortCore port = 3; | ||
15 | +} | ||
16 | + | ||
17 | +enum DeviceEventType { | ||
18 | + DEVICE_ADDED = 0; | ||
19 | + DEVICE_UPDATED = 1; | ||
20 | + DEVICE_REMOVED = 2; | ||
21 | + DEVICE_SUSPENDED = 3; | ||
22 | + DEVICE_AVAILABILITY_CHANGED = 4; | ||
23 | + PORT_ADDED = 5; | ||
24 | + PORT_UPDATED = 6; | ||
25 | + PORT_REMOVED = 7; | ||
26 | + PORT_STATS_UPDATED = 8; | ||
27 | +} | ||
28 | + | ||
29 | + | ||
30 | + |
... | @@ -38,6 +38,20 @@ message ConnectPoint { | ... | @@ -38,6 +38,20 @@ message ConnectPoint { |
38 | string port_number = 2; | 38 | string port_number = 2; |
39 | } | 39 | } |
40 | 40 | ||
41 | +enum LinkState { | ||
42 | + ACTIVE = 0; | ||
43 | + INACTIVE = 1; | ||
44 | +} | ||
45 | + | ||
46 | +// Corresponds to org.onosproject.net.Link. | ||
47 | +message LinkCore { | ||
48 | + LinkState state = 1; | ||
49 | + ConnectPoint src = 2; | ||
50 | + ConnectPoint dst = 3; | ||
51 | + LinkType type = 4; | ||
52 | + map<string, string> annotations = 5; | ||
53 | +} | ||
54 | + | ||
41 | message LinkDescription { | 55 | message LinkDescription { |
42 | ConnectPoint src = 1; | 56 | ConnectPoint src = 1; |
43 | ConnectPoint dst = 2; | 57 | ConnectPoint dst = 2; | ... | ... |
1 | +syntax = "proto3"; | ||
2 | +option java_package = "org.onosproject.grpc.net"; | ||
3 | + | ||
4 | +package LinkEvent; | ||
5 | + | ||
6 | +import "Link.proto"; | ||
7 | + | ||
8 | +// Corresponds to org.onosproject.net.link.LinkEvent. | ||
9 | +message LinkNotification { | ||
10 | + LinkEventType linkEventType = 2; | ||
11 | + Link.LinkCore link = 3; | ||
12 | +} | ||
13 | + | ||
14 | +// Link Event Types | ||
15 | +enum LinkEventType { | ||
16 | + LINK_ADDED = 0; | ||
17 | + LINK_UPDATED = 1; | ||
18 | + LINK_REMOVED = 2; | ||
19 | +} |
... | @@ -31,6 +31,15 @@ message PortDescription { | ... | @@ -31,6 +31,15 @@ message PortDescription { |
31 | map<string, string> annotations = 8; | 31 | map<string, string> annotations = 8; |
32 | } | 32 | } |
33 | 33 | ||
34 | +// Corresponds to org.onosproject.net.Port. | ||
35 | +message PortCore { | ||
36 | + string port_number = 1; | ||
37 | + bool is_enabled = 2; | ||
38 | + PortType type = 3; | ||
39 | + int64 port_speed = 4; | ||
40 | + map<string, string> annotations = 5; | ||
41 | +} | ||
42 | + | ||
34 | message PortStatistics { | 43 | message PortStatistics { |
35 | int32 port = 1; | 44 | int32 port = 1; |
36 | int64 packets_received = 2; | 45 | int64 packets_received = 2; | ... | ... |
-
Please register or login to post a comment