Add clustered-app-config blueprint extension example to the toaster 35/38435/5
authorTom Pantelis <tpanteli@brocade.com>
Wed, 4 May 2016 09:41:23 +0000 (05:41 -0400)
committerAnil Vishnoi <vishnoianil@gmail.com>
Thu, 12 May 2016 21:24:11 +0000 (21:24 +0000)
Added a toaster-app-config yang to utilize the clustered-app-config
blueprint extension as an example. The operational toaster's
manufacturer and model number were made configurable.

Change-Id: Ie4793ecf49ef42d07c6ca9fbce806533ca49aefd
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java
opendaylight/md-sal/samples/toaster-provider/src/main/resources/org/opendaylight/blueprint/toaster-provider.xml
opendaylight/md-sal/samples/toaster-provider/src/main/yang/toaster-app-config.yang [new file with mode: 0644]

index ef2bfb690454c4c411c6a19f4006e8957fe67e62..ff3117a2e19681c3642df1a8f5921570ff36194c 100644 (file)
@@ -45,6 +45,8 @@ 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.toaster.app.config.rev160503.ToasterAppConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.toaster.app.config.rev160503.ToasterAppConfigBuilder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -81,9 +83,17 @@ public class OpendaylightToaster extends AbstractMXBean implements ToasterServic
     // Thread safe holder for our darkness multiplier.
     private final AtomicLong darknessFactor = new AtomicLong( 1000 );
 
+    private final ToasterAppConfig toasterAppConfig;
+
     public OpendaylightToaster() {
+        this(new ToasterAppConfigBuilder().setManufacturer(TOASTER_MANUFACTURER).setModelNumber(TOASTER_MODEL_NUMBER).
+                setMaxMakeToastTries(2).build());
+    }
+
+    public OpendaylightToaster(ToasterAppConfig toasterAppConfig) {
         super("OpendaylightToaster", "toaster-provider", null);
         executor = Executors.newFixedThreadPool(1);
+        this.toasterAppConfig = toasterAppConfig;
     }
 
     public void setNotificationProvider(final NotificationPublishService notificationPublishService) {
@@ -131,8 +141,8 @@ public class OpendaylightToaster extends AbstractMXBean implements ToasterServic
         // note - we are simulating a device whose manufacture and model are
         // fixed (embedded) into the hardware.
         // This is why the manufacture and model number are hardcoded.
-        return new ToasterBuilder().setToasterManufacturer( TOASTER_MANUFACTURER )
-                                   .setToasterModelNumber( TOASTER_MODEL_NUMBER )
+        return new ToasterBuilder().setToasterManufacturer( toasterAppConfig.getManufacturer() )
+                                   .setToasterModelNumber( toasterAppConfig.getModelNumber() )
                                    .setToasterStatus( status )
                                    .build();
     }
@@ -186,7 +196,7 @@ public class OpendaylightToaster extends AbstractMXBean implements ToasterServic
 
         final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
 
-        checkStatusAndMakeToast( input, futureResult, 2 );
+        checkStatusAndMakeToast( input, futureResult, toasterAppConfig.getMaxMakeToastTries() );
 
         return futureResult;
     }
index 01cb3132f174ed3953318a09b682eb94ba24b0b5..4a2be5d256a328bfcada788c9a49b71ef90f9934 100644 (file)
     </cm:default-properties>
   </cm:property-placeholder>
 
+  <!-- "clustered-app-config" is an ODL extension that obtains an application configuration yang container
+       from the MD-SAL data store and makes the binding DataObject available as a bean that can be injected
+       into other beans. Here we obtain the ToasterAppConfig container DataObject. This also shows how to
+       specify default data via the "default-config" child element. While default leaf values defined in the
+       yang are returned, one may have more complex data, eg lists, that require default data. The
+       "default-config" must contain the XML representation of the yang data, including namespace, wrapped
+       in a CDATA section to prevent the blueprint container from treating it as markup.
+  -->
+  <odl:clustered-app-config id="toasterAppConfig"
+      binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.toaster.app.config.rev160503.ToasterAppConfig">
+    <odl:default-config><![CDATA[
+      <toaster-app-config xmlns="urn:opendaylight:params:xml:ns:yang:controller:toaster-app-config">
+        <max-make-toast-tries>3</max-make-toast-tries>
+      </toaster-app-config>
+    ]]></odl:default-config>
+  </odl:clustered-app-config>
+
   <!-- Import MD-SAL services. For the DataBroker, we explicitly specify the odl:type which is configurable
        via the cfg file. In this manner the toaster can be configured to use the default clustered DataBroker
        or the specialized "pingpong" DataBroker (or any other DataBroker implementation).
@@ -35,6 +52,7 @@
   <!-- Create the OpendaylightToaster instance and inject its dependencies -->
   <bean id="toaster" class="org.opendaylight.controller.sample.toaster.provider.OpendaylightToaster"
           init-method="register" destroy-method="unregister">
+    <argument ref="toasterAppConfig"/>
     <property name="dataProvider" ref="dataBroker"/>
     <property name="notificationProvider" ref="notificationService"/>
   </bean>
diff --git a/opendaylight/md-sal/samples/toaster-provider/src/main/yang/toaster-app-config.yang b/opendaylight/md-sal/samples/toaster-provider/src/main/yang/toaster-app-config.yang
new file mode 100644 (file)
index 0000000..369ba46
--- /dev/null
@@ -0,0 +1,33 @@
+module toaster-app-config {
+    yang-version 1;
+
+    namespace "urn:opendaylight:params:xml:ns:yang:controller:toaster-app-config";
+    prefix toaster-app-config;
+
+    import toaster { prefix toaster; revision-date 2009-11-20; }
+
+    description
+      "Configuration for the Opendaylight toaster application.";
+
+    revision "2016-05-03" {
+        description
+            "Initial revision.";
+    }
+
+    container toaster-app-config {
+        leaf manufacturer {
+            type toaster:DisplayString;
+            default "Opendaylight";
+        }
+
+        leaf model-number {
+            type toaster:DisplayString;
+            default "Model 1 - Binding Aware";
+        }
+
+        leaf max-make-toast-tries {
+            type uint16;
+            default 2;
+        }
+    }
+}
\ No newline at end of file