Declaring P4Runtime and gRPC protocol subsystems as apps

The advantage is that we don't have to carry over the driver all
required gRPC and P4Runtime bundles. Each module is now responsible for
bringing in its own runtime dependencies.

Change-Id: Icb1365e68d486f12fb1e25dc5d3937f42e3e1c62
diff --git a/drivers/bmv2/BUCK b/drivers/bmv2/BUCK
index 3726829..b7de8b4 100644
--- a/drivers/bmv2/BUCK
+++ b/drivers/bmv2/BUCK
@@ -1,57 +1,22 @@
-GRPC_DEPS = [
-    '//incubator/grpc-dependencies:grpc-core-repkg-1.3.0',
-    '//lib:grpc-protobuf-1.3.0',
-    '//lib:grpc-protobuf-lite-1.3.0',
-    '//lib:grpc-stub-1.3.0',
-    '//lib:grpc-netty-1.3.0',
-    '//lib:grpc-auth-1.3.0',
-    '//lib:google-instrumentation-0.3.0',
-    '//lib:protobuf-java-3.0.2',
-    # Lazily adding all netty-related packages.
-    # Some of them might not be necessary.
-    '//lib:netty',
-    '//lib:netty-buffer',
-    '//lib:netty-codec',
-    '//lib:netty-codec-http',
-    '//lib:netty-codec-http2',
-    '//lib:netty-common',
-    '//lib:netty-handler',
-    '//lib:netty-transport',
-    '//lib:netty-transport-native-epoll',
-    '//lib:netty-resolver',
-]
+GRPC_VER = '1.3.0'
 
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//protocols/p4runtime/api:onos-protocols-p4runtime-api',
     '//incubator/bmv2/model:onos-incubator-bmv2-model',
-    '//incubator/grpc-dependencies:grpc-core-repkg-1.3.0',
-    '//lib:grpc-netty-1.3.0',
     '//drivers/default:onos-drivers-default',
-]
-
-TEST_DEPS = [
-    '//lib:TEST_ADAPTERS',
-    '//core/api:onos-api-tests',
+    '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
+    '//lib:grpc-netty-' + GRPC_VER,
 ]
 
 BUNDLES = [
     ':onos-drivers-bmv2',
-    '//protocols/p4runtime/proto:onos-protocols-p4runtime-proto',
-    '//protocols/p4runtime/api:onos-protocols-p4runtime-api',
-    '//protocols/p4runtime/ctl:onos-protocols-p4runtime-ctl',
-    '//protocols/grpc/api:onos-protocols-grpc-api',
-    '//protocols/grpc/ctl:onos-protocols-grpc-ctl',
-    '//protocols/grpc/proto:onos-protocols-grpc-proto',
     '//incubator/bmv2/model:onos-incubator-bmv2-model',
     '//drivers/default:onos-drivers-default',
-] + GRPC_DEPS
+]
 
-osgi_jar_with_tests(
+osgi_jar(
     deps = COMPILE_DEPS,
-    test_deps = TEST_DEPS,
-    resources_root = 'src/main/resources',
-    resources = glob(['src/main/resources/**']),
 )
 
 onos_app (
@@ -59,9 +24,10 @@
     title = 'BMv2 Device Drivers',
     category = 'Drivers',
     url = 'http://onosproject.org',
-    description = 'ONOS BMv2 Device Drivers application.',
+    description = 'ONOS BMv2 device drivers application.',
     included_bundles = BUNDLES,
     required_apps = [
-        'org.onosproject.generaldeviceprovider'
+        'org.onosproject.generaldeviceprovider',
+        'org.onosproject.protocols.p4runtime'
     ],
 )
diff --git a/modules.defs b/modules.defs
index 0ad980c..ba172d6 100644
--- a/modules.defs
+++ b/modules.defs
@@ -42,9 +42,6 @@
     '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc',
     '//protocols/ovsdb/api:onos-protocols-ovsdb-api',
     '//protocols/ovsdb/ctl:onos-protocols-ovsdb-ctl',
-    '//protocols/p4runtime/api:onos-protocols-p4runtime-api',
-    '//protocols/p4runtime/ctl:onos-protocols-p4runtime-ctl',
-    '//protocols/p4runtime/proto:onos-protocols-p4runtime-proto',
     '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
     '//protocols/pcep/api:onos-protocols-pcep-api',
     '//protocols/pcep/ctl:onos-protocols-pcep-ctl',
@@ -60,8 +57,6 @@
     '//protocols/tl1/ctl:onos-protocols-tl1-ctl',
     '//protocols/restconf/client/api:onos-protocols-restconf-client-api',
     '//protocols/restconf/client/ctl:onos-protocols-restconf-client-ctl',
-    '//protocols/grpc/api:onos-protocols-grpc-api',
-    '//protocols/grpc/ctl:onos-protocols-grpc-ctl',
 
     '//drivers/utilities:onos-drivers-utilities',
 
@@ -213,6 +208,11 @@
     '//apps/artemis:onos-apps-artemis-oar',
 ]
 
+PROTOCOL_APPS = [
+    '//protocols/grpc:onos-protocols-grpc-oar',
+    '//protocols/p4runtime:onos-protocols-p4runtime-oar',
+]
+
 MODELS = [
     '//models/huawei:onos-models-huawei-oar',
     '//models/openroadm:onos-models-openroadm-oar',
@@ -236,5 +236,5 @@
     '//apps/vtn/vtnweb:onos-apps-vtn-vtnweb',
 ]
 
-APPS = ONOS_DRIVERS + ONOS_PROVIDERS + ONOS_APPS + MODELS
+APPS = ONOS_DRIVERS + ONOS_PROVIDERS + ONOS_APPS + MODELS + PROTOCOL_APPS
 
diff --git a/protocols/grpc/BUCK b/protocols/grpc/BUCK
new file mode 100644
index 0000000..57ab1a0
--- /dev/null
+++ b/protocols/grpc/BUCK
@@ -0,0 +1,38 @@
+PROTOBUF_VER = '3.0.2'
+GRPC_VER = '1.3.0'
+
+BUNDLES = [
+    '//protocols/grpc/proto:onos-protocols-grpc-proto',
+    '//protocols/grpc/api:onos-protocols-grpc-api',
+    '//protocols/grpc/ctl:onos-protocols-grpc-ctl',
+    # gRPC dependencies
+    '//incubator/grpc-dependencies:grpc-core-repkg-1.3.0',
+    '//lib:grpc-protobuf-1.3.0',
+    '//lib:grpc-protobuf-lite-1.3.0',
+    '//lib:grpc-stub-1.3.0',
+    '//lib:grpc-netty-1.3.0',
+    '//lib:grpc-auth-1.3.0',
+    '//lib:google-instrumentation-0.3.0',
+    '//lib:protobuf-java-3.0.2',
+    # Lazily adding all netty-related packages.
+    # Some of them might not be necessary.
+    '//lib:netty',
+    '//lib:netty-buffer',
+    '//lib:netty-codec',
+    '//lib:netty-codec-http',
+    '//lib:netty-codec-http2',
+    '//lib:netty-common',
+    '//lib:netty-handler',
+    '//lib:netty-transport',
+    '//lib:netty-transport-native-epoll',
+    '//lib:netty-resolver',
+]
+
+onos_app (
+    app_name = 'org.onosproject.protocols.grpc',
+    title = 'gRPC Protocol Subsystem',
+    category = 'Protocols',
+    url = 'http://onosproject.org',
+    description = 'ONOS gRPC protocol subsystem',
+    included_bundles = BUNDLES,
+)
\ No newline at end of file
diff --git a/protocols/grpc/ctl/BUCK b/protocols/grpc/ctl/BUCK
index d6cab68..ad855fd 100644
--- a/protocols/grpc/ctl/BUCK
+++ b/protocols/grpc/ctl/BUCK
@@ -1,4 +1,4 @@
-PROTOC_VER = '3.0.2'
+PROTOBUF_VER = '3.0.2'
 GRPC_VER = '1.3.0'
 
 COMPILE_DEPS = [
@@ -7,7 +7,7 @@
     '//protocols/grpc/proto:onos-protocols-grpc-proto',
     '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
     '//lib:grpc-stub-' + GRPC_VER,
-    '//lib:protobuf-java-' + PROTOC_VER,
+    '//lib:protobuf-java-' + PROTOBUF_VER,
 ]
 
 osgi_jar (
diff --git a/protocols/grpc/proto/BUCK b/protocols/grpc/proto/BUCK
index f4a4033..f0df65d 100644
--- a/protocols/grpc/proto/BUCK
+++ b/protocols/grpc/proto/BUCK
@@ -2,7 +2,7 @@
     '//bucklets/grpc.bucklet'
 )
 
-PROTOC_VER = '3.0.2'
+PROTOBUF_VER = '3.0.2'
 GRPC_VER = '1.3.0'
 
 COMPILE_DEPS = [
@@ -10,13 +10,13 @@
     '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
     '//lib:grpc-stub-' + GRPC_VER,
     '//lib:grpc-protobuf-' + GRPC_VER,
-    '//lib:protobuf-java-' + PROTOC_VER,
+    '//lib:protobuf-java-' + PROTOBUF_VER,
 ]
 
 grpc_jar(
     proto_match_patterns = ["*.proto"],
     proto_paths = ["$ONOS_ROOT/protocols/grpc/proto/", "$ONOS_ROOT"], #FIXME should not have to include ONOS_ROOT top level here
-    protoc_version = PROTOC_VER,
+    protoc_version = PROTOBUF_VER,
     plugin_version = GRPC_VER,
     deps = COMPILE_DEPS,
 )
diff --git a/protocols/p4runtime/BUCK b/protocols/p4runtime/BUCK
new file mode 100644
index 0000000..e677f9f
--- /dev/null
+++ b/protocols/p4runtime/BUCK
@@ -0,0 +1,17 @@
+BUNDLES = [
+    '//protocols/p4runtime/proto:onos-protocols-p4runtime-proto',
+    '//protocols/p4runtime/api:onos-protocols-p4runtime-api',
+    '//protocols/p4runtime/ctl:onos-protocols-p4runtime-ctl',
+]
+
+onos_app(
+    app_name = 'org.onosproject.protocols.p4runtime',
+    title = 'P4Runtime Protocol Subsystem',
+    category = 'Protocols',
+    url = 'http://onosproject.org',
+    description = 'ONOS P4Runtime protocol subsystem',
+    included_bundles = BUNDLES,
+    required_apps = [
+        'org.onosproject.protocols.grpc'
+    ],
+)
\ No newline at end of file
diff --git a/protocols/p4runtime/api/BUCK b/protocols/p4runtime/api/BUCK
index b7d1869..cefdf3a 100644
--- a/protocols/p4runtime/api/BUCK
+++ b/protocols/p4runtime/api/BUCK
@@ -5,13 +5,6 @@
     '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
 ]
 
-TEST_DEPS = [
-    '//lib:TEST_ADAPTERS',
-    '//core/api:onos-api-tests',
-]
-
-
-osgi_jar_with_tests(
+osgi_jar(
     deps = COMPILE_DEPS,
-    test_deps = TEST_DEPS,
 )
\ No newline at end of file
diff --git a/protocols/p4runtime/ctl/BUCK b/protocols/p4runtime/ctl/BUCK
index 27e102a..e4a90e7 100644
--- a/protocols/p4runtime/ctl/BUCK
+++ b/protocols/p4runtime/ctl/BUCK
@@ -1,39 +1,18 @@
 GRPC_VER = '1.3.0'
 PROTOBUF_VER = '3.0.2'
 
-GRPC_DEPS = [
-    '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
-    '//lib:grpc-protobuf-' + GRPC_VER,
-    '//lib:grpc-protobuf-lite-' + GRPC_VER,
-    '//lib:grpc-stub-' + GRPC_VER,
-    '//lib:grpc-netty-' + GRPC_VER,
-    '//lib:grpc-auth-' + GRPC_VER,
-    '//lib:google-instrumentation-0.3.0',
-    '//lib:protobuf-java-' + PROTOBUF_VER,
-    # Lazily adding all netty-related packages.
-    # Some of them might not be necessary.
-    '//lib:netty',
-    '//lib:netty-buffer',
-    '//lib:netty-codec',
-    '//lib:netty-codec-http',
-    '//lib:netty-codec-http2',
-    '//lib:netty-common',
-    '//lib:netty-handler',
-    '//lib:netty-transport',
-    '//lib:netty-transport-native-epoll',
-    '//lib:netty-resolver',
-]
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//protocols/grpc/api:onos-protocols-grpc-api',
     '//protocols/p4runtime/api:onos-protocols-p4runtime-api',
-    '//protocols/p4runtime/proto:onos-protocols-p4runtime-proto'
-] + GRPC_DEPS
+    '//protocols/p4runtime/proto:onos-protocols-p4runtime-proto',
+    '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
+    '//lib:grpc-stub-' + GRPC_VER,
+    '//lib:protobuf-java-' + PROTOBUF_VER,
+]
 
 TEST_DEPS = [
     '//lib:TEST',
-    '//core/api:onos-api-tests',
     '//incubator/bmv2/model:onos-incubator-bmv2-model',
 ]
 
diff --git a/protocols/p4runtime/proto/BUCK b/protocols/p4runtime/proto/BUCK
index ee185d4..6216be6 100644
--- a/protocols/p4runtime/proto/BUCK
+++ b/protocols/p4runtime/proto/BUCK
@@ -2,8 +2,8 @@
     '//bucklets/grpc.bucklet'
 )
 
-P4RT_PROTOC_VER = '3.0.2'
-P4RT_GRPC_VER = '1.3.0'
+PROTOBUF_VER = '3.0.2'
+GRPC_VER = '1.3.0'
 
 PI_COMMIT = '8051d54c9c3415ca800db232a226189fd17ad60a'
 PI_BASEURL = 'https://github.com/p4lang/PI.git'
@@ -20,10 +20,10 @@
 
 COMPILE_DEPS =[
     '//lib:CORE_DEPS',
-    '//incubator/grpc-dependencies:grpc-core-repkg-' + P4RT_GRPC_VER,
-    '//lib:grpc-stub-' + P4RT_GRPC_VER,
-    '//lib:grpc-protobuf-' + P4RT_GRPC_VER,
-    '//lib:protobuf-java-' + P4RT_PROTOC_VER,
+    '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
+    '//lib:grpc-stub-' + GRPC_VER,
+    '//lib:grpc-protobuf-' + GRPC_VER,
+    '//lib:protobuf-java-' + PROTOBUF_VER,
 ]
 
 genrule(
@@ -44,8 +44,8 @@
     proto_paths = [
         '$(location :p4lang-pi-repo-' + PI_COMMIT + ')/proto',
     ],
-    protoc_version = P4RT_PROTOC_VER,
-    plugin_version = P4RT_GRPC_VER,
+    protoc_version = PROTOBUF_VER,
+    plugin_version = GRPC_VER,
     deps = COMPILE_DEPS,
     include_std_lib = True,
 )