From 1170cbe05efa5ee7b62773e5ffcfb7cc14fe7ed0 Mon Sep 17 00:00:00 2001 From: Harman Singh Date: Fri, 1 Aug 2014 18:35:58 -0700 Subject: [PATCH] Adding remoterpc connector to distribution and Updating actor system creation Actor system will be created with in bundle class loader now. This change has been made to avoid any conflict with other actor systems. We faced one class cast exception earlier and this fixes that Change-Id: Iad55e60ee950fdcff8698270445f0da31bc39c5e Signed-off-by: Harman Singh --- opendaylight/commons/opendaylight/pom.xml | 12 ++++++ .../distribution/opendaylight/pom.xml | 5 +++ .../md-sal/sal-remoterpc-connector/pom.xml | 5 ++- .../RemoteRPCBrokerModule.java | 8 +++- .../RemoteRPCBrokerModuleFactory.java | 19 +++++++++ .../remote/rpc/ActorSystemFactory.java | 42 ++++++++++++------- .../remote/rpc/RemoteRpcProviderFactory.java | 5 ++- .../remote/rpc/utils/XmlDocumentUtils.java | 3 +- 8 files changed, 81 insertions(+), 18 deletions(-) diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index a7bbbe772d..ff8735a518 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -332,6 +332,11 @@ akka-testkit_${scala.version} ${akka.version} + + com.typesafe.akka + akka-osgi_${scala.version} + ${akka.version} + commons-codec commons-codec @@ -1284,6 +1289,13 @@ ${mdsal.version} + + org.opendaylight.controller + sal-remoterpc-connector + ${mdsal.version} + + + org.opendaylight.controller diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index e4468b6f27..f8796e0ae4 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -1062,6 +1062,11 @@ org.opendaylight.controller sal-restconf-broker + + org.opendaylight.controller + sal-remoterpc-connector + + org.opendaylight.controller diff --git a/opendaylight/md-sal/sal-remoterpc-connector/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/pom.xml index ce3bfe9a4c..a2bee8ffee 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/pom.xml +++ b/opendaylight/md-sal/sal-remoterpc-connector/pom.xml @@ -34,7 +34,10 @@ com.typesafe.akka akka-testkit_${scala.version} - + + com.typesafe.akka + akka-osgi_${scala.version} + 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 9824889b80..2be8ba47b9 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 @@ -2,8 +2,10 @@ package org.opendaylight.controller.config.yang.config.remote_rpc_connector; 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); } @@ -20,6 +22,10 @@ public class RemoteRPCBrokerModule extends org.opendaylight.controller.config.ya @Override public java.lang.AutoCloseable createInstance() { Broker broker = getDomBrokerDependency(); - return RemoteRpcProviderFactory.createInstance(broker); + return RemoteRpcProviderFactory.createInstance(broker, bundleContext); + } + + public void setBundleContext(BundleContext bundleContext) { + this.bundleContext = bundleContext; } } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModuleFactory.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModuleFactory.java index 330845b14f..f97338d329 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModuleFactory.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModuleFactory.java @@ -10,6 +10,25 @@ package org.opendaylight.controller.config.yang.config.remote_rpc_connector; +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 RemoteRPCBrokerModuleFactory extends org.opendaylight.controller.config.yang.config.remote_rpc_connector.AbstractRemoteRPCBrokerModuleFactory { + @Override + public Module createModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) { + RemoteRPCBrokerModule module = (RemoteRPCBrokerModule)super.createModule(instanceName,dependencyResolver,bundleContext); + module.setBundleContext(bundleContext); + return module; + } + @Override + public Module createModule(String instanceName, DependencyResolver dependencyResolver, + DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception { + RemoteRPCBrokerModule module = (RemoteRPCBrokerModule)super.createModule(instanceName, dependencyResolver, + old, bundleContext); + module.setBundleContext(bundleContext); + return module; + } } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java index 4a6124a3bc..bd49b6239c 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java @@ -9,25 +9,39 @@ package org.opendaylight.controller.remote.rpc; import akka.actor.ActorSystem; -import akka.actor.Props; -import com.google.common.base.Function; +import akka.osgi.BundleDelegatingClassLoader; import com.typesafe.config.ConfigFactory; +import org.osgi.framework.BundleContext; -import javax.annotation.Nullable; public class ActorSystemFactory { - private static final ActorSystem actorSystem = (new Function(){ + private static volatile ActorSystem actorSystem = null; - @Nullable @Override public ActorSystem apply(@Nullable Void aVoid) { - ActorSystem system = - ActorSystem.create("opendaylight-rpc", ConfigFactory - .load().getConfig("odl-cluster")); - system.actorOf(Props.create(TerminationMonitor.class), "termination-monitor"); - return system; - } - }).apply(null); + public static final ActorSystem getInstance(){ + return actorSystem; + } + + /** + * This method should be called only once during initialization + * + * @param bundleContext + */ + public static final void createInstance(final BundleContext bundleContext) { - public static final ActorSystem getInstance(){ - return actorSystem; + if(actorSystem == null) { + // Create an OSGi bundle classloader for actor system + BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(), + Thread.currentThread().getContextClassLoader()); + synchronized (ActorSystemFactory.class) { + // Double check + if (actorSystem == null) { + ActorSystem system = ActorSystem.create("opendaylight-rpc", + ConfigFactory.load().getConfig("odl-cluster"), classLoader); + actorSystem = system; + } + } + } else { + throw new IllegalStateException("Actor system should be created only once. Use getInstance method to access existing actor system"); } + } } 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 4c40ca1777..fc75f7747a 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 @@ -11,9 +11,12 @@ package org.opendaylight.controller.remote.rpc; import org.opendaylight.controller.sal.core.api.Broker; import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; +import org.osgi.framework.BundleContext; public class RemoteRpcProviderFactory { - public static RemoteRpcProvider createInstance(final Broker broker){ + public static RemoteRpcProvider createInstance(final Broker broker, final BundleContext bundleContext){ + + ActorSystemFactory.createInstance(bundleContext); RemoteRpcProvider rpcProvider = new RemoteRpcProvider(ActorSystemFactory.getInstance(), (RpcProvisionRegistry) broker); broker.registerProvider(rpcProvider); diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/XmlDocumentUtils.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/XmlDocumentUtils.java index 49ba843071..b4cca1ab48 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/XmlDocumentUtils.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/XmlDocumentUtils.java @@ -185,7 +185,8 @@ public class XmlDocumentUtils { value = codec.deserialize(text); } - if (schema.getType() instanceof InstanceIdentifierType) { + final TypeDefinition baseType = XmlUtils.resolveBaseTypeFrom(schema.getType()); + if (baseType instanceof InstanceIdentifierType) { logger.debug("toSimpleNodeWithType: base type of node is instance identifier, deserializing element", xmlElement); value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx); } -- 2.36.6