From: Jakub Toth Date: Wed, 30 Aug 2017 14:29:46 +0000 (+0200) Subject: Bug 8967 - Various classes in cntrl/md-sal use hardcoded X-Git-Tag: release/oxygen~111 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=88620eacdbb3a8e4b8c3114f0628ff95a5c8b5f6 Bug 8967 - Various classes in cntrl/md-sal use hardcoded 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 --- 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 index 5b6e447d0b..ef2db4b0c1 100644 --- 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 @@ -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 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) () -> - 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 index 0000000000..1357e555bb --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/AkkaConfigFactory.java @@ -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 index 0000000000..d47b47bb60 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/BundleClassLoaderFactory.java @@ -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) () -> 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 index 0000000000..348241d358 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/factory/osgi/QuarantinedMonitorActorPropsFactory.java @@ -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(); + }); + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/org/opendaylight/blueprint/clustered-datastore.xml b/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/org/opendaylight/blueprint/clustered-datastore.xml index 28411e50fb..6f4301f992 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/org/opendaylight/blueprint/clustered-datastore.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/org/opendaylight/blueprint/clustered-datastore.xml @@ -14,9 +14,27 @@ + + + + + + + + + + + + + - + + +