Convert message-bus to blueprint 09/59109/2
authorTom Pantelis <tompantelis@gmail.com>
Fri, 16 Jun 2017 20:40:53 +0000 (16:40 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 17 Jun 2017 13:41:50 +0000 (09:41 -0400)
Change-Id: I2dcabedf8a5fa05ca7433573c4d1957884154161
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/messagebus-config/src/main/resources/initial/05-message-bus.xml
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModule.java
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactory.java
opendaylight/md-sal/messagebus-impl/src/main/resources/org/opendaylight/blueprint/messagebus.xml [new file with mode: 0644]
opendaylight/md-sal/messagebus-impl/src/main/yang/messagebus-app-impl.yang
opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactoryTest.java [deleted file]
opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleTest.java [deleted file]
opendaylight/md-sal/messagebus-spi/src/main/yang/messagebus-event-source-registry.yang

index 3e00d93..e3bd8e5 100644 (file)
               <module>
                   <name>messagebus-app-impl</name>
                   <type xmlns:binding-impl="urn:opendaylight:params:xml:ns:yang:controller:messagebus:app:impl">binding-impl:messagebus-app-impl</type>
-                  <binding-broker xmlns="urn:opendaylight:params:xml:ns:yang:controller:messagebus:app:impl">
-                      <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">prefix:binding-broker-osgi-registry</type>
-                      <name>binding-osgi-broker</name>
-                  </binding-broker>
               </module>
           </modules>
           <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
index 9f9d737..b870e14 100644 (file)
@@ -9,16 +9,16 @@ package org.opendaylight.controller.config.yang.messagebus.app.impl;
 
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology;
-import org.opendaylight.controller.messagebus.app.util.Providers;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
+import org.opendaylight.controller.messagebus.spi.EventSource;
+import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
+import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class MessageBusAppImplModule extends org.opendaylight.controller.config.yang.messagebus.app.impl.AbstractMessageBusAppImplModule {
+@Deprecated
+public class MessageBusAppImplModule extends AbstractMessageBusAppImplModule {
     private static final Logger LOG = LoggerFactory.getLogger(MessageBusAppImplModule.class);
 
     private BundleContext bundleContext;
@@ -40,18 +40,24 @@ public class MessageBusAppImplModule extends org.opendaylight.controller.config.
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
-    @Override
-    protected void customValidation() {
-    }
-
     @Override
     public java.lang.AutoCloseable createInstance() {
-        final ProviderContext bindingCtx = getBindingBrokerDependency().registerProvider(new Providers.BindingAware());
-        final DataBroker dataBroker = bindingCtx.getSALService(DataBroker.class);
-        final RpcProviderRegistry rpcRegistry = bindingCtx.getSALService(RpcProviderRegistry.class);
-        final EventSourceTopology eventSourceTopology = new EventSourceTopology(dataBroker, rpcRegistry);
-        LOG.info("Messagebus initialized");
-        return eventSourceTopology;
+        final WaitingServiceTracker<EventSourceRegistry> tracker =
+                WaitingServiceTracker.create(EventSourceRegistry.class, bundleContext);
+        final EventSourceRegistry service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+
+        return new EventSourceRegistry() {
+            @Override
+            public void close() {
+                // We need to close the WaitingServiceTracker however we don't want to close the actual
+                // service instance because its life-cycle is controlled via blueprint.
+                tracker.close();
+            }
+
+            @Override
+            public <T extends EventSource> EventSourceRegistration<T> registerEventSource(T eventSource) {
+                return service.registerEventSource(eventSource);
+            }
+        };
     }
-
 }
index 92ec080..3359bbe 100644 (file)
@@ -22,7 +22,8 @@ import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
 import org.opendaylight.controller.config.spi.Module;
 import org.osgi.framework.BundleContext;
 
-public class MessageBusAppImplModuleFactory extends org.opendaylight.controller.config.yang.messagebus.app.impl.AbstractMessageBusAppImplModuleFactory {
+@Deprecated
+public class MessageBusAppImplModuleFactory extends AbstractMessageBusAppImplModuleFactory {
     @Override
     public Module createModule(String instanceName,
                                DependencyResolver dependencyResolver,
diff --git a/opendaylight/md-sal/messagebus-impl/src/main/resources/org/opendaylight/blueprint/messagebus.xml b/opendaylight/md-sal/messagebus-impl/src/main/resources/org/opendaylight/blueprint/messagebus.xml
new file mode 100644 (file)
index 0000000..b24d648
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017 Inocybe Technologies Inc. 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
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+           odl:use-default-for-reference-types="true">
+
+  <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+  <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
+
+  <bean id="eventSourceTopology" class="org.opendaylight.controller.messagebus.app.impl.EventSourceTopology"
+          destroy-method="close">
+    <argument ref="dataBroker"/>
+    <argument ref="rpcRegistry"/>
+  </bean>
+
+  <service ref="eventSourceTopology"
+          interface="org.opendaylight.controller.messagebus.spi.EventSourceRegistry"/>
+</blueprint>
index 01c1ba2..ac897b3 100644 (file)
@@ -16,6 +16,7 @@ module messagebus-app-impl {
     }
 
     identity messagebus-app-impl {
+        status deprecated;
         base config:module-type;
         config:provided-service esr:event-source-registry;
         config:java-name-prefix MessageBusAppImpl;
@@ -28,7 +29,7 @@ module messagebus-app-impl {
             container binding-broker {
                 uses config:service-ref {
                     refine type {
-                        mandatory true;
+                        mandatory false;
                         config:required-identity sal:binding-broker-osgi-registry;
                     }
                 }
@@ -37,4 +38,4 @@ module messagebus-app-impl {
         }
     }
 
-}
\ No newline at end of file
+}
diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactoryTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactoryTest.java
deleted file mode 100644 (file)
index d06a1a8..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.messagebus.app.impl;
-
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.osgi.framework.BundleContext;
-
-public class MessageBusAppImplModuleFactoryTest {
-
-    DependencyResolver dependencyResolverMock;
-    BundleContext bundleContextMock;
-    MessageBusAppImplModuleFactory messageBusAppImplModuleFactory;
-    DynamicMBeanWithInstance dynamicMBeanWithInstanceMock;
-
-    @BeforeClass
-    public static void initTestClass() throws IllegalAccessException, InstantiationException {
-    }
-
-    @Before
-    public void setUp() throws Exception {
-        dependencyResolverMock = mock(DependencyResolver.class);
-        bundleContextMock = mock(BundleContext.class);
-        dynamicMBeanWithInstanceMock = mock(DynamicMBeanWithInstance.class);
-        messageBusAppImplModuleFactory = new MessageBusAppImplModuleFactory();
-    }
-
-    @Test
-    public void createModuleTest() {
-        assertNotNull("Module has not been created correctly.", messageBusAppImplModuleFactory.createModule("instanceName1", dependencyResolverMock, bundleContextMock));
-    }
-
-    @Test
-    public void createModuleBTest() throws Exception{
-        MessageBusAppImplModule messageBusAppImplModuleMock = mock(MessageBusAppImplModule.class);
-        doReturn(messageBusAppImplModuleMock).when(dynamicMBeanWithInstanceMock).getModule();
-        assertNotNull("Module has not been created correctly.", messageBusAppImplModuleFactory.createModule("instanceName1", dependencyResolverMock, dynamicMBeanWithInstanceMock, bundleContextMock));
-    }
-
-}
\ No newline at end of file
diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleTest.java
deleted file mode 100644 (file)
index fe5e60b..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.messagebus.app.impl;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.JmxAttribute;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.MountPointService;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.controller.sal.core.api.Broker;
-import org.opendaylight.controller.sal.core.api.Provider;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.osgi.framework.BundleContext;
-
-import com.google.common.util.concurrent.CheckedFuture;
-
-import javax.management.ObjectName;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-public class MessageBusAppImplModuleTest {
-
-    MessageBusAppImplModule messageBusAppImplModule;
-    ModuleIdentifier moduleIdentifier;
-    DependencyResolver dependencyResolverMock;
-
-    @BeforeClass
-    public static void initTestClass() throws IllegalAccessException, InstantiationException {
-    }
-
-    @Before
-    public void setUp() throws Exception {
-        moduleIdentifier = new ModuleIdentifier("factoryName1", "instanceName1");
-        dependencyResolverMock = mock(DependencyResolver.class);
-        messageBusAppImplModule = new MessageBusAppImplModule(moduleIdentifier, dependencyResolverMock);
-    }
-
-    @Test
-    public void constructorTest() {
-        assertNotNull("Instance has not been created correctly.", messageBusAppImplModule);
-    }
-
-    @Test
-    public void constructorBTest() {
-        MessageBusAppImplModule messageBusAppImplModuleOld = mock(MessageBusAppImplModule.class);
-        java.lang.AutoCloseable oldInstanceAutocloseableMock = mock(AutoCloseable.class);
-        MessageBusAppImplModule messageBusAppImplModule = new MessageBusAppImplModule(moduleIdentifier, dependencyResolverMock, messageBusAppImplModuleOld, oldInstanceAutocloseableMock);
-        assertNotNull("Instance has not been created correctly.", messageBusAppImplModule);
-    }
-
-    @Test
-    public void setGetBundleContextTest() {
-        BundleContext bundleContext = mock(BundleContext.class);
-        messageBusAppImplModule.setBundleContext(bundleContext);
-        assertEquals("Set and/or get method/s don't work correctly.", bundleContext, messageBusAppImplModule.getBundleContext());
-    }
-
-    @Test
-    public void createInstanceTest() throws Exception{
-        org.opendaylight.controller.sal.binding.api.BindingAwareBroker bindingAwareBrokerMock = mock(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class);
-        Broker brokerMock = mock(Broker.class);
-        doReturn(brokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class));
-        doReturn(bindingAwareBrokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class));
-        messageBusAppImplModule.resolveDependencies();
-
-        BindingAwareBroker.ProviderContext providerContext = mock(BindingAwareBroker.ProviderContext.class);
-        doReturn(providerContext).when(bindingAwareBrokerMock).registerProvider(any(BindingAwareProvider.class));
-        Broker.ProviderSession providerSessionMock = mock(Broker.ProviderSession.class);
-        doReturn(providerSessionMock).when(brokerMock).registerProvider(any(Provider.class));
-        DataBroker dataBrokerMock = mock(DataBroker.class);
-        doReturn(dataBrokerMock).when(providerContext).getSALService(eq(DataBroker.class));
-        DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class);
-        doReturn(domNotificationPublishServiceMock).when(providerSessionMock).getService(DOMNotificationPublishService.class);
-        DOMMountPointService domMountPointServiceMock = mock(DOMMountPointService.class);
-        doReturn(domMountPointServiceMock).when(providerSessionMock).getService(DOMMountPointService.class);
-        MountPointService mountPointServiceMock = mock(MountPointService.class);
-        doReturn(mountPointServiceMock).when(providerContext).getSALService(eq(MountPointService.class));
-        RpcProviderRegistry rpcProviderRegistryMock = mock(RpcProviderRegistry.class);
-        doReturn(rpcProviderRegistryMock).when(providerContext).getSALService(eq(RpcProviderRegistry.class));
-
-        WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
-        doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
-        doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
-        CheckedFuture checkedFutureMock = mock(CheckedFuture.class);
-        doReturn(checkedFutureMock).when(writeTransactionMock).submit();
-        assertNotNull("EventSourceRegistryWrapper has not been created correctly.", messageBusAppImplModule.createInstance());
-    }
-
-}
\ No newline at end of file
index 4c5a47c..4843326 100644 (file)
@@ -14,8 +14,10 @@ module messagebus-event-source-registry {
          }
 
      identity event-source-registry {
+             status deprecated;
              base "config:service-type";
              config:java-class "org.opendaylight.controller.messagebus.spi.EventSourceRegistry";
+             config:disable-osgi-service-registration;
      }
 
 }

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