Added sample provider and consumer for MD SAL 64/864/3
authorTony Tkacik <ttkacik@cisco.com>
Tue, 13 Aug 2013 16:15:17 +0000 (18:15 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 14 Aug 2013 12:01:38 +0000 (14:01 +0200)
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
Change-Id: I8293baab178623762b6ce9e1e2ecb582e78d7f4e

13 files changed:
opendaylight/sal/yang-prototype/sal/pom.xml
opendaylight/sal/yang-prototype/sal/samples/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang [new file with mode: 0644]

index b2ae8d9..a3d95bd 100644 (file)
@@ -12,6 +12,7 @@
                <module>sal-data-api</module>
                <module>sal-binding-api</module>
                <module>sal-binding-broker-impl</module>
+        <module>samples</module>
        </modules>
 
        <properties>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/pom.xml
new file mode 100644 (file)
index 0000000..dc06185
--- /dev/null
@@ -0,0 +1,18 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-parent</artifactId>
+               <version>1.0-SNAPSHOT</version>
+               <groupId>org.opendaylight.controller</groupId>
+       </parent>
+       <packaging>pom</packaging>
+       <artifactId>sal-samples</artifactId>
+       <modules>
+               <module>toaster</module>
+               <module>toaster-consumer</module>
+               <module>toaster-it</module>
+               <module>toaster-provider</module>
+       </modules>
+       <groupId>org.opendaylight.controller.samples</groupId>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml
new file mode 100644 (file)
index 0000000..914accd
--- /dev/null
@@ -0,0 +1,40 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-samples</artifactId>
+               <groupId>org.opendaylight.controller.samples</groupId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>sample-toaster-consumer</artifactId>
+       <packaging>bundle</packaging>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                               <Export-Package>org.opendaylight.controller.sample.toaster.provider.api</Export-Package>
+                                               <Private-Package>org.opendaylight.controller.sample.toaster.provider.impl</Private-Package>
+                                               <Bundle-Activator>org.opendaylight.controller.sample.toaster.provider.impl.ToastConsumerImpl</Bundle-Activator>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>sample-toaster</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-binding-api</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java
new file mode 100644 (file)
index 0000000..b236c0e
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2013 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.sample.toaster.provider.api;
+
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastType;
+
+public interface ToastConsumer {
+       
+       boolean createToast(Class<? extends ToastType> type,int doneness);
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java
new file mode 100644 (file)
index 0000000..71ef68d
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2013 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.sample.toaster.provider.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.ExecutionException;
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.controller.sal.binding.api.NotificationService;
+import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.MakeToastInputBuilder;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastDone;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastType;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ToastConsumerImpl implements BundleActivator, BindingAwareConsumer, ToastConsumer,
+        NotificationListener<ToastDone> {
+
+    private static final Logger log = LoggerFactory.getLogger(ToastConsumerImpl.class);
+
+    private ToasterService toaster;
+
+    private ConsumerContext session;
+
+    @Override
+    public boolean createToast(Class<? extends ToastType> type, int doneness) {
+        MakeToastInputBuilder toastInput = new MakeToastInputBuilder();
+        toastInput.setToasterDoneness((long) doneness);
+        toastInput.setToasterToastType(type);
+
+        try {
+            RpcResult<Void> result = getToastService().makeToast(toastInput.build()).get();
+
+            if (result.isSuccessful()) {
+                log.info("Toast was successfuly finished");
+            } else {
+                log.info("Toast was not successfuly finished");
+            }
+            return result.isSuccessful();
+        } catch (InterruptedException | ExecutionException e) {
+            log.info("Error occured during toast creation");
+        }
+        return false;
+
+    }
+
+    @Override
+    public void onSessionInitialized(ConsumerContext session) {
+        this.session = session;
+        NotificationService notificationService = session.getSALService(NotificationService.class);
+        notificationService.addNotificationListener(ToastDone.class, this);
+
+    }
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        ServiceReference<BindingAwareBroker> brokerRef = context.getServiceReference(BindingAwareBroker.class);
+        BindingAwareBroker broker = context.getService(brokerRef);
+        broker.registerConsumer(this, context);
+        Dictionary<String, String> properties = new Hashtable<>();
+        context.registerService(ToastConsumer.class, this, properties);
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onNotification(ToastDone notification) {
+        log.info("ToastDone Notification Received: {} ",notification.getToastStatus());
+
+    }
+
+    private ToasterService getToastService() {
+        if (toaster == null) {
+            toaster = session.getRpcService(ToasterService.class);
+        }
+        return toaster;
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml
new file mode 100644 (file)
index 0000000..edce9a0
--- /dev/null
@@ -0,0 +1,132 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-samples</artifactId>
+               <groupId>org.opendaylight.controller.samples</groupId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>sample-toaster-it</artifactId>
+
+       <properties>
+               <exam.version>3.0.0</exam.version>
+               <url.version>1.5.0</url.version>
+       </properties>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.ops4j.pax.exam</groupId>
+                               <artifactId>maven-paxexam-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <id>generate-config</id>
+                                               <goals>
+                                                       <goal>generate-depends-file</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+               <pluginManagement>
+                       <plugins>
+                               <!--This plugin's configuration is used to store Eclipse m2e settings 
+                                       only. It has no influence on the Maven build itself. -->
+                               <plugin>
+                                       <groupId>org.eclipse.m2e</groupId>
+                                       <artifactId>lifecycle-mapping</artifactId>
+                                       <version>1.0.0</version>
+                                       <configuration>
+                                               <lifecycleMappingMetadata>
+                                                       <pluginExecutions>
+                                                               <pluginExecution>
+                                                                       <pluginExecutionFilter>
+                                                                               <groupId>
+                                                                                       org.ops4j.pax.exam
+                                                                               </groupId>
+                                                                               <artifactId>
+                                                                                       maven-paxexam-plugin
+                                                                               </artifactId>
+                                                                               <versionRange>
+                                                                                       [1.2.4,)
+                                                                               </versionRange>
+                                                                               <goals>
+                                                                                       <goal>
+                                                                                               generate-depends-file
+                                                                                       </goal>
+                                                                               </goals>
+                                                                       </pluginExecutionFilter>
+                                                                       <action>
+                                                                               <ignore></ignore>
+                                                                       </action>
+                                                               </pluginExecution>
+                                                       </pluginExecutions>
+                                               </lifecycleMappingMetadata>
+                                       </configuration>
+                               </plugin>
+                       </plugins>
+               </pluginManagement>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.opendaylight.controller.samples</groupId>
+                       <artifactId>sample-toaster</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller.samples</groupId>
+                       <artifactId>sample-toaster-consumer</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller.samples</groupId>
+                       <artifactId>sample-toaster-provider</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-binding-broker-impl</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-container-native</artifactId>
+                       <version>${exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-junit4</artifactId>
+                       <version>${exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-link-mvn</artifactId>
+                       <version>${exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>equinoxSDK381</groupId>
+                       <artifactId>org.eclipse.osgi</artifactId>
+                       <version>3.8.1.v20120830-144521</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>log4j-over-slf4j</artifactId>
+                       <version>1.7.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>ch.qos.logback</groupId>
+                       <artifactId>logback-core</artifactId>
+                       <version>1.0.9</version>
+               </dependency>
+               <dependency>
+                       <groupId>ch.qos.logback</groupId>
+                       <artifactId>logback-classic</artifactId>
+                       <version>1.0.9</version>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java
new file mode 100644 (file)
index 0000000..663e81a
--- /dev/null
@@ -0,0 +1,84 @@
+package org.opendaylight.controller.sample.toaster.it;
+
+import static org.junit.Assert.*;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemPackages;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+
+import java.util.Collection;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sample.toaster.provider.ToasterProvider;
+import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.WhiteBread;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+@RunWith(PaxExam.class)
+public class ToasterTest {
+
+       public static final String ODL = "org.opendaylight.controller";
+       public static final String YANG = "org.opendaylight.yangtools";
+       public static final String SAMPLE = "org.opendaylight.controller.samples";
+
+       @Test
+       public void properInitialized() throws Exception {
+
+               Collection<ServiceReference<ToasterService>> references = ctx
+                               .getServiceReferences(ToasterService.class, null);
+               assertEquals(2, references.size());
+               
+               consumer.createToast(WhiteBread.class, 5);
+               
+       }
+
+       @Inject
+       BindingAwareBroker broker;
+
+       @Inject
+       ToastConsumer consumer;
+
+       @Inject
+       BundleContext ctx;
+
+       @Configuration
+       public Option[] config() {
+               return options(systemProperty("osgi.console").value("2401"),
+                               mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
+                               mavenBundle("org.slf4j", "log4j-over-slf4j")
+                                               .versionAsInProject(),
+                               mavenBundle("ch.qos.logback", "logback-core")
+                                               .versionAsInProject(),
+                               mavenBundle("ch.qos.logback", "logback-classic")
+                                               .versionAsInProject(),
+                               mavenBundle(ODL, "sal-binding-api").versionAsInProject(),
+                               mavenBundle(ODL, "sal-binding-broker-impl")
+                                               .versionAsInProject(), mavenBundle(ODL, "sal-common")
+                                               .versionAsInProject(),
+                               mavenBundle(ODL, "sal-common-util").versionAsInProject(),
+                               mavenBundle(SAMPLE, "sample-toaster").versionAsInProject(),
+                               mavenBundle(SAMPLE, "sample-toaster-consumer")
+                                               .versionAsInProject(),
+                               mavenBundle(SAMPLE, "sample-toaster-provider")
+                                               .versionAsInProject(),
+                               mavenBundle(YANG, "yang-binding").versionAsInProject(),
+                               mavenBundle(YANG, "yang-common").versionAsInProject(),
+                               mavenBundle("com.google.guava", "guava").versionAsInProject(),
+                               junitBundles(), mavenBundle("org.javassist", "javassist")
+                                               .versionAsInProject());
+       }
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml
new file mode 100644 (file)
index 0000000..49d142c
--- /dev/null
@@ -0,0 +1,44 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-samples</artifactId>
+               <groupId>org.opendaylight.controller.samples</groupId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>sample-toaster-provider</artifactId>
+       <packaging>bundle</packaging>
+
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                       <Bundle-Activator>org.opendaylight.controller.sample.toaster.provider.ToasterProvider</Bundle-Activator>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>sample-toaster</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-binding-api</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-common-util</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java
new file mode 100644 (file)
index 0000000..404734b
--- /dev/null
@@ -0,0 +1,118 @@
+package org.opendaylight.controller.sample.toaster.provider;
+
+import java.util.Collections;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.common.util.Futures;
+import org.opendaylight.controller.sal.common.util.Rpcs;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.DisplayString;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.MakeToastInput;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastDone.ToastStatus;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastDoneBuilder;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.Toaster;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.Toaster.ToasterStatus;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterBuilder;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterData;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpendaylightToaster implements ToasterData, ToasterService {
+
+    private static final Logger log = LoggerFactory.getLogger(OpendaylightToaster.class);
+
+    private static final DisplayString toasterManufacturer = new DisplayString("Opendaylight");
+    private static final DisplayString toasterModelNumber = new DisplayString("Model 1 - Binding Aware");
+    private ToasterStatus toasterStatus;
+
+    private NotificationProviderService notificationProvider;
+    private final ExecutorService executor;
+
+    private Future<RpcResult<Void>> currentTask;
+
+    public OpendaylightToaster() {
+        toasterStatus = ToasterStatus.Down;
+        executor = Executors.newFixedThreadPool(1);
+    }
+
+    @Override
+    public Toaster getToaster() {
+        ToasterBuilder tb = new ToasterBuilder();
+        tb //
+        .setToasterManufacturer(toasterManufacturer) //
+                .setToasterModelNumber(toasterModelNumber) //
+                .setToasterStatus(toasterStatus);
+
+        return tb.build();
+    }
+
+    @Override
+    public Future<RpcResult<Void>> cancelToast() {
+        if (currentTask != null) {
+            cancelToastImpl();
+        }
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> makeToast(MakeToastInput input) {
+        // TODO Auto-generated method stub
+        log.info("makeToast - Received input for toast");
+        logToastInput(input);
+        if (currentTask != null) {
+            return inProgressError();
+        }
+        currentTask = executor.submit(new MakeToastTask(input));
+        return currentTask;
+    }
+
+    private Future<RpcResult<Void>> inProgressError() {
+        RpcResult<Void> result = Rpcs.<Void> getRpcResult(false, null, Collections.<RpcError> emptySet());
+        return Futures.immediateFuture(result);
+    }
+
+    private void cancelToastImpl() {
+        currentTask.cancel(true);
+        ToastDoneBuilder toastDone = new ToastDoneBuilder();
+        toastDone.setToastStatus(ToastStatus.Cancelled);
+        notificationProvider.notify(toastDone.build());
+    }
+
+    public void setNotificationProvider(NotificationProviderService salService) {
+        this.notificationProvider = salService;
+    }
+
+    private void logToastInput(MakeToastInput input) {
+        String toastType = input.getToasterToastType().getName();
+        String toastDoneness = input.getToasterDoneness().toString();
+        log.info("Toast: {} doneness: {}", toastType, toastDoneness);
+    }
+
+    private class MakeToastTask implements Callable<RpcResult<Void>> {
+
+        final MakeToastInput toastRequest;
+
+        public MakeToastTask(MakeToastInput toast) {
+            toastRequest = toast;
+        }
+
+        @Override
+        public RpcResult<Void> call() throws Exception {
+            Thread.sleep(1000);
+
+            ToastDoneBuilder notifyBuilder = new ToastDoneBuilder();
+            notifyBuilder.setToastStatus(ToastStatus.Done);
+            notificationProvider.notify(notifyBuilder.build());
+            log.info("Toast Done");
+            logToastInput(toastRequest);
+            return Rpcs.<Void> getRpcResult(true, null, Collections.<RpcError> emptySet());
+        }
+    }
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java
new file mode 100644 (file)
index 0000000..010023a
--- /dev/null
@@ -0,0 +1,5 @@
+package org.opendaylight.controller.sample.toaster.provider;
+
+public class ToasterActivator {
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java
new file mode 100644 (file)
index 0000000..08ac149
--- /dev/null
@@ -0,0 +1,71 @@
+package org.opendaylight.controller.sample.toaster.provider;
+import java.util.Collection;
+import java.util.Collections;
+
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ToasterProvider implements BindingAwareProvider, BundleActivator {
+    private static final Logger log = LoggerFactory.getLogger(ToasterProvider.class);
+
+       private ConsumerContext consumerContext;
+       private ProviderContext providerContext;
+       private OpendaylightToaster toaster;
+       
+       
+       public ToasterProvider() {
+               toaster = new OpendaylightToaster();
+       }
+       
+       @Override
+       public void onSessionInitialized(ConsumerContext session) {
+               log.info("Consumer Session initialized");
+               this.consumerContext = session;
+
+       }
+
+       @Override
+       public void onSessionInitiated(ProviderContext session) {
+               log.info("Provider Session initialized");
+               
+               this.providerContext = session;
+               toaster.setNotificationProvider(session.getSALService(NotificationProviderService.class));
+               providerContext.addRpcImplementation(ToasterService.class, toaster);
+       }       
+       
+       
+       @Override
+       public Collection<? extends RpcService> getImplementations() {
+               return Collections.emptySet();
+       }
+
+       @Override
+       public Collection<? extends ProviderFunctionality> getFunctionality() {
+               return Collections.emptySet();
+       }
+
+       @Override
+       public void start(BundleContext context) throws Exception {
+               ServiceReference<BindingAwareBroker> brokerRef = context.getServiceReference(BindingAwareBroker.class);
+               BindingAwareBroker broker = context.getService(brokerRef);
+               broker.registerProvider(this, context);
+       }
+
+       @Override
+       public void stop(BundleContext context) throws Exception {
+               
+               
+       }
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml
new file mode 100644 (file)
index 0000000..d434275
--- /dev/null
@@ -0,0 +1,117 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>sal-samples</artifactId>
+        <groupId>org.opendaylight.controller.samples</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>sample-toaster</artifactId>
+    <packaging>bundle</packaging>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+                <version>0.5.7-SNAPSHOT</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate-sources</goal>
+                        </goals>
+                        <configuration>
+                            <yangFilesRootDir>src/main/yang</yangFilesRootDir>
+                            <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>
+                                        target/generated-sources/sal
+                                    </outputBaseDir>
+                                </generator>
+                            </codeGenerators>
+                            <inspectDependencies>false</inspectDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+
+                <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.5.7-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
+                </dependencies>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.7</version>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/sal</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+        <pluginManagement>
+            <plugins>
+                <!--This plugin's configuration is used to store Eclipse 
+                    m2e settings only. It has no influence on the Maven build itself. -->
+                <plugin>
+                    <groupId>org.eclipse.m2e</groupId>
+                    <artifactId>lifecycle-mapping</artifactId>
+                    <version>1.0.0</version>
+                    <configuration>
+                        <lifecycleMappingMetadata>
+                            <pluginExecutions>
+                                <pluginExecution>
+                                    <pluginExecutionFilter>
+                                        <groupId>
+                                            org.opendaylight.yangtools
+                                        </groupId>
+                                        <artifactId>
+                                            yang-maven-plugin
+                                        </artifactId>
+                                        <versionRange>
+                                            [0.5,)
+                                        </versionRange>
+                                        <goals>
+                                            <goal>
+                                                generate-sources
+                                            </goal>
+                                        </goals>
+                                    </pluginExecutionFilter>
+                                    <action>
+                                        <ignore></ignore>
+                                    </action>
+                                </pluginExecution>
+                            </pluginExecutions>
+                        </lifecycleMappingMetadata>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-binding</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang b/opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang
new file mode 100644 (file)
index 0000000..fc9b665
--- /dev/null
@@ -0,0 +1,187 @@
+module toaster {
+
+    yang-version 1;
+
+    namespace
+      "http://netconfcentral.org/ns/toaster";
+
+    prefix toast;
+
+    organization "Netconf Central";
+
+    contact
+      "Andy Bierman <andy@netconfcentral.org>";
+
+    description
+      "YANG version of the TOASTER-MIB.";
+
+    revision "2009-11-20" {
+      description
+        "Toaster module in progress.";
+    }
+
+
+    identity toast-type {
+      description
+          "Base for all bread types supported by the toaster.
+           New bread types not listed here nay be added in the 
+           future.";
+    }
+
+    identity white-bread {
+      base toast:toast-type;
+      description "White bread.";
+    }
+
+    identity wheat-bread {
+      base toast-type;
+      description "Wheat bread.";
+    }
+
+    identity wonder-bread {
+      base toast-type;
+      description "Wonder bread.";
+    }
+
+    identity frozen-waffle {
+      base toast-type;
+      description "Frozen waffle.";
+    }
+
+    identity frozen-bagel {
+      base toast-type;
+      description "Frozen bagel.";
+    }
+
+    identity hash-brown {
+      base toast-type;
+      description "Hash browned potatos.";
+    }
+
+    typedef DisplayString {
+      type string;
+      description
+        "YANG version of the SMIv2 DisplayString TEXTUAL-CONVENTION.";
+      reference
+        "RFC 2579, section 2.";
+
+    }
+
+    container toaster {
+      presence
+        "Indicates the toaster service is available";
+      description
+        "Top-level container for all toaster database objects.";
+      leaf toasterManufacturer {
+        type DisplayString;
+        config false;
+        mandatory true;
+        description
+          "The name of the toaster's manufacturer. For instance, 
+                Microsoft Toaster.";
+      }
+
+      leaf toasterModelNumber {
+        type DisplayString;
+        config false;
+        mandatory true;
+        description
+          "The name of the toaster's model. For instance,
+               Radiant Automatic.";
+      }
+
+      leaf toasterStatus {
+        type enumeration {
+          enum "up" {
+            value 1;
+            description
+              "The toaster knob position is up.
+                      No toast is being made now.";
+          }
+          enum "down" {
+            value 2;
+            description
+              "The toaster knob position is down.
+                      Toast is being made now.";
+          }
+        }
+        config false;
+        mandatory true;
+        description
+          "This variable indicates the current state of 
+               the toaster.";
+      }
+    }  // container toaster
+
+    rpc make-toast {
+      description
+        "Make some toast.
+           The toastDone notification will be sent when 
+           the toast is finished.
+           An 'in-use' error will be returned if toast
+           is already being made.
+           A 'resource-denied' error will be returned 
+           if the toaster service is disabled.";
+      input {
+        leaf toasterDoneness {
+          type uint32 {
+            range "1 .. 10";
+          }
+          default '5';
+          description
+            "This variable controls how well-done is the 
+                   ensuing toast. It should be on a scale of 1 to 10.
+                   Toast made at 10 generally is considered unfit 
+                   for human consumption; toast made at 1 is warmed 
+                   lightly.";
+        }
+
+        leaf toasterToastType {
+          type identityref {
+            base toast:toast-type;
+          }
+          default 'wheat-bread';
+          description
+            "This variable informs the toaster of the type of 
+                   material that is being toasted. The toaster 
+                   uses this information, combined with 
+                   toasterDoneness, to compute for how 
+                   long the material must be toasted to achieve 
+                   the required doneness.";
+        }
+      }
+    }  // rpc make-toast
+
+    rpc cancel-toast {
+      description
+        "Stop making toast, if any is being made.
+           A 'resource-denied' error will be returned 
+           if the toaster service is disabled.";
+    }  // rpc cancel-toast
+
+    notification toastDone {
+      description
+        "Indicates that the toast in progress has completed.";
+      leaf toastStatus {
+        type enumeration {
+          enum "done" {
+            value 0;
+            description "The toast is done.";
+          }
+          enum "cancelled" {
+            value 1;
+            description
+              "The toast was cancelled.";
+          }
+          enum "error" {
+            value 2;
+            description
+              "The toaster service was disabled or
+                     the toaster is broken.";
+          }
+        }
+        description
+          "Indicates the final toast status";
+      }
+    }  // notification toastDone
+  }  // module toaster