Refactor protocol buffer to split models into different packages
Change-Id: I26152ba227ebe9afd871c6e501ccca17c49e1e4e
diff --git a/incubator/rpc-grpc/pom.xml b/incubator/rpc-grpc/pom.xml
index 4139f18..af56f07 100644
--- a/incubator/rpc-grpc/pom.xml
+++ b/incubator/rpc-grpc/pom.xml
@@ -19,7 +19,7 @@
<parent>
<artifactId>onos-incubator-grpc-dependencies</artifactId>
<groupId>org.onosproject</groupId>
- <version>1.11-SNAPSHOT</version>
+ <version>1.11.0-SNAPSHOT</version>
<relativePath>../grpc-dependencies/pom.xml</relativePath>
</parent>
@@ -34,7 +34,7 @@
<onos.app.title>ONOS gRPC API</onos.app.title>
<onos.app.requires>
org.onosproject.incubator.rpc,
- org.onosproject.incubator.protobuf,
+ org.onosproject.incubator.protobuf.models,
org.onosproject.incubator.grpc
</onos.app.requires>
</properties>
@@ -96,7 +96,7 @@
<dependency>
<groupId>org.onosproject</groupId>
- <artifactId>onos-incubator-protobuf</artifactId>
+ <artifactId>onos-incubator-protobuf-models</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java
index 4f41835..1da5ddd 100644
--- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java
+++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java
@@ -31,6 +31,8 @@
import org.onosproject.grpc.net.device.DeviceService.IsReachableRequest;
import org.onosproject.grpc.net.device.DeviceService.RoleChanged;
import org.onosproject.grpc.net.device.DeviceService.TriggerProbe;
+import org.onosproject.grpc.net.device.models.PortDescriptionProtoOuterClass.PortDescriptionProto;
+import org.onosproject.grpc.net.device.models.PortStatisticsProtoOuterClass.PortStatisticsProto;
import org.onosproject.incubator.protobuf.models.ProtobufUtils;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
@@ -115,7 +117,7 @@
checkValidity();
DeviceProviderServiceMsg.Builder builder = DeviceProviderServiceMsg.newBuilder();
- List<org.onosproject.grpc.net.Port.PortDescription> portDescs =
+ List<PortDescriptionProto> portDescs =
portDescriptions.stream()
.map(ProtobufUtils::translate)
.collect(toList());
@@ -168,7 +170,7 @@
checkValidity();
DeviceProviderServiceMsg.Builder builder = DeviceProviderServiceMsg.newBuilder();
- List<org.onosproject.grpc.net.Port.PortStatistics> portStats =
+ List<PortStatisticsProto> portStats =
portStatistics.stream()
.map(ProtobufUtils::translate)
.collect(toList());
diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java
index 78f9f37..5c40c90 100644
--- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java
+++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java
@@ -15,18 +15,16 @@
*/
package org.onosproject.incubator.rpc.grpc;
-import static org.onosproject.incubator.protobuf.models.ProtobufUtils.asMap;
-
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.onosproject.grpc.net.Link.LinkType;
+import com.google.common.annotations.Beta;
+import com.google.common.util.concurrent.ListenableFuture;
+import io.grpc.Channel;
import org.onosproject.grpc.net.link.LinkProviderServiceRpcGrpc;
import org.onosproject.grpc.net.link.LinkProviderServiceRpcGrpc.LinkProviderServiceRpcFutureStub;
import org.onosproject.grpc.net.link.LinkService.LinkDetectedMsg;
import org.onosproject.grpc.net.link.LinkService.LinkVanishedMsg;
import org.onosproject.grpc.net.link.LinkService.Void;
+import org.onosproject.grpc.net.link.models.LinkEnumsProto.LinkTypeProto;
+import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link.Type;
@@ -38,10 +36,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
-import io.grpc.Channel;
+import static org.onosproject.incubator.protobuf.models.ProtobufUtils.asMap;
/**
* Proxy object to handle LinkProviderService calls.
@@ -226,25 +225,25 @@
* Translates ONOS object to gRPC message.
*
* @param type {@link org.onosproject.net.Link.Type Link.Type}
- * @return gRPC LinkType
+ * @return gRPC LinkTypeProto
*/
- private LinkType translate(Type type) {
+ private LinkTypeProto translate(Type type) {
switch (type) {
case DIRECT:
- return LinkType.DIRECT;
+ return LinkTypeProto.DIRECT;
case EDGE:
- return LinkType.EDGE;
+ return LinkTypeProto.EDGE;
case INDIRECT:
- return LinkType.INDIRECT;
+ return LinkTypeProto.INDIRECT;
case OPTICAL:
- return LinkType.OPTICAL;
+ return LinkTypeProto.OPTICAL;
case TUNNEL:
- return LinkType.TUNNEL;
+ return LinkTypeProto.TUNNEL;
case VIRTUAL:
- return LinkType.VIRTUAL;
+ return LinkTypeProto.VIRTUAL;
default:
- return LinkType.DIRECT;
+ return LinkTypeProto.DIRECT;
}
}
@@ -253,10 +252,10 @@
* Translates ONOS object to gRPC message.
*
* @param cp {@link ConnectPoint}
- * @return gRPC ConnectPoint
+ * @return gRPC ConnectPointProto
*/
- private org.onosproject.grpc.net.Link.ConnectPoint translate(ConnectPoint cp) {
- return org.onosproject.grpc.net.Link.ConnectPoint.newBuilder()
+ private ConnectPointProto translate(ConnectPoint cp) {
+ return ConnectPointProto.newBuilder()
.setDeviceId(cp.deviceId().toString())
.setPortNumber(cp.port().toString())
.build();
diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java
index 69f9cfd..3ba56e4 100644
--- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java
+++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java
@@ -15,26 +15,24 @@
*/
package org.onosproject.incubator.rpc.grpc;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.cache.RemovalListeners.asynchronous;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.LinkKey.linkKey;
-
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
+import com.google.common.annotations.Beta;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalNotification;
+import io.grpc.stub.StreamObserver;
import org.apache.commons.lang3.tuple.Pair;
-import org.onosproject.grpc.net.Link.ConnectPoint.ElementIdCase;
-import org.onosproject.grpc.net.Link.LinkType;
import org.onosproject.grpc.net.link.LinkProviderServiceRpcGrpc.LinkProviderServiceRpcImplBase;
import org.onosproject.grpc.net.link.LinkService.LinkDetectedMsg;
import org.onosproject.grpc.net.link.LinkService.LinkVanishedMsg;
import org.onosproject.grpc.net.link.LinkService.Void;
+import org.onosproject.grpc.net.link.models.LinkDescriptionProtoOuterClass.LinkDescriptionProto;
+import org.onosproject.grpc.net.link.models.LinkEnumsProto.LinkTypeProto;
+import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto;
+import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto.ElementIdCase;
import org.onosproject.incubator.protobuf.models.ProtobufUtils;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
+import org.onosproject.net.Link.Type;
import org.onosproject.net.LinkKey;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
@@ -44,12 +42,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalNotification;
-import com.google.common.annotations.Beta;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
-import io.grpc.stub.StreamObserver;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.cache.RemovalListeners.asynchronous;
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.net.LinkKey.linkKey;
// Only single instance will be created and bound to gRPC LinkProviderService
/**
@@ -174,7 +174,7 @@
* @param connectPoint gRPC message.
* @return {@link ConnectPoint}
*/
- private ConnectPoint translate(org.onosproject.grpc.net.Link.ConnectPoint connectPoint) {
+ private ConnectPoint translate(ConnectPointProto connectPoint) {
checkArgument(connectPoint.getElementIdCase() == ElementIdCase.DEVICE_ID,
"Only DeviceId supported.");
return new ConnectPoint(deviceId(connectPoint.getDeviceId()),
@@ -187,10 +187,10 @@
* @param linkDescription gRPC message
* @return {@link LinkDescription}
*/
- private LinkDescription translate(org.onosproject.grpc.net.Link.LinkDescription linkDescription) {
+ private LinkDescription translate(LinkDescriptionProto linkDescription) {
ConnectPoint src = translate(linkDescription.getSrc());
ConnectPoint dst = translate(linkDescription.getDst());
- Link.Type type = translate(linkDescription.getType());
+ Type type = translate(linkDescription.getType());
SparseAnnotations annotations = ProtobufUtils.asAnnotations(linkDescription.getAnnotations());
return new DefaultLinkDescription(src, dst, type, annotations);
}
@@ -199,26 +199,26 @@
* Translates gRPC message to corresponding ONOS object.
*
* @param type gRPC message enum
- * @return {@link org.onosproject.net.Link.Type Link.Type}
+ * @return {@link Type Link.Type}
*/
- private Link.Type translate(LinkType type) {
+ private Type translate(LinkTypeProto type) {
switch (type) {
case DIRECT:
- return Link.Type.DIRECT;
+ return Type.DIRECT;
case EDGE:
- return Link.Type.EDGE;
+ return Type.EDGE;
case INDIRECT:
- return Link.Type.INDIRECT;
+ return Type.INDIRECT;
case OPTICAL:
- return Link.Type.INDIRECT;
+ return Type.INDIRECT;
case TUNNEL:
- return Link.Type.TUNNEL;
+ return Type.TUNNEL;
case VIRTUAL:
- return Link.Type.VIRTUAL;
+ return Type.VIRTUAL;
case UNRECOGNIZED:
default:
- return Link.Type.DIRECT;
+ return Type.DIRECT;
}
}
diff --git a/incubator/rpc-grpc/src/main/proto/DeviceService.proto b/incubator/rpc-grpc/src/main/proto/DeviceService.proto
index 5ae7cd6..9ff86c5 100644
--- a/incubator/rpc-grpc/src/main/proto/DeviceService.proto
+++ b/incubator/rpc-grpc/src/main/proto/DeviceService.proto
@@ -1,15 +1,17 @@
syntax = "proto3";
option java_package = "org.onosproject.grpc.net.device";
-import "models/Device.proto";
-import "models/Port.proto";
+import "net/device/DeviceDescriptionProto.proto";
+import "net/device/PortDescriptionProto.proto";
+import "net/device/PortStatisticsProto.proto";
+import "net/device/DeviceEnumsProto.proto";
package Device;
message DeviceConnected {
// DeviceID as String DeviceId#toString
string device_id = 1;
- DeviceDescription device_description = 2;
+ net.device.DeviceDescriptionProto device_description = 2;
}
message DeviceDisconnected {
@@ -20,26 +22,26 @@
message UpdatePorts {
// DeviceID as String DeviceId#toString
string device_id = 1;
- repeated Port.PortDescription port_descriptions= 2;
+ repeated net.device.PortDescriptionProto port_descriptions= 2;
}
message PortStatusChanged {
// DeviceID as String DeviceId#toString
string device_id = 1;
- Port.PortDescription port_description= 2;
+ net.device.PortDescriptionProto port_description= 2;
}
message ReceivedRoleReply {
// DeviceID as String DeviceId#toString
string device_id = 1;
- MastershipRole requested = 2;
- MastershipRole response = 3;
+ net.device.MastershipRoleProto requested = 2;
+ net.device.MastershipRoleProto response = 3;
}
message UpdatePortStatistics {
// DeviceID as String DeviceId#toString
string device_id = 1;
- repeated Port.PortStatistics port_statistics = 2;
+ repeated net.device.PortStatisticsProto port_statistics = 2;
}
message RegisterProvider {
@@ -72,7 +74,7 @@
message RoleChanged {
// DeviceID as String DeviceId#toString
string device_id = 1;
- MastershipRole new_role = 2;
+ net.device.MastershipRoleProto new_role = 2;
}
message IsReachableRequest {
diff --git a/incubator/rpc-grpc/src/main/proto/LinkService.proto b/incubator/rpc-grpc/src/main/proto/LinkService.proto
index ee32453..e211e11 100644
--- a/incubator/rpc-grpc/src/main/proto/LinkService.proto
+++ b/incubator/rpc-grpc/src/main/proto/LinkService.proto
@@ -1,7 +1,8 @@
syntax = "proto3";
option java_package = "org.onosproject.grpc.net.link";
-import "models/Link.proto";
+import "net/link/LinkDescriptionProto.proto";
+import "net/ConnectPointProto.proto";
package Link;
@@ -11,15 +12,15 @@
message LinkDetectedMsg {
// ProviderId scheme only
string provider_id = 1;
- LinkDescription link_description = 2;
+ net.link.LinkDescriptionProto link_description = 2;
}
message LinkVanishedMsg {
// ProviderId scheme only
string provider_id = 1;
oneof subject {
- LinkDescription link_description = 2;
- ConnectPoint connect_point = 3;
+ net.link.LinkDescriptionProto link_description = 2;
+ net.ConnectPointProto connect_point = 3;
string device_id = 4;
}
}