Bug 8967 - Various classes in cntrl/md-sal use hardcoded 51/62451/11
authorJakub Toth <jakub.toth@pantheon.tech>
Wed, 30 Aug 2017 14:29:46 +0000 (16:29 +0200)
committerJakub Toth <jakub.toth@pantheon.tech>
Sat, 2 Sep 2017 18:32:59 +0000 (18:32 +0000)
dependencies on OSGI/karaf - PART 1

  * remove dependency of ActorSystemProviderImpl on OSGI
  * move Config out of ActorSystemProviderImpl

Change-Id: I7e9cb184385207726839e137ea6dcafd6359c47b
Signed-off-by: Jakub Toth <jakub.toth@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/AkkaConfigFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/BundleClassLoaderFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/QuarantinedMonitorActorPropsFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/resources/org/opendaylight/blueprint/clustered-datastore.xml

index 5b6e447..ef2db4b 100644 (file)
@@ -9,22 +9,14 @@ package org.opendaylight.controller.config.yang.config.actor_system_provider.imp
 
 import akka.actor.ActorSystem;
 import akka.actor.Props;
-import akka.osgi.BundleDelegatingClassLoader;
 import com.typesafe.config.Config;
-import com.typesafe.config.ConfigFactory;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 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.controller.cluster.common.actor.QuarantinedMonitorActor;
 import org.opendaylight.controller.cluster.datastore.TerminationMonitor;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.util.ListenerRegistry;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import scala.concurrent.Await;
@@ -32,33 +24,18 @@ 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 final ActorSystem actorSystem;
     private final ListenerRegistry<ActorSystemProviderListener> listeners = new ListenerRegistry<>();
 
-    public ActorSystemProviderImpl(final BundleContext bundleContext) {
+    public ActorSystemProviderImpl(
+            final ClassLoader classLoader, final Props quarantinedMonitorActorProps, final Config akkaConfig) {
         LOG.info("Creating new ActorSystem");
 
-        final Bundle bundle = bundleContext.getBundle();
-
-        final BundleDelegatingClassLoader classLoader = AccessController.doPrivileged(
-            (PrivilegedAction<BundleDelegatingClassLoader>) () ->
-                new BundleDelegatingClassLoader(bundle, Thread.currentThread().getContextClassLoader()));
-
-        final AkkaConfigurationReader configurationReader = new FileAkkaConfigurationReader();
-        final Config akkaConfig = ConfigFactory.load(configurationReader.read()).getConfig(CONFIGURATION_NAME);
-
         actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, akkaConfig, classLoader);
 
         actorSystem.actorOf(Props.create(TerminationMonitor.class), TerminationMonitor.ADDRESS);
-
-        actorSystem.actorOf(QuarantinedMonitorActor.props(() -> {
-            // restart the entire karaf container
-            LOG.warn("Restarting karaf container");
-            System.setProperty("karaf.restart.jvm", "true");
-            bundleContext.getBundle(0).stop();
-        }), QuarantinedMonitorActor.ADDRESS);
+        actorSystem.actorOf(quarantinedMonitorActorProps, QuarantinedMonitorActor.ADDRESS);
     }
 
     @Override
@@ -79,7 +56,7 @@ public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseab
 
         try {
             Await.result(actorSystem.terminate(), Duration.create(10, TimeUnit.SECONDS));
-        } catch (Exception e) {
+        } catch (final Exception e) {
             LOG.warn("Error awaiting actor termination", e);
         }
     }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/AkkaConfigFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/AkkaConfigFactory.java
new file mode 100644 (file)
index 0000000..1357e55
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.factory;
+
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
+
+public class AkkaConfigFactory {
+
+    private static final String CONFIGURATION_NAME = "odl-cluster-data";
+
+    public static Config createAkkaConfig(final AkkaConfigurationReader reader) {
+        return ConfigFactory.load(reader.read()).getConfig(CONFIGURATION_NAME);
+    }
+}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/BundleClassLoaderFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/BundleClassLoaderFactory.java
new file mode 100644 (file)
index 0000000..d47b47b
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.factory.osgi;
+
+import akka.osgi.BundleDelegatingClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import org.osgi.framework.BundleContext;
+
+public class BundleClassLoaderFactory {
+
+    public static ClassLoader createClassLoader(final BundleContext bundleContext) {
+        return AccessController
+                .doPrivileged((PrivilegedAction<BundleDelegatingClassLoader>) () -> new BundleDelegatingClassLoader(
+                        bundleContext.getBundle(), Thread.currentThread().getContextClassLoader()));
+    }
+}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/QuarantinedMonitorActorPropsFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/QuarantinedMonitorActorPropsFactory.java
new file mode 100644 (file)
index 0000000..348241d
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.factory.osgi;
+
+import akka.actor.Props;
+import org.opendaylight.controller.cluster.common.actor.QuarantinedMonitorActor;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class QuarantinedMonitorActorPropsFactory {
+    private static final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActorPropsFactory.class);
+
+    public static Props createProps(final BundleContext bundleContext) {
+        return QuarantinedMonitorActor.props(() -> {
+            // restart the entire karaf container
+            LOG.warn("Restarting karaf container");
+            System.setProperty("karaf.restart.jvm", "true");
+            bundleContext.getBundle().stop();
+        });
+    }
+}
index 28411e5..6f4301f 100644 (file)
 
   <!-- ActorSystemProvider -->
 
+  <bean id="bundleClassLoader" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.factory.osgi.BundleClassLoaderFactory"
+          factory-method="createClassLoader">
+    <argument ref="blueprintBundleContext" />
+  </bean>
+
+  <bean id="actorSystemProps" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.factory.osgi.QuarantinedMonitorActorPropsFactory"
+          factory-method="createProps">
+    <argument ref="blueprintBundleContext" />
+  </bean>
+
+  <bean id="akkaReader" class="org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader"/>
+  <bean id="akkaConfig" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.factory.AkkaConfigFactory"
+          factory-method="createAkkaConfig">
+    <argument ref="akkaReader" />
+  </bean>
+
   <bean id="actorSystemProvider" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.ActorSystemProviderImpl"
           destroy-method="close">
-    <argument ref="blueprintBundleContext"/>
+    <argument ref="bundleClassLoader" />
+    <argument ref="actorSystemProps"/>
+    <argument ref="akkaConfig"/>
   </bean>
 
   <service ref="actorSystemProvider" interface="org.opendaylight.controller.cluster.ActorSystemProvider"/>

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.