Committed by
Gerrit Code Review
ONOS-3323 gRPC implementation of Remote Service
- Start modelling Device related service (ONOS-3306) - exclude machine generated code from doc Change-Id: Idffbcd883f813de79c6f05fedc9475f308efcc31
Showing
15 changed files
with
779 additions
and
5 deletions
... | @@ -46,11 +46,13 @@ | ... | @@ -46,11 +46,13 @@ |
46 | <plugin> | 46 | <plugin> |
47 | <groupId>org.apache.maven.plugins</groupId> | 47 | <groupId>org.apache.maven.plugins</groupId> |
48 | <artifactId>maven-javadoc-plugin</artifactId> | 48 | <artifactId>maven-javadoc-plugin</artifactId> |
49 | - <version>2.10.1</version> | 49 | + <version>2.10.3</version> |
50 | <configuration> | 50 | <configuration> |
51 | <show>package</show> | 51 | <show>package</show> |
52 | - <excludePackageNames>@external-excludes | 52 | + <excludePackageNames>@external-excludes</excludePackageNames> |
53 | - </excludePackageNames> | 53 | + <sourceFileExcludes> |
54 | + <sourceFileExclude>**/generated-sources/**</sourceFileExclude> | ||
55 | + </sourceFileExcludes> | ||
54 | <docfilessubdirs>true</docfilessubdirs> | 56 | <docfilessubdirs>true</docfilessubdirs> |
55 | <doctitle>ONOS Java API (1.4.0-SNAPSHOT)</doctitle> | 57 | <doctitle>ONOS Java API (1.4.0-SNAPSHOT)</doctitle> |
56 | <groups> | 58 | <groups> | ... | ... |
... | @@ -51,8 +51,11 @@ | ... | @@ -51,8 +51,11 @@ |
51 | <show>package</show> | 51 | <show>package</show> |
52 | <docfilessubdirs>true</docfilessubdirs> | 52 | <docfilessubdirs>true</docfilessubdirs> |
53 | <doctitle>ONOS Java API (1.4.0-SNAPSHOT)</doctitle> | 53 | <doctitle>ONOS Java API (1.4.0-SNAPSHOT)</doctitle> |
54 | - <excludePackageNames>@internal-excludes | 54 | + <excludePackageNames>@internal-excludes</excludePackageNames> |
55 | - </excludePackageNames> | 55 | + <sourceFileExcludes> |
56 | + <sourceFileExclude>**/generated-sources/**</sourceFileExclude> | ||
57 | + </sourceFileExcludes> | ||
58 | + | ||
56 | <groups> | 59 | <groups> |
57 | <group> | 60 | <group> |
58 | <title>Network Model & Services</title> | 61 | <title>Network Model & Services</title> | ... | ... |
incubator/rpc-grpc/features.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2015 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:com.google.protobuf/protobuf-java/3.0.0-beta-1</bundle> | ||
22 | + <bundle>mvn:io.netty/netty-common/4.1.0.Beta6</bundle> | ||
23 | + <bundle>mvn:io.netty/netty-buffer/4.1.0.Beta6</bundle> | ||
24 | + <bundle>mvn:io.netty/netty-transport/4.1.0.Beta6</bundle> | ||
25 | + <bundle>mvn:io.netty/netty-handler/4.1.0.Beta6</bundle> | ||
26 | + <bundle>mvn:io.netty/netty-codec/4.1.0.Beta6</bundle> | ||
27 | + <bundle>mvn:io.netty/netty-codec-http/4.1.0.Beta6</bundle> | ||
28 | + <bundle>mvn:io.netty/netty-codec-http2/4.1.0.Beta6</bundle> | ||
29 | + <bundle>mvn:io.netty/netty-resolver/4.1.0.Beta6</bundle> | ||
30 | + <bundle>mvn:com.twitter/hpack/0.11.0</bundle> | ||
31 | + <!-- TODO: Create shaded jar for these. --> | ||
32 | + <bundle>wrap:mvn:com.google.auth/google-auth-library-credentials/0.3.0$Bundle-SymbolicName=com.google.auth.google-auth-library-credentials&Bundle-Version=0.3.0</bundle> | ||
33 | + <bundle>wrap:mvn:com.google.auth/google-auth-library-oauth2-http/0.3.0$Bundle-SymbolicName=com.google.auth.google-auth-library-oauth2-http&Bundle-Version=0.3.0</bundle> | ||
34 | + <bundle>wrap:mvn:io.grpc/grpc-all/0.9.0$Bundle-SymbolicName=io.grpc.grpc-all&Bundle-Version=0.9.0&Import-Package=io.netty.*;version=4.1.0.Beta6,javax.net.ssl,com.google.protobuf.nano;resolution:=optional,okio;resolution:=optional,*</bundle> | ||
35 | + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle> | ||
36 | + </feature> | ||
37 | +</features> |
incubator/rpc-grpc/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2015 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" 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"> | ||
18 | + <modelVersion>4.0.0</modelVersion> | ||
19 | + <parent> | ||
20 | + <artifactId>onos-incubator</artifactId> | ||
21 | + <groupId>org.onosproject</groupId> | ||
22 | + <version>1.4.0-SNAPSHOT</version> | ||
23 | + </parent> | ||
24 | + | ||
25 | + <artifactId>onos-incubator-rpc-grpc</artifactId> | ||
26 | + <packaging>bundle</packaging> | ||
27 | + | ||
28 | + <description>ONOS inter-cluster RPC based on gRPC</description> | ||
29 | + <url>http://onosproject.org</url> | ||
30 | + | ||
31 | + <properties> | ||
32 | + <onos.app.name>org.onosproject.incubator.rpc.grpc</onos.app.name> | ||
33 | + <onos.app.requires>org.onosproject.incubator.rpc</onos.app.requires> | ||
34 | + <!-- Note: update feature.xml when updating --> | ||
35 | + <grpc.version>0.9.0</grpc.version> | ||
36 | + <grpc.netty.version>4.1.0.Beta6</grpc.netty.version> | ||
37 | + </properties> | ||
38 | + | ||
39 | + <pluginRepositories> | ||
40 | + <pluginRepository> | ||
41 | + <id>protoc-plugin</id> | ||
42 | + <url>https://dl.bintray.com/sergei-ivanov/maven/</url> | ||
43 | + </pluginRepository> | ||
44 | + </pluginRepositories> | ||
45 | + | ||
46 | + | ||
47 | + <dependencies> | ||
48 | + <dependency> | ||
49 | + <groupId>org.onosproject</groupId> | ||
50 | + <artifactId>onos-api</artifactId> | ||
51 | + </dependency> | ||
52 | + | ||
53 | + <dependency> | ||
54 | + <groupId>org.onosproject</groupId> | ||
55 | + <artifactId>onos-incubator-api</artifactId> | ||
56 | + </dependency> | ||
57 | + | ||
58 | + <dependency> | ||
59 | + <groupId>org.onosproject</groupId> | ||
60 | + <artifactId>onlab-osgi</artifactId> | ||
61 | + </dependency> | ||
62 | +<!-- | ||
63 | + <dependency> | ||
64 | + <groupId>io.grpc</groupId> | ||
65 | + <artifactId>grpc-all</artifactId> | ||
66 | + <version>${grpc.version}</version> | ||
67 | + </dependency> | ||
68 | +--> | ||
69 | + <dependency> | ||
70 | + <groupId>io.grpc</groupId> | ||
71 | + <artifactId>grpc-core</artifactId> | ||
72 | + <version>${grpc.version}</version> | ||
73 | + </dependency> | ||
74 | + <dependency> | ||
75 | + <groupId>io.grpc</groupId> | ||
76 | + <artifactId>grpc-protobuf</artifactId> | ||
77 | + <version>${grpc.version}</version> | ||
78 | + </dependency> | ||
79 | + <dependency> | ||
80 | + <groupId>io.grpc</groupId> | ||
81 | + <artifactId>grpc-stub</artifactId> | ||
82 | + <version>${grpc.version}</version> | ||
83 | + </dependency> | ||
84 | + <dependency> | ||
85 | + <groupId>io.grpc</groupId> | ||
86 | + <artifactId>grpc-netty</artifactId> | ||
87 | + <version>${grpc.version}</version> | ||
88 | + </dependency> | ||
89 | + <dependency> | ||
90 | + <groupId>io.grpc</groupId> | ||
91 | + <artifactId>grpc-auth</artifactId> | ||
92 | + <version>${grpc.version}</version> | ||
93 | + </dependency> | ||
94 | + | ||
95 | + <dependency> | ||
96 | + <groupId>junit</groupId> | ||
97 | + <artifactId>junit</artifactId> | ||
98 | + <scope>test</scope> | ||
99 | + </dependency> | ||
100 | + | ||
101 | + <dependency> | ||
102 | + <groupId>org.onosproject</groupId> | ||
103 | + <artifactId>onos-api</artifactId> | ||
104 | + <scope>test</scope> | ||
105 | + <classifier>tests</classifier> | ||
106 | + </dependency> | ||
107 | + | ||
108 | + <dependency> | ||
109 | + <groupId>org.apache.felix</groupId> | ||
110 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
111 | + <scope>provided</scope> | ||
112 | + </dependency> | ||
113 | + </dependencies> | ||
114 | + | ||
115 | + <build> | ||
116 | + <extensions> | ||
117 | + <extension> | ||
118 | + <groupId>kr.motd.maven</groupId> | ||
119 | + <artifactId>os-maven-plugin</artifactId> | ||
120 | + <version>1.4.0.Final</version> | ||
121 | + </extension> | ||
122 | + </extensions> | ||
123 | + | ||
124 | + <plugins> | ||
125 | + <plugin> | ||
126 | + <groupId>org.apache.felix</groupId> | ||
127 | + <artifactId>maven-bundle-plugin</artifactId> | ||
128 | + <extensions>true</extensions> | ||
129 | + </plugin> | ||
130 | + <plugin> | ||
131 | + <groupId>org.apache.maven.plugins</groupId> | ||
132 | + <artifactId>maven-compiler-plugin</artifactId> | ||
133 | + <configuration> | ||
134 | + <source>1.8</source> | ||
135 | + <target>1.8</target> | ||
136 | + </configuration> | ||
137 | + </plugin> | ||
138 | + <plugin> | ||
139 | + <groupId>org.apache.felix</groupId> | ||
140 | + <artifactId>maven-scr-plugin</artifactId> | ||
141 | + <executions> | ||
142 | + <execution> | ||
143 | + <id>generate-scr-srcdescriptor</id> | ||
144 | + <goals> | ||
145 | + <goal>scr</goal> | ||
146 | + </goals> | ||
147 | + </execution> | ||
148 | + </executions> | ||
149 | + <configuration> | ||
150 | + <!-- avoid searching into wrong source path --> | ||
151 | + <scanClasses>true</scanClasses> | ||
152 | + <supportedProjectTypes> | ||
153 | + <supportedProjectType>bundle</supportedProjectType> | ||
154 | + <supportedProjectType>war</supportedProjectType> | ||
155 | + </supportedProjectTypes> | ||
156 | + </configuration> | ||
157 | + </plugin> | ||
158 | + <plugin> | ||
159 | + <groupId>org.onosproject</groupId> | ||
160 | + <artifactId>onos-maven-plugin</artifactId> | ||
161 | + <executions> | ||
162 | + <execution> | ||
163 | + <id>cfg</id> | ||
164 | + <phase>generate-resources</phase> | ||
165 | + <goals> | ||
166 | + <goal>cfg</goal> | ||
167 | + </goals> | ||
168 | + </execution> | ||
169 | + <execution> | ||
170 | + <id>swagger</id> | ||
171 | + <phase>generate-sources</phase> | ||
172 | + <goals> | ||
173 | + <goal>swagger</goal> | ||
174 | + </goals> | ||
175 | + </execution> | ||
176 | + <execution> | ||
177 | + <id>app</id> | ||
178 | + <phase>package</phase> | ||
179 | + <goals> | ||
180 | + <goal>app</goal> | ||
181 | + </goals> | ||
182 | + </execution> | ||
183 | + </executions> | ||
184 | + </plugin> | ||
185 | + | ||
186 | + <plugin> | ||
187 | + <groupId>com.google.protobuf.tools</groupId> | ||
188 | + <artifactId>maven-protoc-plugin</artifactId> | ||
189 | + <version>0.4.2</version> | ||
190 | + <configuration> | ||
191 | + <!-- The version of protoc must match protobuf-java. If you don't | ||
192 | + depend on protobuf-java directly, you will be transitively depending on the | ||
193 | + protobuf-java version that grpc depends on. --> | ||
194 | + <protocArtifact>com.google.protobuf:protoc:3.0.0-beta-1:exe:${os.detected.classifier}</protocArtifact> | ||
195 | + <pluginId>grpc-java</pluginId> | ||
196 | + <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact> | ||
197 | + </configuration> | ||
198 | + <executions> | ||
199 | + <execution> | ||
200 | + <goals> | ||
201 | + <goal>compile</goal> | ||
202 | + <goal>compile-custom</goal> | ||
203 | + </goals> | ||
204 | + </execution> | ||
205 | + </executions> | ||
206 | + </plugin> | ||
207 | + | ||
208 | + <plugin> | ||
209 | + <groupId>org.codehaus.mojo</groupId> | ||
210 | + <artifactId>build-helper-maven-plugin</artifactId> | ||
211 | + <version>1.9.1</version> | ||
212 | + <executions> | ||
213 | + <execution> | ||
214 | + <id>add-source</id> | ||
215 | + <phase>generate-sources</phase> | ||
216 | + <goals> | ||
217 | + <goal>add-source</goal> | ||
218 | + </goals> | ||
219 | + <configuration> | ||
220 | + <sources> | ||
221 | + <source>${project.build.directory}/generated-sources/protobuf/java</source> | ||
222 | + <source>${project.build.directory}/generated-sources/protobuf/grpc-java</source> | ||
223 | + </sources> | ||
224 | + </configuration> | ||
225 | + </execution> | ||
226 | + </executions> | ||
227 | + </plugin> | ||
228 | + | ||
229 | + </plugins> | ||
230 | + </build> | ||
231 | + | ||
232 | + <!-- gRPC requires more recent version of netty --> | ||
233 | + <dependencyManagement> | ||
234 | + <dependencies> | ||
235 | + <dependency> | ||
236 | + <groupId>io.netty</groupId> | ||
237 | + <artifactId>netty-codec</artifactId> | ||
238 | + <version>${grpc.netty.version}</version> | ||
239 | + </dependency> | ||
240 | + <dependency> | ||
241 | + <groupId>io.netty</groupId> | ||
242 | + <artifactId>netty-transport</artifactId> | ||
243 | + <version>${grpc.netty.version}</version> | ||
244 | + </dependency> | ||
245 | + <dependency> | ||
246 | + <groupId>io.netty</groupId> | ||
247 | + <artifactId>netty-handler</artifactId> | ||
248 | + <version>${grpc.netty.version}</version> | ||
249 | + </dependency> | ||
250 | + <dependency> | ||
251 | + <groupId>io.netty</groupId> | ||
252 | + <artifactId>netty-buffer</artifactId> | ||
253 | + <version>${grpc.netty.version}</version> | ||
254 | + </dependency> | ||
255 | + <dependency> | ||
256 | + <groupId>io.netty</groupId> | ||
257 | + <artifactId>netty-common</artifactId> | ||
258 | + <version>${grpc.netty.version}</version> | ||
259 | + </dependency> | ||
260 | + <dependency> | ||
261 | + <groupId>com.twitter</groupId> | ||
262 | + <artifactId>hpack</artifactId> | ||
263 | + <!-- 0.11.0 and later are published as a bundle --> | ||
264 | + <version>0.11.0</version> | ||
265 | + </dependency> | ||
266 | + </dependencies> | ||
267 | + </dependencyManagement> | ||
268 | + | ||
269 | +</project> |
1 | +/* | ||
2 | + * Copyright 2015 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 | +package org.onosproject.incubator.rpc.grpc; | ||
17 | + | ||
18 | +import java.util.Map; | ||
19 | + | ||
20 | +import org.onosproject.net.device.DeviceProvider; | ||
21 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
22 | +import org.onosproject.net.device.DeviceProviderService; | ||
23 | +import org.onosproject.net.provider.AbstractProviderRegistry; | ||
24 | +import org.slf4j.Logger; | ||
25 | +import org.slf4j.LoggerFactory; | ||
26 | + | ||
27 | +import com.google.common.collect.Maps; | ||
28 | + | ||
29 | +import io.grpc.Channel; | ||
30 | +import io.grpc.ManagedChannel; | ||
31 | + | ||
32 | +// gRPC Client side | ||
33 | +/** | ||
34 | + * Proxy object to handle DeviceProviderRegistry calls. | ||
35 | + * | ||
36 | + * RPC wise, this will start/stop bidirectional streaming service sessions. | ||
37 | + */ | ||
38 | +final class DeviceProviderRegistryClientProxy | ||
39 | + extends AbstractProviderRegistry<DeviceProvider, DeviceProviderService> | ||
40 | + implements DeviceProviderRegistry { | ||
41 | + | ||
42 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
43 | + | ||
44 | + private final Channel channel; | ||
45 | + | ||
46 | + private final Map<DeviceProvider, DeviceProviderServiceClientProxy> pServices; | ||
47 | + | ||
48 | + DeviceProviderRegistryClientProxy(ManagedChannel channel) { | ||
49 | + this.channel = channel; | ||
50 | + pServices = Maps.newIdentityHashMap(); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + protected synchronized DeviceProviderService createProviderService(DeviceProvider provider) { | ||
55 | + | ||
56 | + // Create session | ||
57 | + DeviceProviderServiceClientProxy pService = new DeviceProviderServiceClientProxy(provider, channel); | ||
58 | + log.debug("Created DeviceProviderServiceClientProxy", pService); | ||
59 | + | ||
60 | + DeviceProviderServiceClientProxy old = pServices.put(provider, pService); | ||
61 | + if (old != null) { | ||
62 | + // sanity check, can go away | ||
63 | + log.warn("Duplicate registration detected for {}", provider.id()); | ||
64 | + } | ||
65 | + return pService; | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public synchronized void unregister(DeviceProvider provider) { | ||
70 | + DeviceProviderServiceClientProxy pService = pServices.remove(provider); | ||
71 | + log.debug("Unregistering DeviceProviderServiceClientProxy", pService); | ||
72 | + super.unregister(provider); | ||
73 | + if (pService != null) { | ||
74 | + pService.shutdown(); | ||
75 | + } | ||
76 | + } | ||
77 | +} |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceContext.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 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 | +package org.onosproject.incubator.rpc.grpc; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | + | ||
20 | +import java.util.Map; | ||
21 | +import java.util.NoSuchElementException; | ||
22 | +import java.util.concurrent.ConcurrentHashMap; | ||
23 | + | ||
24 | +import org.onosproject.incubator.rpc.RemoteServiceContext; | ||
25 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
26 | +import org.slf4j.Logger; | ||
27 | +import org.slf4j.LoggerFactory; | ||
28 | + | ||
29 | +import com.google.common.base.MoreObjects; | ||
30 | + | ||
31 | +import io.grpc.ManagedChannel; | ||
32 | + | ||
33 | +// gRPC Client side | ||
34 | +// Probably there should be plug-in mechanism in the future. | ||
35 | +/** | ||
36 | + * RemoteServiceContext based on gRPC. | ||
37 | + * | ||
38 | + * <p> | ||
39 | + * Currently it supports {@link DeviceProviderRegistry}. | ||
40 | + */ | ||
41 | +public class GrpcRemoteServiceContext implements RemoteServiceContext { | ||
42 | + | ||
43 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
44 | + | ||
45 | + private final Map<Class<? extends Object>, Object> services = new ConcurrentHashMap<>(); | ||
46 | + | ||
47 | + private final ManagedChannel channel; | ||
48 | + | ||
49 | + public GrpcRemoteServiceContext(ManagedChannel channel) { | ||
50 | + this.channel = checkNotNull(channel); | ||
51 | + services.put(DeviceProviderRegistry.class, new DeviceProviderRegistryClientProxy(channel)); | ||
52 | + } | ||
53 | + | ||
54 | + | ||
55 | + @Override | ||
56 | + public <T> T get(Class<T> serviceClass) { | ||
57 | + @SuppressWarnings("unchecked") | ||
58 | + T service = (T) services.get(serviceClass); | ||
59 | + if (service != null) { | ||
60 | + return service; | ||
61 | + } | ||
62 | + log.error("{} not supported", serviceClass); | ||
63 | + throw new NoSuchElementException(serviceClass.getTypeName() + " not supported"); | ||
64 | + } | ||
65 | + | ||
66 | + | ||
67 | + @Override | ||
68 | + public String toString() { | ||
69 | + return MoreObjects.toStringHelper(this) | ||
70 | + .add("services", services.keySet()) | ||
71 | + .add("channel", channel.authority()) | ||
72 | + .toString(); | ||
73 | + } | ||
74 | + | ||
75 | +} |
incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceProvider.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 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 | +package org.onosproject.incubator.rpc.grpc; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkArgument; | ||
19 | + | ||
20 | +import java.net.URI; | ||
21 | +import java.util.Map; | ||
22 | +import java.util.Objects; | ||
23 | +import java.util.concurrent.ConcurrentHashMap; | ||
24 | + | ||
25 | +import org.apache.felix.scr.annotations.Activate; | ||
26 | +import org.apache.felix.scr.annotations.Component; | ||
27 | +import org.apache.felix.scr.annotations.Deactivate; | ||
28 | +import org.apache.felix.scr.annotations.Reference; | ||
29 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
30 | +import org.onosproject.incubator.rpc.RemoteServiceContext; | ||
31 | +import org.onosproject.incubator.rpc.RemoteServiceContextProvider; | ||
32 | +import org.onosproject.incubator.rpc.RemoteServiceContextProviderService; | ||
33 | +import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry; | ||
34 | +import org.onosproject.net.provider.ProviderId; | ||
35 | +import org.slf4j.Logger; | ||
36 | +import org.slf4j.LoggerFactory; | ||
37 | + | ||
38 | +import io.grpc.ManagedChannel; | ||
39 | +import io.grpc.netty.NegotiationType; | ||
40 | +import io.grpc.netty.NettyChannelBuilder; | ||
41 | + | ||
42 | + | ||
43 | +// gRPC Client side | ||
44 | +/** | ||
45 | + * RemoteServiceContextProvider based on gRPC. | ||
46 | + */ | ||
47 | +@Component(immediate = true) | ||
48 | +public class GrpcRemoteServiceProvider implements RemoteServiceContextProvider { | ||
49 | + | ||
50 | + public static final String GRPC_SCHEME = "grpc"; | ||
51 | + | ||
52 | + public static final String RPC_PROVIDER_NAME = "org.onosproject.rpc.provider.grpc"; | ||
53 | + | ||
54 | + private static final ProviderId PID = new ProviderId(GRPC_SCHEME, RPC_PROVIDER_NAME); | ||
55 | + | ||
56 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
57 | + | ||
58 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
59 | + protected RemoteServiceProviderRegistry rpcRegistry; | ||
60 | + | ||
61 | + private Map<URI, ManagedChannel> channels = new ConcurrentHashMap<>(); | ||
62 | + | ||
63 | + private RemoteServiceContextProviderService providerService; | ||
64 | + | ||
65 | + | ||
66 | + @Activate | ||
67 | + protected void activate() { | ||
68 | + providerService = rpcRegistry.register(this); | ||
69 | + | ||
70 | + // FIXME remove me. test code to see if gRPC loads in karaf | ||
71 | + //getChannel(URI.create("grpc://localhost:8080")); | ||
72 | + | ||
73 | + log.info("Started"); | ||
74 | + } | ||
75 | + | ||
76 | + @Deactivate | ||
77 | + protected void deactivate() { | ||
78 | + rpcRegistry.unregister(this); | ||
79 | + | ||
80 | + // shutdown all channels | ||
81 | + channels.values().stream() | ||
82 | + .forEach(ManagedChannel::shutdown); | ||
83 | + // Should we wait for shutdown? How? | ||
84 | + channels.clear(); | ||
85 | + log.info("Stopped"); | ||
86 | + } | ||
87 | + | ||
88 | + @Override | ||
89 | + public ProviderId id() { | ||
90 | + return PID; | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public RemoteServiceContext get(URI uri) { | ||
95 | + // Create gRPC client | ||
96 | + return new GrpcRemoteServiceContext(getChannel(uri)); | ||
97 | + } | ||
98 | + | ||
99 | + private ManagedChannel getChannel(URI uri) { | ||
100 | + checkArgument(Objects.equals(GRPC_SCHEME, uri.getScheme()), | ||
101 | + "Invalid URI scheme: %s", uri.getScheme()); | ||
102 | + | ||
103 | + return channels.compute(uri, (u, ch) -> { | ||
104 | + if (ch != null && !ch.isShutdown()) { | ||
105 | + return ch; | ||
106 | + } else { | ||
107 | + return createChannel(u); | ||
108 | + } | ||
109 | + }); | ||
110 | + } | ||
111 | + | ||
112 | + private ManagedChannel createChannel(URI uri) { | ||
113 | + log.debug("Creating channel for {}", uri); | ||
114 | + return NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort()) | ||
115 | + .negotiationType(NegotiationType.PLAINTEXT) | ||
116 | + .build(); | ||
117 | + } | ||
118 | + | ||
119 | +} |
incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceServer.java
0 → 100644
This diff is collapsed. Click to expand it.
1 | +/* | ||
2 | + * Copyright 2015 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 | +/** | ||
18 | + * gRPC based RemoteServiceProvider implementation. | ||
19 | + */ | ||
20 | +package org.onosproject.incubator.rpc.grpc; |
1 | +syntax = "proto3"; | ||
2 | +option java_package = "org.onosproject.grpc"; | ||
3 | + | ||
4 | +import "Port.proto"; | ||
5 | +package Device; | ||
6 | + | ||
7 | +enum DeviceType { | ||
8 | + OTHER = 0; | ||
9 | + SWITCH = 1; | ||
10 | + ROUTER = 2; | ||
11 | + ROADM = 3; | ||
12 | + OTN = 4; | ||
13 | + ROADM_OTN = 5; | ||
14 | + FIREWALL = 6; | ||
15 | + BALANCER = 7; | ||
16 | + IPS = 8; | ||
17 | + IDS = 9; | ||
18 | + CONTROLLER = 10; | ||
19 | + VIRTUAL = 11; | ||
20 | + FIBER_SWITCH = 12; | ||
21 | + MICROWAVE = 13; | ||
22 | +} | ||
23 | + | ||
24 | +message DeviceDescription { | ||
25 | + string device_Uri = 1; | ||
26 | + DeviceType type = 2; | ||
27 | + string manufacturer = 3; | ||
28 | + string hw_version = 4; | ||
29 | + string sw_version = 5; | ||
30 | + string serial_number = 6; | ||
31 | + string chassis_id = 7; | ||
32 | + map<string, string> annotations = 8; | ||
33 | +} | ||
34 | + | ||
35 | +enum MastershipRole { | ||
36 | + NONE = 0; | ||
37 | + MASTER = 1; | ||
38 | + STANDBY = 2; | ||
39 | +} | ||
40 | + | ||
41 | +message DeviceConnected { | ||
42 | + // DeviceID as String DeviceId#toString | ||
43 | + string device_id = 1; | ||
44 | + DeviceDescription device_description = 2; | ||
45 | +} | ||
46 | + | ||
47 | +message DeviceDisconnected { | ||
48 | + // DeviceID as String DeviceId#toString | ||
49 | + string device_id = 1; | ||
50 | +} | ||
51 | + | ||
52 | +message UpdatePorts { | ||
53 | + // DeviceID as String DeviceId#toString | ||
54 | + string device_id = 1; | ||
55 | + repeated Port.PortDescription port_descriptions= 2; | ||
56 | +} | ||
57 | + | ||
58 | +message PortStatusChanged { | ||
59 | + // DeviceID as String DeviceId#toString | ||
60 | + string device_id = 1; | ||
61 | + Port.PortDescription port_description= 2; | ||
62 | +} | ||
63 | + | ||
64 | +message ReceivedRoleReply { | ||
65 | + // DeviceID as String DeviceId#toString | ||
66 | + string device_id = 1; | ||
67 | + MastershipRole requested = 2; | ||
68 | + MastershipRole response = 3; | ||
69 | +} | ||
70 | + | ||
71 | +message UpdatePortStatistics { | ||
72 | + // DeviceID as String DeviceId#toString | ||
73 | + string device_id = 1; | ||
74 | + repeated Port.PortStatistics port_statistics = 2; | ||
75 | +} | ||
76 | + | ||
77 | +message RegisterProvider { | ||
78 | + // DeviceProvider's ProviderId scheme | ||
79 | + string provider_scheme = 1; | ||
80 | +} | ||
81 | + | ||
82 | +message DeviceProviderServiceMsg { | ||
83 | + oneof method { | ||
84 | + DeviceConnected device_connected= 1; | ||
85 | + DeviceDisconnected device_disconnected = 2; | ||
86 | + UpdatePorts update_ports= 3; | ||
87 | + PortStatusChanged port_status_changed = 4; | ||
88 | + ReceivedRoleReply received_role_reply = 5; | ||
89 | + UpdatePortStatistics update_port_statistics = 6; | ||
90 | + | ||
91 | + // This message is for return value of DeviceProvider#isReachable | ||
92 | + IsReachableResponse is_reachable_response = 7; | ||
93 | + | ||
94 | + // This MUST be the 1st message over the stream | ||
95 | + RegisterProvider register_provider = 8; | ||
96 | + } | ||
97 | +} | ||
98 | + | ||
99 | +message TriggerProbe { | ||
100 | + // DeviceID as String DeviceId#toString | ||
101 | + string device_id = 1; | ||
102 | +} | ||
103 | + | ||
104 | +message RoleChanged { | ||
105 | + // DeviceID as String DeviceId#toString | ||
106 | + string device_id = 1; | ||
107 | + MastershipRole new_role = 2; | ||
108 | +} | ||
109 | + | ||
110 | +message IsReachableRequest { | ||
111 | + int32 xid = 1; | ||
112 | + // DeviceID as String DeviceId#toString | ||
113 | + string device_id = 2; | ||
114 | +} | ||
115 | + | ||
116 | +message IsReachableResponse { | ||
117 | + int32 xid = 1; | ||
118 | + bool is_reachable = 2; | ||
119 | +} | ||
120 | + | ||
121 | +message DeviceProviderMsg { | ||
122 | + oneof method { | ||
123 | + TriggerProbe trigger_probe = 1; | ||
124 | + RoleChanged role_changed = 2; | ||
125 | + IsReachableRequest is_reachable_request= 3; | ||
126 | + } | ||
127 | +} | ||
128 | + | ||
129 | +service DeviceProviderRegistryRpc { | ||
130 | + rpc Register(stream DeviceProviderServiceMsg) returns (stream DeviceProviderMsg); | ||
131 | +} |
incubator/rpc-grpc/src/main/proto/Port.proto
0 → 100644
1 | +syntax = "proto3"; | ||
2 | +option java_package = "org.onosproject.grpc"; | ||
3 | + | ||
4 | +package Port; | ||
5 | + | ||
6 | +enum PortType { | ||
7 | + // Signifies copper-based connectivity. | ||
8 | + COPPER = 0; | ||
9 | + // Signifies optical fiber-based connectivity. | ||
10 | + FIBER = 1; | ||
11 | + // Signifies optical fiber-based packet port. | ||
12 | + PACKET = 2; | ||
13 | + // Signifies optical fiber-based optical tributary port (called T-port). | ||
14 | + //The signal from the client side will be formed into a ITU G.709 (OTN) frame. | ||
15 | + ODUCLT = 3; | ||
16 | + // Signifies optical fiber-based Line-side port (called L-port). | ||
17 | + OCH = 4; | ||
18 | + // Signifies optical fiber-based WDM port (called W-port). | ||
19 | + //Optical Multiplexing Section (See ITU G.709). | ||
20 | + OMS = 5; | ||
21 | + // Signifies virtual port. | ||
22 | + VIRTUAL = 6; | ||
23 | +} | ||
24 | + | ||
25 | +// TODO What are we going to do with more specific PortDescription ... | ||
26 | +message PortDescription { | ||
27 | + // PortNumber as String PortNumber#toString | ||
28 | + string port_number = 1; | ||
29 | + bool is_enabled = 2; | ||
30 | + PortType type = 3; | ||
31 | + int64 port_speed = 4; | ||
32 | + map<string, string> annotations = 8; | ||
33 | +} | ||
34 | + | ||
35 | +message PortStatistics { | ||
36 | + int32 port = 1; | ||
37 | + int64 packets_received = 2; | ||
38 | + int64 packets_sent = 3; | ||
39 | + // TODO add all other fields | ||
40 | +} |
incubator/rpc-grpc/src/test/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceTest.java
0 → 100644
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment