Add registerToOsgi flag to ServiceInterfaceAnnotation 13/36713/17
authorTom Pantelis <tpanteli@brocade.com>
Mon, 28 Mar 2016 17:41:36 +0000 (13:41 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 14 Apr 2016 11:02:58 +0000 (11:02 +0000)
Added a flag to the ServiceInterfaceAnnotation to allow disabling OSGi
service registration. This is needed for blueprint bundles that have
already registered the service and also need to create the module
and service in the config system for compatibility support.

Change-Id: Ic12d2cdcf6de77ee043a708c76502f8bc36a4717
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/annotations/ServiceInterfaceAnnotation.java
opendaylight/config/config-api/src/main/yang/config.yang
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Annotation.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ConfigConstants.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntry.java

index e66de46..23a01a7 100644 (file)
@@ -36,6 +36,11 @@ public @interface ServiceInterfaceAnnotation {
      */
     Class<?> osgiRegistrationType();
 
+    /**
+     * Determines whether or not the service instance should be registered with OSGi.
+     */
+    boolean registerToOsgi() default true;
+
     /**
      * Get namespace of {@link #value()}
      */
index e46d327..3d06dd6 100644 (file)
@@ -29,6 +29,12 @@ module config {
         argument "name";
     }
 
+    extension disable-osgi-service-registration {
+        description
+            "YANG language extension that can be associated with a Service identity that
+            disables advertising the service instances to the OSGi registry.";
+    }
+
     extension required-identity {
         description
             "YANG language extension which indicates that a particular
index 67475da..3d93a9d 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.config.manager.impl.osgi;
 
 import static com.google.common.base.Preconditions.checkState;
-
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -72,7 +71,14 @@ public class BeanToOsgiServiceManager {
                                                                 Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
             Set<ServiceRegistration<?>> serviceRegistrations = new HashSet<>();
             for (Entry<ServiceInterfaceAnnotation, String /* service ref name */> entry : serviceNamesToAnnotations.entrySet()) {
-                Class<?> requiredInterface = entry.getKey().osgiRegistrationType();
+                ServiceInterfaceAnnotation annotation = entry.getKey();
+                Class<?> requiredInterface = annotation.osgiRegistrationType();
+
+                if(!annotation.registerToOsgi()) {
+                    LOG.debug("registerToOsgi for service interface {} is false - not registering", requiredInterface);
+                    continue;
+                }
+
                 checkState(requiredInterface.isInstance(instance), instance.getClass().getName() +
                         " instance should implement " + requiredInterface.getName());
                 Dictionary<String, String> propertiesForOsgi = createProps(entry.getValue());
index ae5f947..8f00f90 100644 (file)
@@ -73,7 +73,7 @@ public class Annotation {
         {
             List<Parameter> params = Lists.newArrayList(new Parameter("value", q(sie.getQName().toString())));
             params.add(new Parameter("osgiRegistrationType", exportedClassName + ".class"));
-
+            params.add(new Parameter("registerToOsgi", Boolean.toString(sie.isRegisterToOsgi())));
             params.add(new Parameter("namespace", q(sie.getQName().getNamespace().toString())));
             params.add(new Parameter("revision", q(sie.getQName().getFormattedRevision())));
             params.add(new Parameter("localName", q(sie.getQName().getLocalName())));
index e585eb2..1700062 100644 (file)
@@ -30,6 +30,7 @@ public final class ConfigConstants {
     public static final QName SERVICE_TYPE_Q_NAME = createConfigQName("service-type");
     public static final QName MODULE_TYPE_Q_NAME = createConfigQName("module-type");
     public static final QName JAVA_CLASS_EXTENSION_QNAME = createConfigQName("java-class");
+    public static final QName DISABLE_OSGI_SERVICE_REG_QNAME = createConfigQName("disable-osgi-service-registration");
     public static final QName REQUIRED_IDENTITY_EXTENSION_QNAME = createConfigQName("required-identity");
     public static final QName INNER_STATE_BEAN_EXTENSION_QNAME = createConfigQName("inner-state-bean");
     public static final QName PROVIDED_SERVICE_EXTENSION_QNAME = createConfigQName("provided-service");
index f03bd96..2c853e1 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.config.yangjmxgenerator;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static java.lang.String.format;
 import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.SERVICE_TYPE_Q_NAME;
-
 import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -56,6 +55,7 @@ public class ServiceInterfaceEntry extends AbstractEntry {
     private final QName qName;
     private final String nullableDescription, packageName, typeName;
     private final QName yangModuleQName;
+    private final boolean registerToOsgi;
 
     private ServiceInterfaceEntry(IdentitySchemaNode id, String packageName, QName yangModuleQName) {
         this(Optional.<ServiceInterfaceEntry> absent(), id, packageName, yangModuleQName);
@@ -68,11 +68,14 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         List<UnknownSchemaNode> unknownSchemaNodes = id.getUnknownSchemaNodes();
         List<String> exportedOsgiClassNames = new ArrayList<>(
                 unknownSchemaNodes.size());
+
+        boolean disableOsgiServiceRegistration = false;
         for (UnknownSchemaNode usn : unknownSchemaNodes) {
-            if (ConfigConstants.JAVA_CLASS_EXTENSION_QNAME.equals(usn
-                    .getNodeType())) {
+            if (ConfigConstants.JAVA_CLASS_EXTENSION_QNAME.equals(usn.getNodeType())) {
                 String localName = usn.getNodeParameter();
                 exportedOsgiClassNames.add(localName);
+            } else if (ConfigConstants.DISABLE_OSGI_SERVICE_REG_QNAME.equals(usn.getNodeType())) {
+                disableOsgiServiceRegistration = true;
             } else {
                 throw new IllegalStateException(format(
                         "Unexpected unknown schema node. Expected %s, got %s",
@@ -87,6 +90,8 @@ public class ServiceInterfaceEntry extends AbstractEntry {
                             getClass(),
                             ConfigConstants.JAVA_CLASS_EXTENSION_QNAME, id));
         }
+
+        this.registerToOsgi = !disableOsgiServiceRegistration;
         this.exportedOsgiClassName = exportedOsgiClassNames.get(0);
         qName = id.getQName();
         nullableDescription = id.getDescription();
@@ -116,6 +121,10 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         return qName;
     }
 
+    public boolean isRegisterToOsgi() {
+        return registerToOsgi;
+    }
+
     /**
      * @return Map of QNames as keys and ServiceInterfaceEntry instances as
      *         values

©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.