From 0221d913e9c2f350ec5e015fcf10caa65eb62239 Mon Sep 17 00:00:00 2001 From: Aaron Kruglikov Date: Fri, 25 Aug 2017 16:18:29 +0000 Subject: [PATCH] Revert "Creating a registry for gRPC services, early version restarts on each modification of the set of services." This reverts commit 2d69ca1c88b3b86800aac0a453be33838ff39c1c. Change-Id: I6236393929ba43eb98e139766f0c2377f47ff3a5 --- incubator/api/BUCK | 1 - incubator/api/pom.xml | 5 - .../incubator/grpc/GrpcServiceRegistry.java | 50 ----- .../incubator/grpc/package-info.java | 20 -- incubator/protobuf/pom.xml | 23 -- .../protobuf/net/GrpcServiceRegistryImpl.java | 207 ------------------ lib/BUCK | 38 +--- lib/deps.json | 4 - 8 files changed, 1 insertion(+), 347 deletions(-) delete mode 100644 incubator/api/src/main/java/org/onosproject/incubator/grpc/GrpcServiceRegistry.java delete mode 100644 incubator/api/src/main/java/org/onosproject/incubator/grpc/package-info.java delete mode 100644 incubator/protobuf/src/main/java/org/onosproject/incubator/protobuf/net/GrpcServiceRegistryImpl.java diff --git a/incubator/api/BUCK b/incubator/api/BUCK index c606814fb4..eb7b03679a 100644 --- a/incubator/api/BUCK +++ b/incubator/api/BUCK @@ -1,7 +1,6 @@ COMPILE_DEPS = [ '//lib:CORE_DEPS', '//lib:JACKSON', - '//lib:grpc-core' ] TEST_DEPS = [ diff --git a/incubator/api/pom.xml b/incubator/api/pom.xml index 391ad3a47f..fe86161763 100644 --- a/incubator/api/pom.xml +++ b/incubator/api/pom.xml @@ -43,11 +43,6 @@ easymock test - - io.grpc - grpc-core - 1.2.0 - diff --git a/incubator/api/src/main/java/org/onosproject/incubator/grpc/GrpcServiceRegistry.java b/incubator/api/src/main/java/org/onosproject/incubator/grpc/GrpcServiceRegistry.java deleted file mode 100644 index 0e33f2f0fe..0000000000 --- a/incubator/api/src/main/java/org/onosproject/incubator/grpc/GrpcServiceRegistry.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2017-present Open Networking Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.incubator.grpc; - -import io.grpc.BindableService; - -/** - * A service that allows for de/registration of gRPC services, and determining - * whether a service is present. - */ -public interface GrpcServiceRegistry { - /** - * Register a gRPC service with this registry. - * @param service the service to be registered - * @return true if the service was added and server successfully started, - * false otherwise - */ - boolean register(BindableService service); - - /** - * Unregister a gRPC service with this registry. - * @param service the service to be unregistered - * @return true if the service was removed and the server successfully - * started, false otherwise - */ - boolean unregister(BindableService service); - - /** - * Checks if an instance of the provided serviceClass is currently - * registered with this registry. - * @param serviceClass the class being queries - * @return true if an instance of this specified class has been registered, - * false otherwise - */ - boolean containsService(Class serviceClass); -} diff --git a/incubator/api/src/main/java/org/onosproject/incubator/grpc/package-info.java b/incubator/api/src/main/java/org/onosproject/incubator/grpc/package-info.java deleted file mode 100644 index eac386df67..0000000000 --- a/incubator/api/src/main/java/org/onosproject/incubator/grpc/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2017-present Open Networking Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Abstractions for interacting with the gRPC subsystem. - */ -package org.onosproject.incubator.grpc; diff --git a/incubator/protobuf/pom.xml b/incubator/protobuf/pom.xml index 5d2c5305e7..303c1ee3f8 100644 --- a/incubator/protobuf/pom.xml +++ b/incubator/protobuf/pom.xml @@ -16,18 +16,6 @@ --> 4.0.0 - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - onos-incubator-grpc-dependencies org.onosproject @@ -66,17 +54,6 @@ provided - - org.onosproject - onos-incubator-api - ${project.version} - - - org.osgi - org.osgi.compendium - compile - - diff --git a/incubator/protobuf/src/main/java/org/onosproject/incubator/protobuf/net/GrpcServiceRegistryImpl.java b/incubator/protobuf/src/main/java/org/onosproject/incubator/protobuf/net/GrpcServiceRegistryImpl.java deleted file mode 100644 index 57169265fa..0000000000 --- a/incubator/protobuf/src/main/java/org/onosproject/incubator/protobuf/net/GrpcServiceRegistryImpl.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2017-present Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.incubator.protobuf.net; - -import com.google.common.collect.Maps; -import io.grpc.BindableService; -import io.grpc.Server; -import io.grpc.ServerBuilder; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Modified; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.onosproject.incubator.grpc.GrpcServiceRegistry; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Dictionary; -import java.util.Map; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.BiFunction; -import java.util.function.Function; - -import static org.onlab.util.Tools.get; - -/** - * A basic implementation of {@link GrpcServiceRegistry} designed for use with - * built in gRPC services. - * - * NOTE: this is an early implementation in which the addition of any new - * service forces a restart of the server, this is sufficient for testing but - * inappropriate for deployment. - */ -@Service -@Component(immediate = false) -public class GrpcServiceRegistryImpl implements GrpcServiceRegistry { - - private static final int DEFAULT_SERVER_PORT = 64000; - private static final int DEFAULT_SHUTDOWN_TIME = 1; - private static final AtomicBoolean servicesModifiedSinceStart = new AtomicBoolean(false); - - private static final String PORT_PROPERTY_NAME = "listeningPort"; - - private final Map, BindableService> registeredServices = - Maps.newHashMap(); - private final Logger log = LoggerFactory.getLogger(getClass()); - - private Server server; - - /* It is currently the responsibility of the administrator to notify - clients of nonstandard port usage as there is no mechanism available to - discover the port hosting gRPC services. - */ - @Property(name = PORT_PROPERTY_NAME, intValue = DEFAULT_SERVER_PORT, - label = "The port number which ONOS will use to host gRPC services.") - private int listeningPort = DEFAULT_SERVER_PORT; - - @Activate - public void activate() { - log.info("Started"); - } - - @Deactivate - public void deactivate() { - attemptGracefulShutdownThenForce(DEFAULT_SHUTDOWN_TIME); - log.info("Stopped"); - } - - @Modified - public void modified(ComponentContext context) { - if (context != null) { - setProperties(context); - } - log.info("Connection was restarted to allow service to be added, " + - "this is a temporary workaround"); - restartServer(listeningPort); - } - - @Override - public boolean register(BindableService service) { - synchronized (registeredServices) { - if (!registeredServices.containsKey(service.getClass())) { - registeredServices.put(service.getClass(), service); - } else { - log.warn("The specified class \"{}\" was not added because an " + - "instance of the class is already registered.", - service.getClass().toString()); - return false; - } - } - return restartServer(listeningPort); - } - - @Override - public boolean unregister(BindableService service) { - synchronized (registeredServices) { - if (registeredServices.containsKey(service.getClass())) { - registeredServices.remove(service.getClass()); - } else { - log.warn("The specified class \"{}\" was not removed because it " + - "was not present.", service.getClass().toString()); - return false; - } - } - return restartServer(listeningPort); - } - - @Override - public boolean containsService(Class serviceClass) { - return registeredServices.containsKey(serviceClass); - } - - private void setProperties(ComponentContext context) { - Dictionary properties = context.getProperties(); - String listeningPort = get(properties, PORT_PROPERTY_NAME); - this.listeningPort = listeningPort == null ? DEFAULT_SERVER_PORT : - Integer.parseInt(listeningPort.trim()); - } - - /** - * Attempts a graceful shutdown allowing {@code timeLimitSeconds} to elapse - * before forcing a shutdown. - * - * @param timeLimitSeconds time before a shutdown is forced in seconds - * @return true if the server is terminated, false otherwise - */ - private boolean attemptGracefulShutdownThenForce(int timeLimitSeconds) { - if (!server.isShutdown()) { - server.shutdown(); - } - try { - /*This is not conditional in case the server is shutdown but - handling requests submitted before shutdown was called.*/ - server.awaitTermination(timeLimitSeconds, TimeUnit.SECONDS); - } catch (InterruptedException e) { - log.error("Awaiting server termination failed with error {}", - e.getMessage()); - } - if (!server.isTerminated()) { - server.shutdownNow(); - try { - server.awaitTermination(10, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - log.error("Server failed to terminate as expected with error" + - " {}", e.getMessage()); - } - } - return server.isTerminated(); - } - - private boolean restartServer(int port) { - if (!attemptGracefulShutdownThenForce(DEFAULT_SHUTDOWN_TIME)) { - log.error("Shutdown failed, the previous server may still be" + - " active."); - } - return createServerAndStart(port); - } - - /** - * Creates a server with the set of registered services on the specified - * port. - * - * @param port the port on which this server will listen - * @return true if the server was started successfully, false otherwise - */ - private boolean createServerAndStart(int port) { - - ServerBuilder serverBuilder = - ServerBuilder.forPort(port); - synchronized (registeredServices) { - registeredServices.values().forEach( - service -> serverBuilder.addService(service)); - } - server = serverBuilder.build(); - try { - server.start(); - } catch (IllegalStateException e) { - log.error("The server could not be started because an existing " + - "server is already running: {}", e.getMessage()); - return false; - } catch (IOException e) { - log.error("The server could not be started due to a failure to " + - "bind: {} ", e.getMessage()); - return false; - } - return true; - } -} diff --git a/lib/BUCK b/lib/BUCK index 77dc5bf942..ce7e0a61dd 100644 --- a/lib/BUCK +++ b/lib/BUCK @@ -1,4 +1,4 @@ -# ***** This file was auto-generated at Fri, 25 Aug 2017 00:23:12 GMT. Do not edit this file manually. ***** +# ***** This file was auto-generated at Thu, 24 Aug 2017 21:35:03 GMT. Do not edit this file manually. ***** # ***** Use onos-lib-gen ***** pass_thru_pom( @@ -909,42 +909,6 @@ remote_jar ( visibility = [ 'PUBLIC' ], ) -remote_jar ( - name = 'catalyst-concurrent', - out = 'catalyst-concurrent-1.2.0.jar', - url = 'mvn:io.atomix.catalyst:catalyst-concurrent:jar:1.2.0', - sha1 = 'ba91527a1c0a68c8f46cc591ef0dded3d2d0c298', - maven_coords = 'io.atomix.catalyst:catalyst-concurrent:1.2.0', - visibility = [ 'PUBLIC' ], -) - -remote_jar ( - name = 'catalyst-netty', - out = 'catalyst-netty-1.2.0.jar', - url = 'mvn:io.atomix.catalyst:catalyst-netty:jar:1.2.0', - sha1 = 'abb694b6fe835eb66d30ae6979ec0f7e4ac2e738', - maven_coords = 'io.atomix.catalyst:catalyst-netty:1.2.0', - visibility = [ 'PUBLIC' ], -) - -remote_jar ( - name = 'catalyst-transport', - out = 'catalyst-transport-1.2.0.jar', - url = 'mvn:io.atomix.catalyst:catalyst-transport:jar:1.2.0', - sha1 = '1469017e168a5e611fa4c251273184a763e0cd7f', - maven_coords = 'io.atomix.catalyst:catalyst-transport:1.2.0', - visibility = [ 'PUBLIC' ], -) - -remote_jar ( - name = 'grpc-core', - out = 'grpc-core-1.2.0.jar', - url = 'mvn:io.grpc:grpc-core:jar:1.2.0', - sha1 = 'f12a213e2b59a0615df2cc9bed35dc15fd2fee37', - maven_coords = 'io.grpc:grpc-core:jar:NON-OSGI:1.2.0', - visibility = [ 'PUBLIC' ], -) - remote_jar ( name = 'objenesis', out = 'objenesis-2.2.jar', diff --git a/lib/deps.json b/lib/deps.json index 74e4b1ea0d..640f630d90 100644 --- a/lib/deps.json +++ b/lib/deps.json @@ -196,10 +196,6 @@ "netty-resolver": "mvn:io.netty:netty-resolver:4.1.8.Final", "netty-codec-http2": "mvn:io.netty:netty-codec-http2:4.1.8.Final", "netty-codec-http": "mvn:io.netty:netty-codec-http:4.1.8.Final", - "catalyst-concurrent": "mvn:io.atomix.catalyst:catalyst-concurrent:1.2.0", - "catalyst-netty": "mvn:io.atomix.catalyst:catalyst-netty:1.2.0", - "catalyst-transport": "mvn:io.atomix.catalyst:catalyst-transport:1.2.0", - "grpc-core": "mvn:io.grpc:grpc-core:1.2.0", "objenesis": "mvn:org.objenesis:objenesis:2.2", "openflowj": "mvn:org.onosproject:openflowj:3.2.0.onos", "org.apache.felix.scr": "mvn:org.apache.felix:org.apache.felix.scr:1.8.2",