From 44b5dbe52783a3a558b3eae619b01baf613f82e0 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Sun, 6 Mar 2016 20:46:38 -0500 Subject: [PATCH] Add blueprint wiring to the toaster sample Change-Id: I79922dd24847fd8682a0f2133e6effae9b608a0c Signed-off-by: Tom Pantelis --- .../resources/initial/03-toaster-sample.xml | 12 ++--- .../kitchen/impl/KitchenServiceImpl.java | 25 +++++----- .../blueprint/toaster-consumer.xml | 25 ++++++++++ .../src/main/yang/kitchen-service-impl.yang | 3 +- .../impl/ToasterProviderModule.java | 9 ---- .../toaster/provider/OpendaylightToaster.java | 25 +++++++--- .../blueprint/toaster-provider.xml | 46 +++++++++++++++++++ .../src/main/yang/toaster-provider-impl.yang | 3 +- .../provider/OpenDaylightToasterTest.java | 9 ++-- 9 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 opendaylight/md-sal/samples/toaster-consumer/src/main/resources/org/opendaylight/blueprint/toaster-consumer.xml create mode 100644 opendaylight/md-sal/samples/toaster-provider/src/main/resources/org/opendaylight/blueprint/toaster-provider.xml diff --git a/opendaylight/md-sal/samples/toaster-config/src/main/resources/initial/03-toaster-sample.xml b/opendaylight/md-sal/samples/toaster-config/src/main/resources/initial/03-toaster-sample.xml index 2e8c7d5ce6..df07caa067 100644 --- a/opendaylight/md-sal/samples/toaster-config/src/main/resources/initial/03-toaster-sample.xml +++ b/opendaylight/md-sal/samples/toaster-config/src/main/resources/initial/03-toaster-sample.xml @@ -28,10 +28,10 @@ - - binding:binding-notification-service + + binding:binding-new-notification-publish-service - binding-notification-broker + binding-notification-publish-adapter @@ -47,10 +47,10 @@ - - binding:binding-notification-service + + binding:binding-new-notification-service - binding-notification-broker + binding-notification-adapter diff --git a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java index 3ea7b45f02..563b45ab77 100644 --- a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java +++ b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java @@ -8,13 +8,21 @@ package org.opendaylight.controller.sample.kitchen.impl; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.common.util.concurrent.AsyncFunction; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.JdkFutureAdapters; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; - import org.opendaylight.controller.config.yang.config.kitchen_service.impl.KitchenServiceRuntimeMXBean; +import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; import org.opendaylight.controller.sample.kitchen.api.EggsType; import org.opendaylight.controller.sample.kitchen.api.KitchenService; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput; @@ -26,22 +34,14 @@ import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread; import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; +import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.common.util.concurrent.AsyncFunction; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.JdkFutureAdapters; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; - -public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener { +public class KitchenServiceImpl extends AbstractMXBean + implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener { private static final Logger log = LoggerFactory.getLogger( KitchenServiceImpl.class ); @@ -53,6 +53,7 @@ public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntime private volatile boolean toasterOutOfBread; public KitchenServiceImpl(ToasterService toaster) { + super("KitchenService", "toaster-consumer", null); this.toaster = toaster; } diff --git a/opendaylight/md-sal/samples/toaster-consumer/src/main/resources/org/opendaylight/blueprint/toaster-consumer.xml b/opendaylight/md-sal/samples/toaster-consumer/src/main/resources/org/opendaylight/blueprint/toaster-consumer.xml new file mode 100644 index 0000000000..6b9bf35463 --- /dev/null +++ b/opendaylight/md-sal/samples/toaster-consumer/src/main/resources/org/opendaylight/blueprint/toaster-consumer.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/opendaylight/md-sal/samples/toaster-consumer/src/main/yang/kitchen-service-impl.yang b/opendaylight/md-sal/samples/toaster-consumer/src/main/yang/kitchen-service-impl.yang index d22dfc619a..fd25878949 100644 --- a/opendaylight/md-sal/samples/toaster-consumer/src/main/yang/kitchen-service-impl.yang +++ b/opendaylight/md-sal/samples/toaster-consumer/src/main/yang/kitchen-service-impl.yang @@ -9,6 +9,7 @@ module kitchen-service-impl { import rpc-context { prefix rpcx; revision-date 2013-06-17; } import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } + import opendaylight-sal-binding-broker-impl { prefix binding-impl; revision-date 2013-10-28; } description "This module contains the base YANG definitions for @@ -49,7 +50,7 @@ module kitchen-service-impl { uses config:service-ref { refine type { mandatory true; - config:required-identity mdsal:binding-notification-service; + config:required-identity binding-impl:binding-new-notification-service; } } } diff --git a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/config/yang/config/toaster_provider/impl/ToasterProviderModule.java b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/config/yang/config/toaster_provider/impl/ToasterProviderModule.java index 97e0a6bcf7..47c5692564 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/config/yang/config/toaster_provider/impl/ToasterProviderModule.java +++ b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/config/yang/config/toaster_provider/impl/ToasterProviderModule.java @@ -18,13 +18,9 @@ package org.opendaylight.controller.config.yang.config.toaster_provider.impl; import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sample.toaster.provider.OpendaylightToaster; -import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.Toaster; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService; -import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,10 +60,6 @@ public final class ToasterProviderModule extends DataBroker dataBrokerService = getDataBrokerDependency(); opendaylightToaster.setDataProvider(dataBrokerService); - final ListenerRegistration dataTreeChangeListenerRegistration = dataBrokerService - .registerDataTreeChangeListener(new DataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, - OpendaylightToaster.TOASTER_IID), opendaylightToaster); - final BindingAwareBroker.RpcRegistration rpcRegistration = getRpcRegistryDependency() .addRpcImplementation(ToasterService.class, opendaylightToaster); @@ -81,7 +73,6 @@ public final class ToasterProviderModule extends @Override public void close() throws Exception { - dataTreeChangeListenerRegistration.close(); rpcRegistration.close(); runtimeReg.close(); closeQuietly(opendaylightToaster); diff --git a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java index e39ac2baff..ef2bfb6904 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java +++ b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java @@ -26,13 +26,15 @@ import org.opendaylight.controller.config.yang.config.toaster_provider.impl.Toas import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; 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.common.api.data.OptimisticLockFailedException; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.RestockToasterInput; @@ -43,6 +45,7 @@ import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestocked; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestockedBuilder; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; @@ -51,7 +54,7 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class OpendaylightToaster implements ToasterService, ToasterProviderRuntimeMXBean, +public class OpendaylightToaster extends AbstractMXBean implements ToasterService, ToasterProviderRuntimeMXBean, DataTreeChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(OpendaylightToaster.class); @@ -61,8 +64,9 @@ public class OpendaylightToaster implements ToasterService, ToasterProviderRunti private static final DisplayString TOASTER_MANUFACTURER = new DisplayString("Opendaylight"); private static final DisplayString TOASTER_MODEL_NUMBER = new DisplayString("Model 1 - Binding Aware"); - private NotificationProviderService notificationProvider; + private NotificationPublishService notificationProvider; private DataBroker dataProvider; + private ListenerRegistration dataTreeChangeListenerRegistration; private final ExecutorService executor; @@ -78,15 +82,20 @@ public class OpendaylightToaster implements ToasterService, ToasterProviderRunti private final AtomicLong darknessFactor = new AtomicLong( 1000 ); public OpendaylightToaster() { + super("OpendaylightToaster", "toaster-provider", null); executor = Executors.newFixedThreadPool(1); } - public void setNotificationProvider(final NotificationProviderService salService) { - this.notificationProvider = salService; + public void setNotificationProvider(final NotificationPublishService notificationPublishService) { + this.notificationProvider = notificationPublishService; } public void setDataProvider(final DataBroker salDataProvider) { this.dataProvider = salDataProvider; + + dataProvider.registerDataTreeChangeListener(new DataTreeIdentifier( + LogicalDatastoreType.CONFIGURATION, OpendaylightToaster.TOASTER_IID), this); + setToasterStatusUp( null ); } @@ -99,6 +108,8 @@ public class OpendaylightToaster implements ToasterService, ToasterProviderRunti executor.shutdown(); if (dataProvider != null) { + dataTreeChangeListenerRegistration.close(); + WriteTransaction tx = dataProvider.newWriteOnlyTransaction(); tx.delete(LogicalDatastoreType.OPERATIONAL,TOASTER_IID); Futures.addCallback( tx.submit(), new FutureCallback() { @@ -297,7 +308,7 @@ public class OpendaylightToaster implements ToasterService, ToasterProviderRunti if( amountOfBreadInStock.get() > 0 ) { ToasterRestocked reStockedNotification = new ToasterRestockedBuilder() .setAmountOfBread( input.getAmountOfBreadToStock() ).build(); - notificationProvider.publish( reStockedNotification ); + notificationProvider.offerNotification( reStockedNotification ); } return Futures.immediateFuture( RpcResultBuilder. success().build() ); @@ -383,7 +394,7 @@ public class OpendaylightToaster implements ToasterService, ToasterProviderRunti if( outOfBread() ) { LOG.info( "Toaster is out of bread!" ); - notificationProvider.publish( new ToasterOutOfBreadBuilder().build() ); + notificationProvider.offerNotification( new ToasterOutOfBreadBuilder().build() ); } // Set the Toaster status back to up - this essentially releases the toasting lock. diff --git a/opendaylight/md-sal/samples/toaster-provider/src/main/resources/org/opendaylight/blueprint/toaster-provider.xml b/opendaylight/md-sal/samples/toaster-provider/src/main/resources/org/opendaylight/blueprint/toaster-provider.xml new file mode 100644 index 0000000000..01cb3132f1 --- /dev/null +++ b/opendaylight/md-sal/samples/toaster-provider/src/main/resources/org/opendaylight/blueprint/toaster-provider.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/opendaylight/md-sal/samples/toaster-provider/src/main/yang/toaster-provider-impl.yang b/opendaylight/md-sal/samples/toaster-provider/src/main/yang/toaster-provider-impl.yang index 8de0c98c63..f978e49b47 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/main/yang/toaster-provider-impl.yang +++ b/opendaylight/md-sal/samples/toaster-provider/src/main/yang/toaster-provider-impl.yang @@ -8,6 +8,7 @@ module toaster-provider-impl { import config { prefix config; revision-date 2013-04-05; } import rpc-context { prefix rpcx; revision-date 2013-06-17; } import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } + import opendaylight-sal-binding-broker-impl { prefix binding-impl; revision-date 2013-10-28; } description "This module contains the base YANG definitions for @@ -44,7 +45,7 @@ module toaster-provider-impl { uses config:service-ref { refine type { mandatory true; - config:required-identity mdsal:binding-notification-service; + config:required-identity binding-impl:binding-new-notification-publish-service; } } } diff --git a/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java b/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java index 287b012425..b189e461cc 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java +++ b/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java @@ -13,16 +13,15 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; - +import com.google.common.base.Optional; import java.util.concurrent.Future; - import org.junit.Ignore; import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder; @@ -31,8 +30,6 @@ import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; -import com.google.common.base.Optional; - public class OpenDaylightToasterTest extends AbstractDataBrokerTest{ private static InstanceIdentifier TOASTER_IID = @@ -48,7 +45,7 @@ public class OpenDaylightToasterTest extends AbstractDataBrokerTest{ * Doesn't look like we have support for the NotificationProviderService yet, so mock it * for now. */ - NotificationProviderService mockNotification = mock( NotificationProviderService.class ); + NotificationPublishService mockNotification = mock( NotificationPublishService.class ); toaster.setNotificationProvider( mockNotification ); } -- 2.36.6