From 1a4a451d17d39b0dac45a70de9016bd4b0e6b249 Mon Sep 17 00:00:00 2001 From: Moiz Raja Date: Mon, 28 Sep 2015 20:26:38 -0700 Subject: [PATCH] BUG 4151 : Create a shared actor system This patch adds an ActorSystemProvider interface in clustering commons with a method to get a shard ActorSystem instance which uses the clustered data store configuration as it contains more configuration options than the rpc connector which pretty much uses stock configuration. I added a config yang to define an actor-system-provider-service. I added the ActorSystemProvider implementation and actor-system-provider-impl config yang in the distributed datastore bundle. I tried it in sal-clustering-commmons originally but ran into akka errors re: missing config properties and it also couldn't find the ReadyLocalTransactionSerializer class. So to avoid chasing down those errors I put the implementation in sal-distributed-datastore. I think this makes sense as it is the prime user of the actor system. I added a dependency for the ActorSystemProvider service in both datastores modules so the ActorSystem is now injected in and passed to the DistributedDataStoreFactory. The dependency was also added to the RPC mpdule. Elements for the new actor system provider service and impl were added to the 05-clustering.xml file along with the wiring changes for the data stores and RPC modules. Change-Id: I79c14f84c992a2d5ac9c1f1856efbaeba3cc2b77 Signed-off-by: Moiz Raja --- .../md-sal/sal-clustering-commons/pom.xml | 38 +++++++++- .../cluster/ActorSystemProvider.java | 34 +++++++++ .../cluster/ActorSystemProviderListener.java | 31 ++++++++ .../cluster/common/actor/AbstractConfig.java | 13 ++-- .../yang/actor-system-provider-service.yang | 18 +++++ .../actor/MeteredBoundedMailboxTest.java | 22 ++++-- .../resources/initial/05-clustering.xml.conf | 27 ++++++- .../src/main/resources/initial/akka.conf | 37 ---------- .../datastore/DistributedDataStore.java | 1 - .../DistributedDataStoreFactory.java | 55 +------------- .../impl/ActorSystemProviderImpl.java | 71 ++++++++++++++++++ .../impl/ActorSystemProviderModule.java | 29 ++++++++ .../ActorSystemProviderModuleFactory.java | 33 +++++++++ ...tributedConfigDataStoreProviderModule.java | 2 +- ...tedOperationalDataStoreProviderModule.java | 2 +- .../main/yang/actor-system-provider-impl.yang | 26 +++++++ .../yang/distributed-datastore-provider.yang | 23 +++++- .../RemoteRPCBrokerModule.java | 72 +++++++++---------- .../remote/rpc/RemoteRpcProvider.java | 9 ++- .../remote/rpc/RemoteRpcProviderConfig.java | 3 +- .../remote/rpc/RemoteRpcProviderFactory.java | 36 ++-------- .../controller/remote/rpc/RpcManager.java | 12 ++-- .../remote/rpc/registry/RpcRegistry.java | 15 ++-- .../rpc/registry/gossip/BucketStore.java | 7 +- .../remote/rpc/registry/gossip/Gossiper.java | 10 +-- .../src/main/yang/remote-rpc-connector.yang | 16 +++-- .../remote/rpc/RemoteRpcProviderTest.java | 3 +- .../remote/rpc/registry/RpcRegistryTest.java | 38 ++++++---- .../rpc/registry/gossip/BucketStoreTest.java | 3 +- .../rpc/registry/gossip/GossiperTest.java | 33 +++++---- 30 files changed, 483 insertions(+), 236 deletions(-) create mode 100644 opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProvider.java create mode 100644 opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProviderListener.java create mode 100644 opendaylight/md-sal/sal-clustering-commons/src/main/yang/actor-system-provider-service.yang create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModule.java create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModuleFactory.java create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/yang/actor-system-provider-impl.yang diff --git a/opendaylight/md-sal/sal-clustering-commons/pom.xml b/opendaylight/md-sal/sal-clustering-commons/pom.xml index 8a32507ada..a764f2c499 100644 --- a/opendaylight/md-sal/sal-clustering-commons/pom.xml +++ b/opendaylight/md-sal/sal-clustering-commons/pom.xml @@ -130,10 +130,46 @@ org.opendaylight.yangtools yang-parser-impl + + org.opendaylight.controller + config-api + + + + org.opendaylight.yangtools + yang-maven-plugin + + + + generate-sources + + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + ${salGeneratorPath} + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + ${jmxGeneratorPath} + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl + target/site/models + + + true + + + + org.jacoco jacoco-maven-plugin @@ -169,8 +205,6 @@ ${project.groupId}.${project.artifactId} - org.opendaylight.controller.cluster.*,org.opendaylight.common.actor,org.opendaylight.common.reporting,org.opendaylight.controller.protobuff.*,org.opendaylight.controller.xml.* - * diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProvider.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProvider.java new file mode 100644 index 0000000000..31ce16a1c0 --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster; + +import akka.actor.ActorSystem; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.concepts.ListenerRegistration; + +/** + * Interface that provides an akka ActorSystem instance. + * + * @author Thomas Pantelis + */ +public interface ActorSystemProvider { + /** + * @return the current ActorSystem. + */ + @Nonnull + ActorSystem getActorSystem(); + + /** + * Register a listener for ActorSystem lifecycle events. + * + * @param listener the ActorSystemProviderListener to register + * @return a ListenerRegistration instance to be used to unregister + */ + ListenerRegistration registerActorSystemProviderListener( + @Nonnull ActorSystemProviderListener listener); +} diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProviderListener.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProviderListener.java new file mode 100644 index 0000000000..ebb66f4257 --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/ActorSystemProviderListener.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster; + +import akka.actor.ActorSystem; +import java.util.EventListener; + +/** + * Listener interface for notification of ActorSystem changes from an ActorSystemProvider. + * + * @author Thomas Pantelis + */ +public interface ActorSystemProviderListener extends EventListener { + /** + * Method called when the current actor system is about to be shutdown. + */ + void onPreShutdownActorSystem(); + + /** + * Method called when the current actor system is shutdown and a new actor system is created. This method + * is always preceded by a call to {@link #onPreShutdownActorSystem}. + * + * @param actorSytem the new ActorSystem + */ + void onNewActorSystem(ActorSystem actorSytem); +} diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractConfig.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractConfig.java index 0f2ac854ce..1a331b7e99 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractConfig.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractConfig.java @@ -11,13 +11,12 @@ package org.opendaylight.controller.cluster.common.actor; import com.google.common.base.Preconditions; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; - import java.util.HashMap; import java.util.Map; public abstract class AbstractConfig implements UnifiedConfig { - private Config config; + private final Config config; public AbstractConfig(Config config){ this.config = config; @@ -45,11 +44,13 @@ public abstract class AbstractConfig implements UnifiedConfig { return (T)this; } - protected Config merge(){ - if (fallback == null) - fallback = ConfigFactory.load().getConfig(actorSystemName); + protected Config merge() { + Config config = ConfigFactory.parseMap(configHolder); + if (fallback != null) { + config = config.withFallback(fallback); + } - return ConfigFactory.parseMap(configHolder).withFallback(fallback); + return config; } } } diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/yang/actor-system-provider-service.yang b/opendaylight/md-sal/sal-clustering-commons/src/main/yang/actor-system-provider-service.yang new file mode 100644 index 0000000000..f284851cd9 --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/yang/actor-system-provider-service.yang @@ -0,0 +1,18 @@ +module actor-system-provider-service { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:config:actor-system-provider:service"; + prefix "actor-system"; + + import config { prefix config; revision-date 2013-04-05; } + + description "Akka actor system provider service definition"; + + revision "2015-10-05" { + description "Initial revision"; + } + + identity actor-system-provider-service { + base "config:service-type"; + config:java-class "org.opendaylight.controller.cluster.ActorSystemProvider"; + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java index b706d20d1a..c027de0acf 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java @@ -13,14 +13,15 @@ import akka.actor.DeadLetter; import akka.actor.Props; import akka.actor.UntypedActor; import akka.testkit.JavaTestKit; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; import org.junit.After; import org.junit.Before; import org.junit.Test; import scala.concurrent.duration.FiniteDuration; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReentrantLock; - public class MeteredBoundedMailboxTest { private static ActorSystem actorSystem; @@ -29,14 +30,20 @@ public class MeteredBoundedMailboxTest { @Before public void setUp() throws Exception { - config = new CommonConfig.Builder<>("testsystem").build(); + config = new CommonConfig.Builder<>("testsystem").withConfigReader(new AkkaConfigurationReader() { + @Override + public Config read() { + return ConfigFactory.load(); + } + }).build(); actorSystem = ActorSystem.create("testsystem", config.get()); } @After public void tearDown() throws Exception { - if (actorSystem != null) - actorSystem.shutdown(); + if (actorSystem != null) { + actorSystem.shutdown(); + } } @Test @@ -86,8 +93,9 @@ public class MeteredBoundedMailboxTest { public void onReceive(Object message) throws Exception { lock.lock(); try { - if ("ping".equals(message)) + if ("ping".equals(message)) { getSender().tell("pong", getSelf()); + } } finally { lock.unlock(); } diff --git a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf index df6091b015..6c5e91a168 100644 --- a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf +++ b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf @@ -31,6 +31,11 @@ + + as:actor-system-provider-impl + actor-system-provider-impl + + prefix:distributed-operational-datastore-provider distributed-operational-store-module @@ -38,6 +43,10 @@ dom:schema-service yang-schema-service + + as:actor-system-provider-service + actor-system-provider + false 20 @@ -51,6 +60,10 @@ dom:schema-service yang-schema-service + + as:actor-system-provider-service + actor-system-provider + 20 @@ -63,8 +76,11 @@ dom:dom-broker-osgi-registry dom-broker + + as:actor-system-provider-service + actor-system-provider + true - odl-cluster-rpc 1000 @@ -72,6 +88,13 @@ + + as:actor-system-provider-service + + actor-system-provider + /modules/module[type='actor-system-provider-impl'][name='actor-system-provider-impl'] + + config-dom-store-spi:config-dom-datastore @@ -101,6 +124,8 @@ urn:opendaylight:params:xml:ns:yang:controller:config:concurrent-data-broker?module=odl-concurrent-data-broker-cfg&revision=2014-11-24 + urn:opendaylight:params:xml:ns:yang:controller:config:actor-system-provider:service?module=actor-system-provider-service&revision=2015-10-05 + urn:opendaylight:params:xml:ns:yang:controller:config:actor-system-provider:impl?module=actor-system-provider-impl&revision=2015-10-05 urn:opendaylight:params:xml:ns:yang:controller:config:distributed-datastore-provider?module=distributed-datastore-provider&revision=2014-06-12 urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:config-dom-store?module=opendaylight-config-dom-datastore&revision=2014-06-17 urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:operational-dom-store?module=opendaylight-operational-dom-datastore&revision=2014-06-17 diff --git a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/akka.conf b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/akka.conf index f542847fa1..5a6dbe5879 100644 --- a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/akka.conf +++ b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/akka.conf @@ -71,40 +71,3 @@ odl-cluster-data { } } } - -odl-cluster-rpc { - bounded-mailbox { - mailbox-type = "org.opendaylight.controller.cluster.common.actor.MeteredBoundedMailbox" - mailbox-capacity = 1000 - mailbox-push-timeout-time = 100ms - } - - metric-capture-enabled = true - - akka { - loglevel = "INFO" - loggers = ["akka.event.slf4j.Slf4jLogger"] - logger-startup-timeout = 300s - - actor { - provider = "akka.cluster.ClusterActorRefProvider" - - } - remote { - log-remote-lifecycle-events = off - netty.tcp { - hostname = "127.0.0.1" - port = 2551 - maximum-frame-size = 419430400 - send-buffer-size = 52428800 - receive-buffer-size = 52428800 - } - } - - cluster { - seed-nodes = ["akka.tcp://odl-cluster-rpc@127.0.0.1:2551"] - - auto-down-unreachable-after = 300s - } - } -} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java index 455b36c151..49f5388842 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java @@ -203,7 +203,6 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener, txContextFactory.close(); actorContext.shutdown(); - DistributedDataStoreFactory.destroyInstance(this); } public ActorContext getActorContext() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java index 4d3854f9ef..25029b6f18 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java @@ -8,31 +8,18 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.osgi.BundleDelegatingClassLoader; -import com.google.common.base.Preconditions; -import com.typesafe.config.ConfigFactory; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader; import org.opendaylight.controller.cluster.datastore.config.Configuration; import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl; import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import scala.concurrent.duration.Duration; public class DistributedDataStoreFactory { - private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data"; - private static final String CONFIGURATION_NAME = "odl-cluster-data"; - private static ActorSystem actorSystem = null; - private static final Set createdInstances = new HashSet<>(2); private static final Logger LOG = LoggerFactory.getLogger(DistributedDataStoreFactory.class); - public static synchronized DistributedDataStore createInstance(SchemaService schemaService, - DatastoreContext datastoreContext, BundleContext bundleContext) { + public static DistributedDataStore createInstance(SchemaService schemaService, + DatastoreContext datastoreContext, ActorSystem actorSystem, BundleContext bundleContext) { LOG.info("Create data store instance of type : {}", datastoreContext.getDataStoreType()); @@ -40,7 +27,6 @@ public class DistributedDataStoreFactory { DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay( introspector, bundleContext); - ActorSystem actorSystem = getActorSystem(bundleContext, datastoreContext.getConfigurationReader()); Configuration config = new ConfigurationImpl("module-shards.conf", "modules.conf"); final DistributedDataStore dataStore = new DistributedDataStore(actorSystem, new ClusterWrapperImpl(actorSystem), config, introspector.getContext()); @@ -52,43 +38,6 @@ public class DistributedDataStoreFactory { dataStore.setCloseable(overlay); dataStore.waitTillReady(); - createdInstances.add(dataStore); return dataStore; } - - private static synchronized final ActorSystem getActorSystem(final BundleContext bundleContext, - AkkaConfigurationReader configurationReader) { - if (actorSystem == null) { - // Create an OSGi bundle classloader for actor system - BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(), - Thread.currentThread().getContextClassLoader()); - - actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, - ConfigFactory.load(configurationReader.read()).getConfig(CONFIGURATION_NAME), classLoader); - actorSystem.actorOf(Props.create(TerminationMonitor.class), "termination-monitor"); - } - - return actorSystem; - } - - public static synchronized void destroyInstance(DistributedDataStore dataStore){ - Preconditions.checkNotNull(dataStore, "dataStore should not be null"); - - LOG.info("Destroy data store instance of type : {}", dataStore.getActorContext().getDataStoreType()); - - if(createdInstances.remove(dataStore)){ - if(createdInstances.size() == 0){ - if(actorSystem != null) { - actorSystem.shutdown(); - try { - actorSystem.awaitTermination(Duration.create(10, TimeUnit.SECONDS)); - } catch (Exception e) { - LOG.warn("Error awaiting actor termination", e); - } - actorSystem = null; - } - } - } - } - } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java new file mode 100644 index 0000000000..22d728dd75 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.config.actor_system_provider.impl; + +import akka.actor.ActorSystem; +import akka.osgi.BundleDelegatingClassLoader; +import com.typesafe.config.ConfigFactory; +import java.util.concurrent.TimeUnit; +import org.opendaylight.controller.cluster.ActorSystemProvider; +import org.opendaylight.controller.cluster.ActorSystemProviderListener; +import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader; +import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.util.ListenerRegistry; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import scala.concurrent.duration.Duration; + +public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseable { + private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data"; + private static final String CONFIGURATION_NAME = "odl-cluster-data"; + static final Logger LOG = LoggerFactory.getLogger(ActorSystemProviderImpl.class); + + private ActorSystem actorSystem; + private final BundleDelegatingClassLoader classLoader; + private final ListenerRegistry listeners = new ListenerRegistry<>(); + + public ActorSystemProviderImpl(BundleContext bundleContext) { + LOG.info("Creating new ActorSystem"); + + classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(), + Thread.currentThread().getContextClassLoader()); + + createActorSystem(); + } + + private void createActorSystem() { + AkkaConfigurationReader configurationReader = new FileAkkaConfigurationReader(); + actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, + ConfigFactory.load(configurationReader.read()).getConfig(CONFIGURATION_NAME), classLoader); + } + + @Override + public ActorSystem getActorSystem() { + return actorSystem; + } + + @Override + public ListenerRegistration registerActorSystemProviderListener( + ActorSystemProviderListener listener) { + return listeners.register(listener); + } + + @Override + public void close() { + LOG.info("Shutting down ActorSystem"); + + actorSystem.shutdown(); + try { + actorSystem.awaitTermination(Duration.create(10, TimeUnit.SECONDS)); + } catch (Exception e) { + LOG.warn("Error awaiting actor termination", e); + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModule.java new file mode 100644 index 0000000000..96cb83de42 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModule.java @@ -0,0 +1,29 @@ +package org.opendaylight.controller.config.yang.config.actor_system_provider.impl; + +import org.osgi.framework.BundleContext; + +public class ActorSystemProviderModule extends AbstractActorSystemProviderModule { + private BundleContext bundleContext; + + public ActorSystemProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public ActorSystemProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, ActorSystemProviderModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new ActorSystemProviderImpl(bundleContext); + } + + public void setBundleContext(BundleContext bundleContext) { + this.bundleContext = bundleContext; + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModuleFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModuleFactory.java new file mode 100644 index 0000000000..94042dd778 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderModuleFactory.java @@ -0,0 +1,33 @@ +/* +* Generated file +* +* Generated from: yang module name: actor-system-provider-impl yang module local name: actor-system-provider-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Tue Oct 06 02:11:27 EDT 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.config.actor_system_provider.impl; + +import org.opendaylight.controller.config.api.DependencyResolver; +import org.opendaylight.controller.config.api.DynamicMBeanWithInstance; +import org.opendaylight.controller.config.spi.Module; +import org.osgi.framework.BundleContext; + +public class ActorSystemProviderModuleFactory extends AbstractActorSystemProviderModuleFactory { + @Override + public Module createModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) { + ActorSystemProviderModule module = (ActorSystemProviderModule)super.createModule(instanceName,dependencyResolver,bundleContext); + module.setBundleContext(bundleContext); + return module; + } + + @Override + public Module createModule(String instanceName, DependencyResolver dependencyResolver, + DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception { + ActorSystemProviderModule module = (ActorSystemProviderModule)super.createModule(instanceName, dependencyResolver, + old, bundleContext); + module.setBundleContext(bundleContext); + return module; + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java index f43f13d904..4ad6ca7e5e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java @@ -72,7 +72,7 @@ public class DistributedConfigDataStoreProviderModule extends .build(); return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(), - datastoreContext, bundleContext); + datastoreContext, getConfigActorSystemProviderDependency().getActorSystem(), bundleContext); } public void setBundleContext(BundleContext bundleContext) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java index 85dddde443..ef3fa45147 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java @@ -73,7 +73,7 @@ public class DistributedOperationalDataStoreProviderModule extends .build(); return DistributedDataStoreFactory.createInstance(getOperationalSchemaServiceDependency(), - datastoreContext, bundleContext); + datastoreContext, getOperationalActorSystemProviderDependency().getActorSystem(), bundleContext); } public void setBundleContext(BundleContext bundleContext) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/actor-system-provider-impl.yang b/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/actor-system-provider-impl.yang new file mode 100644 index 0000000000..75d6125fda --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/actor-system-provider-impl.yang @@ -0,0 +1,26 @@ +module actor-system-provider-impl { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:config:actor-system-provider:impl"; + prefix "actor-system-impl"; + + import config { prefix config; revision-date 2013-04-05; } + import actor-system-provider-service {prefix actor-system;} + + description "Akka actor system provider implementation"; + + revision "2015-10-05" { + description "Initial revision"; + } + + identity actor-system-provider-impl { + base config:module-type; + config:provided-service actor-system:actor-system-provider-service; + config:java-name-prefix ActorSystemProvider; + } + + augment "/config:modules/config:module/config:configuration" { + case actor-system-provider-impl { + when "/config:modules/config:module/config:type = 'actor-system-provider-impl'"; + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang b/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang index 91c4279f24..b6980a659f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang @@ -10,6 +10,7 @@ module distributed-datastore-provider { import opendaylight-config-dom-datastore {prefix config-dom-store-spi;} import opendaylight-operational-dom-datastore {prefix operational-dom-store-spi;} import opendaylight-md-sal-dom {prefix sal;} + import actor-system-provider-service {prefix actor-system;} description "This module contains the base YANG definitions for @@ -241,12 +242,21 @@ module distributed-datastore-provider { container config-schema-service { uses config:service-ref { refine type { - mandatory false; + mandatory true; config:required-identity sal:schema-service; } } } + container config-actor-system-provider { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity actor-system:actor-system-provider-service; + } + } + } + container config-properties { uses data-store-properties; } @@ -260,12 +270,21 @@ module distributed-datastore-provider { container operational-schema-service { uses config:service-ref { refine type { - mandatory false; + mandatory true; config:required-identity sal:schema-service; } } } + container operational-actor-system-provider { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity actor-system:actor-system-provider-service; + } + } + } + container operational-properties { uses data-store-properties; } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModule.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModule.java index 8bf768d6be..d7843eab8a 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModule.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModule.java @@ -1,45 +1,45 @@ package org.opendaylight.controller.config.yang.config.remote_rpc_connector; -import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader; +import akka.actor.ActorSystem; import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; import org.opendaylight.controller.remote.rpc.RemoteRpcProviderFactory; import org.opendaylight.controller.sal.core.api.Broker; import org.osgi.framework.BundleContext; public class RemoteRPCBrokerModule extends org.opendaylight.controller.config.yang.config.remote_rpc_connector.AbstractRemoteRPCBrokerModule { - private BundleContext bundleContext; - public RemoteRPCBrokerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public RemoteRPCBrokerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.remote_rpc_connector.RemoteRPCBrokerModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public boolean canReuseInstance(AbstractRemoteRPCBrokerModule oldModule) { - return true; - } - - @Override - public java.lang.AutoCloseable createInstance() { - Broker broker = getDomBrokerDependency(); - - RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder(getActorSystemName()) - .metricCaptureEnabled(getEnableMetricCapture()) - .mailboxCapacity(getBoundedMailboxCapacity()) - .withConfigReader(new FileAkkaConfigurationReader()) - .build(); - - return RemoteRpcProviderFactory.createInstance(broker, bundleContext, config); - } - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } + private BundleContext bundleContext; + public RemoteRPCBrokerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public RemoteRPCBrokerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.remote_rpc_connector.RemoteRPCBrokerModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public boolean canReuseInstance(AbstractRemoteRPCBrokerModule oldModule) { + return true; + } + + @Override + public java.lang.AutoCloseable createInstance() { + Broker broker = getDomBrokerDependency(); + + ActorSystem actorSystem = getActorSystemProviderDependency().getActorSystem(); + RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder(actorSystem.name()) + .metricCaptureEnabled(getEnableMetricCapture()) + .mailboxCapacity(getBoundedMailboxCapacity()) + .build(); + + return RemoteRpcProviderFactory.createInstance(broker, bundleContext, actorSystem, config); + } + + public void setBundleContext(BundleContext bundleContext) { + this.bundleContext = bundleContext; + } } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java index a1b6286a59..8be62c482e 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java @@ -11,6 +11,7 @@ package org.opendaylight.controller.remote.rpc; import akka.actor.ActorRef; import akka.actor.ActorSystem; +import com.google.common.base.Preconditions; import java.util.Collection; import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService; import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; @@ -42,10 +43,12 @@ public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContext private final RemoteRpcProviderConfig config; - public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry) { + public RemoteRpcProvider(final ActorSystem actorSystem, + final DOMRpcProviderService rpcProvisionRegistry, + final RemoteRpcProviderConfig config) { this.actorSystem = actorSystem; this.rpcProvisionRegistry = rpcProvisionRegistry; - config = new RemoteRpcProviderConfig(actorSystem.settings().config()); + this.config = Preconditions.checkNotNull(config); } @Override @@ -78,7 +81,7 @@ public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContext final DOMRpcService rpcService = brokerSession.getService(DOMRpcService.class); schemaContext = schemaService.getGlobalContext(); rpcManager = actorSystem.actorOf(RpcManager.props(schemaContext, - rpcProvisionRegistry, rpcService), config.getRpcManagerName()); + rpcProvisionRegistry, rpcService, config), config.getRpcManagerName()); schemaListenerRegistration = schemaService.registerSchemaContextListener(this); LOG.debug("rpc manager started"); } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderConfig.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderConfig.java index 3f6d42d742..6f3a10e648 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderConfig.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderConfig.java @@ -9,11 +9,10 @@ package org.opendaylight.controller.remote.rpc; import akka.util.Timeout; import com.typesafe.config.Config; +import java.util.concurrent.TimeUnit; import org.opendaylight.controller.cluster.common.actor.CommonConfig; import scala.concurrent.duration.FiniteDuration; -import java.util.concurrent.TimeUnit; - /** */ public class RemoteRpcProviderConfig extends CommonConfig { diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactory.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactory.java index 83101a77b8..af36b8afc9 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactory.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactory.java @@ -9,43 +9,17 @@ package org.opendaylight.controller.remote.rpc; import akka.actor.ActorSystem; -import akka.osgi.BundleDelegatingClassLoader; -import com.typesafe.config.Config; import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService; import org.opendaylight.controller.sal.core.api.Broker; import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class RemoteRpcProviderFactory { - private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProviderFactory.class); + public static RemoteRpcProvider createInstance(final Broker broker, final BundleContext bundleContext, + final ActorSystem actorSystem, final RemoteRpcProviderConfig config) { - public static RemoteRpcProvider createInstance( - final Broker broker, final BundleContext bundleContext, final RemoteRpcProviderConfig config){ + final RemoteRpcProvider rpcProvider = new RemoteRpcProvider(actorSystem, (DOMRpcProviderService) broker, config); - final RemoteRpcProvider rpcProvider = - new RemoteRpcProvider(createActorSystem(bundleContext, config), (DOMRpcProviderService) broker); - - broker.registerProvider(rpcProvider); - return rpcProvider; - } - - private static ActorSystem createActorSystem(final BundleContext bundleContext, final RemoteRpcProviderConfig config){ - - // Create an OSGi bundle classloader for actor system - final BundleDelegatingClassLoader classLoader = - new BundleDelegatingClassLoader(bundleContext.getBundle(), - Thread.currentThread().getContextClassLoader()); - - final Config actorSystemConfig = config.get(); - if(LOG.isDebugEnabled()) { - LOG.debug("Actor system configuration\n{}", actorSystemConfig.root().render()); - } - if (config.isMetricCaptureEnabled()) { - LOG.info("Instrumentation is enabled in actor system {}. Metrics can be viewed in JMX console.", - config.getActorSystemName()); - } - - return ActorSystem.create(config.getActorSystemName(), actorSystemConfig, classLoader); + broker.registerProvider(rpcProvider); + return rpcProvider; } } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java index 1ade84bd0f..fc75ea6089 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java @@ -55,11 +55,12 @@ public class RpcManager extends AbstractUntypedActor { private RpcManager(final SchemaContext schemaContext, final DOMRpcProviderService rpcProvisionRegistry, - final DOMRpcService rpcSevices) { + final DOMRpcService rpcSevices, + final RemoteRpcProviderConfig config) { this.schemaContext = schemaContext; this.rpcProvisionRegistry = rpcProvisionRegistry; rpcServices = rpcSevices; - config = new RemoteRpcProviderConfig(getContext().system().settings().config()); + this.config = config; createRpcActors(); startListeners(); @@ -67,18 +68,19 @@ public class RpcManager extends AbstractUntypedActor { public static Props props(final SchemaContext schemaContext, - final DOMRpcProviderService rpcProvisionRegistry, final DOMRpcService rpcServices) { + final DOMRpcProviderService rpcProvisionRegistry, final DOMRpcService rpcServices, + final RemoteRpcProviderConfig config) { Preconditions.checkNotNull(schemaContext, "SchemaContext can not be null!"); Preconditions.checkNotNull(rpcProvisionRegistry, "RpcProviderService can not be null!"); Preconditions.checkNotNull(rpcServices, "RpcService can not be null!"); - return Props.create(RpcManager.class, schemaContext, rpcProvisionRegistry, rpcServices); + return Props.create(RpcManager.class, schemaContext, rpcProvisionRegistry, rpcServices, config); } private void createRpcActors() { LOG.debug("Create rpc registry and broker actors"); rpcRegistry = - getContext().actorOf(RpcRegistry.props(). + getContext().actorOf(RpcRegistry.props(config). withMailbox(config.getMailBoxName()), config.getRpcRegistryName()); rpcBroker = diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java index 1dcc4e1405..c2ff0456f7 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java @@ -15,6 +15,7 @@ import akka.japi.Pair; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.List; +import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes; import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.FindRouters; import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes; @@ -34,12 +35,13 @@ import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier; */ public class RpcRegistry extends BucketStore { - public RpcRegistry() { + public RpcRegistry(RemoteRpcProviderConfig config) { + super(config); getLocalBucket().setData(new RoutingTable()); } - public static Props props() { - return Props.create(new RpcRegistryCreator()); + public static Props props(RemoteRpcProviderConfig config) { + return Props.create(new RpcRegistryCreator(config)); } @Override @@ -231,10 +233,15 @@ public class RpcRegistry extends BucketStore { private static class RpcRegistryCreator implements Creator { private static final long serialVersionUID = 1L; + private final RemoteRpcProviderConfig config; + + private RpcRegistryCreator(RemoteRpcProviderConfig config) { + this.config = config; + } @Override public RpcRegistry create() throws Exception { - RpcRegistry registry = new RpcRegistry(); + RpcRegistry registry = new RpcRegistry(config); RemoteRpcRegistryMXBean mxBean = new RemoteRpcRegistryMXBeanImpl(registry); return registry; } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStore.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStore.java index febff0bc92..d349035b3c 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStore.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStore.java @@ -13,6 +13,7 @@ import akka.actor.ActorRefProvider; import akka.actor.Address; import akka.actor.Props; import akka.cluster.ClusterActorRefProvider; +import com.google.common.base.Preconditions; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -68,8 +69,8 @@ public class BucketStore> extends AbstractUntypedActorWithMe private final RemoteRpcProviderConfig config; - public BucketStore(){ - config = new RemoteRpcProviderConfig(getContext().system().settings().config()); + public BucketStore(RemoteRpcProviderConfig config){ + this.config = Preconditions.checkNotNull(config); } @Override @@ -78,7 +79,7 @@ public class BucketStore> extends AbstractUntypedActorWithMe selfAddress = provider.getDefaultAddress(); if ( provider instanceof ClusterActorRefProvider) { - getContext().actorOf(Props.create(Gossiper.class).withMailbox(config.getMailBoxName()), "gossiper"); + getContext().actorOf(Props.create(Gossiper.class, config).withMailbox(config.getMailBoxName()), "gossiper"); } } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/Gossiper.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/Gossiper.java index e45950d1ca..f597c316e5 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/Gossiper.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/Gossiper.java @@ -18,6 +18,7 @@ import akka.cluster.ClusterEvent; import akka.cluster.Member; import akka.dispatch.Mapper; import akka.pattern.Patterns; +import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -77,10 +78,10 @@ public class Gossiper extends AbstractUntypedActorWithMetering { private Boolean autoStartGossipTicks = true; - private RemoteRpcProviderConfig config; + private final RemoteRpcProviderConfig config; - public Gossiper(){ - config = new RemoteRpcProviderConfig(getContext().system().settings().config()); + public Gossiper(RemoteRpcProviderConfig config){ + this.config = Preconditions.checkNotNull(config); } /** @@ -88,7 +89,8 @@ public class Gossiper extends AbstractUntypedActorWithMetering { * @param autoStartGossipTicks used for turning off gossip ticks during testing. * Gossip tick can be manually sent. */ - public Gossiper(Boolean autoStartGossipTicks){ + public Gossiper(Boolean autoStartGossipTicks, RemoteRpcProviderConfig config){ + this(config); this.autoStartGossipTicks = autoStartGossipTicks; } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/yang/remote-rpc-connector.yang b/opendaylight/md-sal/sal-remoterpc-connector/src/main/yang/remote-rpc-connector.yang index 334d872c44..6f21929d78 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/yang/remote-rpc-connector.yang +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/yang/remote-rpc-connector.yang @@ -5,6 +5,7 @@ module remote-rpc-connector { import config { prefix config; revision-date 2013-04-05; } import opendaylight-md-sal-dom {prefix dom;} + import actor-system-provider-service {prefix actor-system;} description "This module contains the base YANG definitions for @@ -35,18 +36,21 @@ module remote-rpc-connector { } } + container actor-system-provider { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity actor-system:actor-system-provider-service; + } + } + } + leaf enable-metric-capture { default false; type boolean; description "Enable or disable metric capture."; } - leaf actor-system-name { - default odl-cluster-rpc; - type string; - description "Name by which actor system is identified. Its also used to find relevant configuration"; - } - leaf bounded-mailbox-capacity { default 1000; type uint16; diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderTest.java index 78a368fe8d..1187365a85 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderTest.java @@ -51,7 +51,8 @@ public class RemoteRpcProviderTest { @Test public void testRemoteRpcProvider() throws Exception { - final RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(DOMRpcProviderService.class)); + final RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(DOMRpcProviderService.class), + new RemoteRpcProviderConfig(system.settings().config())); final Broker.ProviderSession session = mock(Broker.ProviderSession.class); final SchemaService schemaService = mock(SchemaService.class); when(schemaService.getGlobalContext()). thenReturn(mock(SchemaContext.class)); diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java index d83d513170..8700334b22 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java @@ -15,6 +15,8 @@ import akka.actor.Props; import akka.japi.Pair; import akka.testkit.JavaTestKit; import com.google.common.util.concurrent.Uninterruptibles; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -29,6 +31,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader; import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; import org.opendaylight.controller.remote.rpc.RouteIdentifierImpl; import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes; @@ -61,26 +64,37 @@ public class RpcRegistryTest { @BeforeClass public static void staticSetup() throws InterruptedException { - RemoteRpcProviderConfig config1 = new RemoteRpcProviderConfig.Builder("memberA").build(); - RemoteRpcProviderConfig config2 = new RemoteRpcProviderConfig.Builder("memberB").build(); - RemoteRpcProviderConfig config3 = new RemoteRpcProviderConfig.Builder("memberC").build(); - node1 = ActorSystem.create("opendaylight-rpc", config1.get()); - node2 = ActorSystem.create("opendaylight-rpc", config2.get()); - node3 = ActorSystem.create("opendaylight-rpc", config3.get()); + AkkaConfigurationReader reader = new AkkaConfigurationReader() { + @Override + public Config read() { + return ConfigFactory.load(); + } + }; + + RemoteRpcProviderConfig config1 = new RemoteRpcProviderConfig.Builder("memberA").withConfigReader(reader).build(); + RemoteRpcProviderConfig config2 = new RemoteRpcProviderConfig.Builder("memberB").withConfigReader(reader).build(); + RemoteRpcProviderConfig config3 = new RemoteRpcProviderConfig.Builder("memberC").withConfigReader(reader).build(); + node1 = ActorSystem.create("opendaylight-rpc", config1.get()); + node2 = ActorSystem.create("opendaylight-rpc", config2.get()); + node3 = ActorSystem.create("opendaylight-rpc", config3.get()); } @AfterClass public static void staticTeardown() { - JavaTestKit.shutdownActorSystem(node1); - JavaTestKit.shutdownActorSystem(node2); - JavaTestKit.shutdownActorSystem(node3); + JavaTestKit.shutdownActorSystem(node1); + JavaTestKit.shutdownActorSystem(node2); + JavaTestKit.shutdownActorSystem(node3); } @Before public void setup() { - registry1 = node1.actorOf(Props.create(RpcRegistry.class)); - registry2 = node2.actorOf(Props.create(RpcRegistry.class)); - registry3 = node3.actorOf(Props.create(RpcRegistry.class)); + registry1 = node1.actorOf(Props.create(RpcRegistry.class, config(node1))); + registry2 = node2.actorOf(Props.create(RpcRegistry.class, config(node2))); + registry3 = node3.actorOf(Props.create(RpcRegistry.class, config(node3))); + } + + private RemoteRpcProviderConfig config(ActorSystem node){ + return new RemoteRpcProviderConfig(node.settings().config()); } @After diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStoreTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStoreTest.java index ddd08a5f47..667a1156f2 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStoreTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStoreTest.java @@ -18,6 +18,7 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; import org.opendaylight.controller.remote.rpc.TerminationMonitor; public class BucketStoreTest { @@ -131,7 +132,7 @@ public class BucketStoreTest { * @return instance of BucketStore class */ private static BucketStore createStore(){ - final Props props = Props.create(BucketStore.class); + final Props props = Props.create(BucketStore.class, new RemoteRpcProviderConfig(system.settings().config())); final TestActorRef testRef = TestActorRef.create(system, props, "testStore"); return testRef.underlyingActor(); } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java index cf42ebf1cc..54b09bfce7 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java @@ -7,34 +7,33 @@ */ package org.opendaylight.controller.remote.rpc.registry.gossip; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyMap; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipEnvelope; +import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipStatus; import akka.actor.ActorSystem; import akka.actor.Address; import akka.actor.Props; import akka.testkit.TestActorRef; import com.typesafe.config.ConfigFactory; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; import org.opendaylight.controller.remote.rpc.TerminationMonitor; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipEnvelope; -import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipStatus; - public class GossiperTest { @@ -121,7 +120,7 @@ public class GossiperTest { */ private static Gossiper createGossiper(){ - final Props props = Props.create(Gossiper.class, false); + final Props props = Props.create(Gossiper.class, false, new RemoteRpcProviderConfig(system.settings().config())); final TestActorRef testRef = TestActorRef.create(system, props, "testGossiper"); return testRef.underlyingActor(); -- 2.36.6