Added BundleContext reference to generated factories for config subsystem 49/2249/2
authorMaros Marsalek <mmarsale@cisco.com>
Tue, 29 Oct 2013 15:11:04 +0000 (16:11 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Wed, 30 Oct 2013 07:49:59 +0000 (08:49 +0100)
Change-Id: I24f597f462f3f7514e55484729284825768af513
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
15 files changed:
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/spi/ModuleFactory.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ClassBasedModuleFactory.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImplTest.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapperTest.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapperTest.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/TestingParallelAPSPModuleFactory.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/TestingScheduledThreadPoolModuleFactory.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/TestingFixedThreadPoolModuleFactory.java
opendaylight/config/logback-config/pom.xml
opendaylight/config/logback-config/src/main/java/org/opendaylight/controller/config/yang/logback/config/LogbackModuleFactory.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/AbstractFactoryTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/factory_abs_template.ftl
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java

index e300523..4498743 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.controller.config.spi;
 
-import javax.management.DynamicMBean;
-
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.DependencyResolverFactory;
 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
+import org.osgi.framework.BundleContext;
 
+import javax.management.DynamicMBean;
 import java.util.Set;
 
 /**
@@ -44,11 +44,15 @@ public interface ModuleFactory {
      * @param dependencyResolver
      *            This resolver will return actual config mbean based on its
      *            ObjectName.
+     * @param bundleContext Reference to OSGi bundleContext that can be used to
+     *                      acquire OSGi services, startup configuration and other
+     *                      OSGi related information.
+     *
      * @return newly created module
      *
      */
     public Module createModule(String instanceName,
-            DependencyResolver dependencyResolver);
+            DependencyResolver dependencyResolver, BundleContext bundleContext);
 
     /**
      * Create a new Module instance. The returned object is expected to use the
@@ -78,15 +82,18 @@ public interface ModuleFactory {
      *            {@link ClassCastException} when OSGi bundle is being updated.
      *            In this case, implementation should revert to creating new
      *            instance.
+     * @param bundleContext Reference to OSGi bundleContext that can be used to
+     *                      acquire OSGi services, startup configuration and other
+     *                      OSGi related information.
+     *
      * @return newly created module
      * @throws Exception
      *             if it is not possible to recover configuration from old. This
      *             leaves server in a running state but no configuration
      *             transaction can be created.
      */
-    public Module createModule(String instanceName,
-            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old)
-            throws Exception;
+    public Module createModule(String instanceName, DependencyResolver dependencyResolver,
+            DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception;
 
     boolean isModuleImplementingServiceInterface(
             Class<? extends AbstractServiceInterface> serviceInterface);
@@ -97,9 +104,15 @@ public interface ModuleFactory {
      * the method is called for each ModuleFactory separately and transaction
      * is committed automatically, returned modules MUST be valid and commitable
      * without any manual intervention.
+     *
      * @param dependencyResolverFactory factory for getting dependency resolvers for each module.
+     * @param bundleContext Reference to OSGi bundleContext that can be used to
+     *                      acquire OSGi services, startup configuration and other
+     *                      OSGi related information.
+     *
      * @return set of default modules. Null is not allowed.
      */
-    public Set<? extends Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory);
+    public Set<? extends Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory,
+            BundleContext bundleContext);
 
 }
index 75db0e8..ef41c90 100644 (file)
@@ -7,26 +7,6 @@
  */
 package org.opendaylight.controller.config.manager.impl;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import javax.annotation.concurrent.GuardedBy;
-import javax.annotation.concurrent.NotThreadSafe;
-import javax.annotation.concurrent.ThreadSafe;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
 import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule;
@@ -50,6 +30,13 @@ import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.NotThreadSafe;
+import javax.annotation.concurrent.ThreadSafe;
+import javax.management.*;
+import java.util.*;
+import java.util.Map.Entry;
+
 /**
  * Singleton that is responsible for creating and committing Config
  * Transactions. It is registered in Platform MBean Server.
@@ -60,6 +47,10 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
 
     private final ModuleFactoriesResolver resolver;
     private final MBeanServer configMBeanServer;
+
+    @GuardedBy("this")
+    private final BundleContext bundleContext;
+
     @GuardedBy("this")
     private long version = 0;
     @GuardedBy("this")
@@ -114,6 +105,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
         this.resolver = resolver;
         this.beanToOsgiServiceManager = new BeanToOsgiServiceManager(
                 bundleContext);
+        this.bundleContext = bundleContext;
         this.configMBeanServer = configMBeanServer;
         this.baseJMXRegistrator = baseJMXRegistrator;
         this.registryMBeanServer = MBeanServerFactory
@@ -138,7 +130,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
         List<ModuleFactory> allCurrentFactories = Collections.unmodifiableList(resolver.getAllFactories());
         ConfigTransactionControllerInternal transactionController = new ConfigTransactionControllerImpl(
                 transactionName, transactionRegistrator, version,
-                versionCounter, allCurrentFactories, transactionsMBeanServer, configMBeanServer);
+                versionCounter, allCurrentFactories, transactionsMBeanServer, configMBeanServer, bundleContext);
         try {
             transactionRegistrator.registerMBean(transactionController, transactionController.getControllerObjectName());
         } catch (InstanceAlreadyExistsException e) {
index 740a741..17fb7cc 100644 (file)
@@ -7,20 +7,6 @@
  */
 package org.opendaylight.controller.config.manager.impl;
 
-import static java.lang.String.format;
-
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.GuardedBy;
-import javax.management.DynamicMBean;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.ValidationException;
@@ -32,15 +18,24 @@ import org.opendaylight.controller.config.manager.impl.dynamicmbean.ReadOnlyAtom
 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HierarchicalConfigMBeanFactoriesHolder;
 import org.opendaylight.controller.config.manager.impl.jmx.TransactionJMXRegistrator;
 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator;
-import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator
-        .TransactionModuleJMXRegistration;
+import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration;
 import org.opendaylight.controller.config.manager.impl.util.LookupBeansUtil;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.opendaylight.yangtools.concepts.Identifiable;
+import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.GuardedBy;
+import javax.management.*;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static java.lang.String.format;
+
 /**
  * This is a JMX bean representing current transaction. It contains
  * {@link #transactionIdentifier}, unique version and parent version for
@@ -74,11 +69,13 @@ class ConfigTransactionControllerImpl implements
             configBeanModificationDisabled);
     private final MBeanServer configMBeanServer;
 
+    private final BundleContext bundleContext;
+
     public ConfigTransactionControllerImpl(String transactionName,
-            TransactionJMXRegistrator transactionRegistrator,
-            long parentVersion, long currentVersion,
-            List<ModuleFactory> currentlyRegisteredFactories,
-            MBeanServer transactionsMBeanServer, MBeanServer configMBeanServer) {
+                                           TransactionJMXRegistrator transactionRegistrator,
+                                           long parentVersion, long currentVersion,
+                                           List<ModuleFactory> currentlyRegisteredFactories,
+                                           MBeanServer transactionsMBeanServer, MBeanServer configMBeanServer, BundleContext bundleContext) {
 
         this.transactionIdentifier = new TransactionIdentifier(transactionName);
         this.controllerON = ObjectNameUtil
@@ -94,6 +91,7 @@ class ConfigTransactionControllerImpl implements
         this.dependencyResolverManager = new DependencyResolverManager(transactionName, transactionStatus);
         this.transactionsMBeanServer = transactionsMBeanServer;
         this.configMBeanServer = configMBeanServer;
+        this.bundleContext = bundleContext;
     }
 
     @Override
@@ -130,7 +128,7 @@ class ConfigTransactionControllerImpl implements
         }
         // add default modules
         for (ModuleFactory moduleFactory : toBeAdded) {
-            Set<? extends Module> defaultModules = moduleFactory.getDefaultModules(dependencyResolverManager);
+            Set<? extends Module> defaultModules = moduleFactory.getDefaultModules(dependencyResolverManager, bundleContext);
             for (Module module : defaultModules) {
                 try {
                     putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null);
@@ -167,7 +165,7 @@ class ConfigTransactionControllerImpl implements
         try {
             module = moduleFactory.createModule(
                     moduleIdentifier.getInstanceName(), dependencyResolver,
-                    oldConfigBeanInfo.getReadableModule());
+                    oldConfigBeanInfo.getReadableModule(), bundleContext);
         } catch (Exception e) {
             throw new IllegalStateException(format(
                     "Error while copying old configuration from %s to %s",
@@ -188,7 +186,7 @@ class ConfigTransactionControllerImpl implements
         // find factory
         ModuleFactory moduleFactory = factoriesHolder.findByModuleName(factoryName);
         DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
-        Module module = moduleFactory.createModule(instanceName, dependencyResolver);
+        Module module = moduleFactory.createModule(instanceName, dependencyResolver, bundleContext);
         return putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module,
                 moduleFactory, null);
     }
index f0ad562..d23b5ca 100644 (file)
@@ -7,13 +7,7 @@
  */
 package org.opendaylight.controller.config.manager.impl;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import com.google.common.base.Preconditions;
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.DependencyResolverFactory;
 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
@@ -21,9 +15,14 @@ import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
+import org.osgi.framework.BundleContext;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * Creates new modules by reflection. Provided class must have this constructor:
@@ -56,7 +55,7 @@ public class ClassBasedModuleFactory implements ModuleFactory {
 
     @Override
     public Module createModule(String instanceName,
-            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old)
+            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext)
             throws Exception {
         Preconditions.checkNotNull(old);
         return constructModule(instanceName, dependencyResolver, old);
@@ -79,7 +78,7 @@ public class ClassBasedModuleFactory implements ModuleFactory {
 
     @Override
     public Module createModule(String instanceName,
-            DependencyResolver dependencyResolver) {
+            DependencyResolver dependencyResolver, BundleContext bundleContext) {
         try {
             return constructModule(instanceName, dependencyResolver, null);
         } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
@@ -105,7 +104,7 @@ public class ClassBasedModuleFactory implements ModuleFactory {
     }
 
     @Override
-    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory) {
+    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) {
         return new HashSet<Module>();
     }
 }
index eceb675..c77c97b 100644 (file)
@@ -7,17 +7,7 @@
  */
 package org.opendaylight.controller.config.manager.impl;
 
-import static org.junit.Assert.assertEquals;
-
-import java.lang.management.ManagementFactory;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
+import com.google.common.collect.Sets;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -28,7 +18,15 @@ import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXR
 import org.opendaylight.controller.config.manager.impl.runtimembean.TestingRuntimeBean;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 
-import com.google.common.collect.Sets;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
 
 public class ConfigTransactionControllerImplTest extends
         AbstractLockedPlatformMBeanServerTest {
@@ -68,7 +66,7 @@ public class ConfigTransactionControllerImplTest extends
         testedTxController = new ConfigTransactionControllerImpl(
                 transactionName123, jmxRegistrator123, 1, 1,
                 currentlyRegisteredFactories, transactionsMBeanServer,
-                ManagementFactory.getPlatformMBeanServer());
+                ManagementFactory.getPlatformMBeanServer(), null);
         TransactionModuleJMXRegistrator transactionModuleJMXRegistrator123 = testedTxController
                 .getTxModuleJMXRegistrator();
         transactionModuleJMXRegistrator123.registerMBean(
index e411778..26f46a7 100644 (file)
@@ -7,19 +7,6 @@
  */
 package org.opendaylight.controller.config.manager.impl.dynamicmbean;
 
-import static org.junit.Assert.assertEquals;
-
-import java.lang.management.ManagementFactory;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.DynamicMBean;
-import javax.management.JMX;
-import javax.management.MBeanInfo;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -32,6 +19,11 @@ import org.opendaylight.controller.config.manager.testingservices.threadpool.Tes
 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory;
 import org.opendaylight.controller.config.spi.Module;
 
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+
+import static org.junit.Assert.assertEquals;
+
 public abstract class AbstractDynamicWrapperTest extends
         AbstractLockedPlatformMBeanServerTest {
     protected final MBeanServer platformMBeanServer = ManagementFactory
@@ -54,7 +46,7 @@ public abstract class AbstractDynamicWrapperTest extends
         internalServer = MBeanServerFactory.createMBeanServer();
         TestingFixedThreadPoolModuleFactory testingFixedThreadPoolConfigBeanFactory = new TestingFixedThreadPoolModuleFactory();
         threadPoolConfigBean = testingFixedThreadPoolConfigBeanFactory
-                .createModule("", null);
+                .createModule("", null, null);
 
         threadPoolConfigBean.setThreadCount(threadCount);
         AbstractDynamicWrapper dynamicWrapper = getDynamicWrapper(
index 4c3e72f..d9ce9eb 100644 (file)
@@ -7,18 +7,6 @@
  */
 package org.opendaylight.controller.config.manager.impl.dynamicmbean;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.DynamicMBean;
-import javax.management.JMX;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
 import org.junit.Test;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
@@ -30,6 +18,12 @@ import org.opendaylight.controller.config.manager.testingservices.parallelapsp.T
 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean;
 import org.opendaylight.controller.config.spi.Module;
 
+import javax.management.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 public class DynamicWritableWrapperTest extends AbstractDynamicWrapperTest {
     private final int newThreadCount = 10;
     private final AtomicBoolean atomicBoolean = new AtomicBoolean();
@@ -84,7 +78,7 @@ public class DynamicWritableWrapperTest extends AbstractDynamicWrapperTest {
             throws Exception {
         TestingParallelAPSPModuleFactory testingParallelAPSPConfigBeanFactory = new TestingParallelAPSPModuleFactory();
         TestingParallelAPSPModule apspConfigBean = testingParallelAPSPConfigBeanFactory
-                .createModule("", null);
+                .createModule("", null, null);
         ModuleIdentifier moduleIdentifier2 = new ModuleIdentifier("apsp",
                 "parallel");
         ObjectName dynON2 = ObjectNameUtil
index dd83e91..3adf114 100644 (file)
@@ -7,9 +7,6 @@
  */
 package org.opendaylight.controller.config.manager.testingservices.parallelapsp;
 
-import javax.annotation.concurrent.ThreadSafe;
-import javax.management.ObjectName;
-
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.DependencyResolverFactory;
 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
@@ -17,7 +14,10 @@ import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
+import org.osgi.framework.BundleContext;
 
+import javax.annotation.concurrent.ThreadSafe;
+import javax.management.ObjectName;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -33,14 +33,14 @@ public class TestingParallelAPSPModuleFactory implements ModuleFactory {
 
     @Override
     public TestingParallelAPSPModule createModule(String instanceName,
-            DependencyResolver dependencyResolver) {
+            DependencyResolver dependencyResolver, BundleContext bundleContext) {
         return new TestingParallelAPSPModule(new ModuleIdentifier(NAME,
                 instanceName), dependencyResolver, null, null);
     }
 
     @Override
     public TestingParallelAPSPModule createModule(String instanceName,
-            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old)
+            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext context)
             throws Exception {
         TestingParallelAPSPImpl oldInstance;
         try {
@@ -66,7 +66,7 @@ public class TestingParallelAPSPModuleFactory implements ModuleFactory {
     }
 
     @Override
-    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory) {
+    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext context) {
         return new HashSet<Module>();
     }
 }
index c4426d1..2e10478 100644 (file)
@@ -7,21 +7,21 @@
  */
 package org.opendaylight.controller.config.manager.testingservices.scheduledthreadpool;
 
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.DependencyResolverFactory;
 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
-import org.opendaylight.controller.config.manager.testingservices.seviceinterface
-        .TestingScheduledThreadPoolServiceInterface;
+import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingScheduledThreadPoolServiceInterface;
 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
+import org.osgi.framework.BundleContext;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 public class TestingScheduledThreadPoolModuleFactory implements ModuleFactory {
     public static final String NAME = "scheduled";
@@ -42,14 +42,14 @@ public class TestingScheduledThreadPoolModuleFactory implements ModuleFactory {
 
     @Override
     public Module createModule(String instanceName,
-            DependencyResolver dependencyResolver) {
+            DependencyResolver dependencyResolver, BundleContext bundleContext) {
         return new TestingScheduledThreadPoolModule(new ModuleIdentifier(NAME,
                 instanceName), null, null);
     }
 
     @Override
     public Module createModule(String instanceName,
-            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old)
+            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext)
             throws Exception {
         TestingScheduledThreadPoolImpl oldInstance;
         try {
@@ -67,7 +67,7 @@ public class TestingScheduledThreadPoolModuleFactory implements ModuleFactory {
     }
 
     @Override
-    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory) {
+    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) {
         return new HashSet<Module>();
     }
 }
index 2c6ba17..cf05e44 100644 (file)
@@ -7,11 +7,6 @@
  */
 package org.opendaylight.controller.config.manager.testingservices.threadpool;
 
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.DependencyResolverFactory;
 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
@@ -21,6 +16,12 @@ import org.opendaylight.controller.config.manager.testingservices.seviceinterfac
 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
+import org.osgi.framework.BundleContext;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 public class TestingFixedThreadPoolModuleFactory implements ModuleFactory {
     public static final String NAME = "fixed";
@@ -34,14 +35,14 @@ public class TestingFixedThreadPoolModuleFactory implements ModuleFactory {
 
     @Override
     public TestingFixedThreadPoolModule createModule(String instanceName,
-            DependencyResolver dependencyResolver) {
+            DependencyResolver dependencyResolver, BundleContext bundleContext) {
         return new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME,
                 instanceName), null, null);
     }
 
     @Override
     public Module createModule(String instanceName,
-            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old)
+            DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext)
             throws Exception {
         int threadCount = (Integer) old.getAttribute("ThreadCount");
         // is the instance compatible?
@@ -67,7 +68,7 @@ public class TestingFixedThreadPoolModuleFactory implements ModuleFactory {
     }
 
     @Override
-    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory) {
+    public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) {
         return new HashSet<Module>();
     }
 }
index 451ac3e..9abc8cc 100644 (file)
@@ -95,7 +95,8 @@
                             com.google.common.base,
                             com.google.common.collect,
                             org.apache.commons.lang3,
-                            org.slf4j
+                            org.slf4j,
+                            org.osgi.framework
                         </Import-Package>
                         <Export-Package>
                             org.opendaylight.controller.config.yang.logback.config,
index 732161d..fb183fc 100644 (file)
@@ -8,14 +8,6 @@
  */
 package org.opendaylight.controller.config.yang.logback.config;
 
-import java.util.*;
-import java.util.Map.Entry;
-
-import org.apache.commons.lang3.StringUtils;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.slf4j.LoggerFactory;
-
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
@@ -25,9 +17,16 @@ import ch.qos.logback.core.Appender;
 import ch.qos.logback.core.rolling.FixedWindowRollingPolicy;
 import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy;
 import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
-
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.osgi.framework.BundleContext;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.util.Map.Entry;
 
 /**
 *
@@ -42,7 +41,8 @@ public class LogbackModuleFactory extends
     private Map<String, FileAppenderTO> fileDTOs;
 
     @Override
-    public LogbackModule instantiateModule(String instanceName, DependencyResolver dependencyResolver) {
+    public LogbackModule instantiateModule(String instanceName,
+            DependencyResolver dependencyResolver, BundleContext bundleContext) {
         Preconditions.checkArgument(instanceName.equals(INSTANCE_NAME),
                 "There should be just one instance of logback, named " + INSTANCE_NAME);
         prepareDTOs();
@@ -56,8 +56,9 @@ public class LogbackModuleFactory extends
     }
 
     @Override
-    public LogbackModule instantiateModule(String instanceName, DependencyResolver dependencyResolver,
-            LogbackModule oldModule, AutoCloseable oldInstance) {
+    public LogbackModule instantiateModule(String instanceName,
+            DependencyResolver dependencyResolver, LogbackModule oldModule,
+            AutoCloseable oldInstance, BundleContext bundleContext) {
         Preconditions.checkArgument(instanceName.equals(INSTANCE_NAME),
                 "There should be just one instance of logback, named " + INSTANCE_NAME);
         prepareDTOs();
index b9245a4..47b68eb 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
 
-import java.util.Collections;
-import java.util.List;
-
+import com.google.common.collect.Lists;
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
@@ -20,8 +18,10 @@ import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Cons
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition;
+import org.osgi.framework.BundleContext;
 
-import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
 
 /**
  *
@@ -83,6 +83,10 @@ public class AbstractFactoryTemplate extends GeneralClassTemplate {
         return DynamicMBeanWithInstance.class.getCanonicalName();
     }
 
+    public String getBundleContextType() {
+        return BundleContext.class.getCanonicalName();
+    }
+
     @Override
     public String getFtlTempleteLocation() {
         return "factory_abs_template.ftl";
index 5fd1496..00f2581 100644 (file)
@@ -21,19 +21,19 @@ package ${packageName};
     }
 
     @Override
-    public ${moduleType} createModule(String instanceName, ${dependencyResolverType} dependencyResolver) {
-        return instantiateModule(instanceName, dependencyResolver);
+    public ${moduleType} createModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${bundleContextType} bundleContext) {
+        return instantiateModule(instanceName, dependencyResolver, bundleContext);
     }
 
     @Override
-    public ${moduleType} createModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${dynamicMBeanWithInstanceType} old) throws Exception {
+    public ${moduleType} createModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${dynamicMBeanWithInstanceType} old, ${bundleContextType} bundleContext) throws Exception {
         ${moduleInstanceType} oldModule = null;
         try {
             oldModule = (${moduleInstanceType}) old.getModule();
         } catch(Exception e) {
             return handleChangedClass(old);
         }
-        ${moduleInstanceType} module = instantiateModule(instanceName, dependencyResolver, oldModule, old.getInstance());
+        ${moduleInstanceType} module = instantiateModule(instanceName, dependencyResolver, oldModule, old.getInstance(), bundleContext);
 
         <#list fields as attr>
         module.set${attr.name}(oldModule.get${attr.name}());
@@ -42,11 +42,11 @@ package ${packageName};
         return module;
     }
 
-    public ${moduleInstanceType} instantiateModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${moduleInstanceType} oldModule, ${instanceType} oldInstance) {
+    public ${moduleInstanceType} instantiateModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${moduleInstanceType} oldModule, ${instanceType} oldInstance, ${bundleContextType} bundleContext) {
         return new ${moduleInstanceType}(new ${moduleNameType}(NAME, instanceName), dependencyResolver, oldModule, oldInstance);
     }
 
-    public ${moduleInstanceType} instantiateModule(String instanceName, ${dependencyResolverType} dependencyResolver) {
+    public ${moduleInstanceType} instantiateModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${bundleContextType} bundleContext) {
         return new ${moduleInstanceType}(new ${moduleNameType}(NAME, instanceName), dependencyResolver);
     }
 
@@ -61,7 +61,7 @@ package ${packageName};
     }
 
     @Override
-    public java.util.Set<${moduleInstanceType}> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory) {
+    public java.util.Set<${moduleInstanceType}> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory, ${bundleContextType} bundleContext) {
         return new java.util.HashSet<${moduleInstanceType}>();
     }
 
index d4e6a22..b3b5b50 100644 (file)
@@ -7,42 +7,17 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin;
 
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.matchers.JUnitMatchers.containsString;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.*;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.io.Files;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.compiler.IProblem;
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTParser;
-import org.eclipse.jdt.core.dom.ASTVisitor;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.FieldDeclaration;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.NormalAnnotation;
-import org.eclipse.jdt.core.dom.PackageDeclaration;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.*;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.api.annotations.Description;
@@ -58,11 +33,19 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.io.Files;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.*;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.containsString;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
 
 public class JMXGeneratorTest extends AbstractGeneratorTest {
 
@@ -469,14 +452,13 @@ public class JMXGeneratorTest extends AbstractGeneratorTest {
 
         assertEquals(2, fieldDeclarations.size());
 
-
         Set<String> expectedMethods = new HashSet<>(Arrays.asList("String getImplementationName()",
-                "org.opendaylight.controller.config.spi.Module createModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver)",
-                "org.opendaylight.controller.config.spi.Module createModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,org.opendaylight.controller.config.api.DynamicMBeanWithInstance old)",
+                "org.opendaylight.controller.config.spi.Module createModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,org.osgi.framework.BundleContext bundleContext)",
+                "org.opendaylight.controller.config.spi.Module createModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,org.opendaylight.controller.config.api.DynamicMBeanWithInstance old,org.osgi.framework.BundleContext bundleContext)",
                 "org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule handleChangedClass(org.opendaylight.controller.config.api.DynamicMBeanWithInstance old)",
-                "org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule instantiateModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule oldModule,java.lang.AutoCloseable oldInstance)",
-                "org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule instantiateModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver)",
-                "java.util.Set<org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory)",
+                "org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule instantiateModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule oldModule,java.lang.AutoCloseable oldInstance,org.osgi.framework.BundleContext bundleContext)",
+                "org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule instantiateModule(String instanceName,org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,org.osgi.framework.BundleContext bundleContext)",
+                "java.util.Set<org.opendaylight.controller.config.threads.java.NamingThreadFactoryModule> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory,org.osgi.framework.BundleContext bundleContext)",
                 "boolean isModuleImplementingServiceInterface(Class<? extends org.opendaylight.controller.config.api.annotations.AbstractServiceInterface> serviceInterface)"));
         assertEquals("Incorrenct number of generated methods", expectedMethods, visitor.methods);
         assertEquals("Incorrenct number of generated method descriptions", 0,