From 35620f5ccf1ed4d1e4ac78a97fff3c1fede8ad95 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 13 Aug 2013 18:15:17 +0200 Subject: [PATCH] Added sample provider and consumer for MD SAL Signed-off-by: Tony Tkacik Change-Id: I8293baab178623762b6ce9e1e2ecb582e78d7f4e --- opendaylight/sal/yang-prototype/sal/pom.xml | 1 + .../sal/yang-prototype/sal/samples/pom.xml | 18 ++ .../sal/samples/toaster-consumer/pom.xml | 40 ++++ .../toaster/provider/api/ToastConsumer.java | 16 ++ .../provider/impl/ToastConsumerImpl.java | 98 +++++++++ .../sal/samples/toaster-it/pom.xml | 132 +++++++++++++ .../sample/toaster/it/ToasterTest.java | 84 ++++++++ .../sal/samples/toaster-provider/pom.xml | 44 +++++ .../toaster/provider/OpendaylightToaster.java | 118 +++++++++++ .../toaster/provider/ToasterActivator.java | 5 + .../toaster/provider/ToasterProvider.java | 71 +++++++ .../sal/samples/toaster/pom.xml | 117 +++++++++++ .../toaster/src/main/yang/toaster.yang | 187 ++++++++++++++++++ 13 files changed, 931 insertions(+) create mode 100644 opendaylight/sal/yang-prototype/sal/samples/pom.xml create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml create mode 100644 opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang diff --git a/opendaylight/sal/yang-prototype/sal/pom.xml b/opendaylight/sal/yang-prototype/sal/pom.xml index b2ae8d921a..a3d95bdf30 100644 --- a/opendaylight/sal/yang-prototype/sal/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/pom.xml @@ -12,6 +12,7 @@ sal-data-api sal-binding-api sal-binding-broker-impl + samples diff --git a/opendaylight/sal/yang-prototype/sal/samples/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/pom.xml new file mode 100644 index 0000000000..dc06185b28 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/pom.xml @@ -0,0 +1,18 @@ + + 4.0.0 + + sal-parent + 1.0-SNAPSHOT + org.opendaylight.controller + + pom + sal-samples + + toaster + toaster-consumer + toaster-it + toaster-provider + + org.opendaylight.controller.samples + 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 index 0000000000..914accde3b --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + + sal-samples + org.opendaylight.controller.samples + 1.0-SNAPSHOT + + sample-toaster-consumer + bundle + + + + + org.apache.felix + maven-bundle-plugin + + + org.opendaylight.controller.sample.toaster.provider.api + org.opendaylight.controller.sample.toaster.provider.impl + org.opendaylight.controller.sample.toaster.provider.impl.ToastConsumerImpl + + + + + + + + + ${project.groupId} + sample-toaster + ${project.version} + + + org.opendaylight.controller + sal-binding-api + 1.0-SNAPSHOT + + + 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 index 0000000000..b236c0e333 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java @@ -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 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 index 0000000000..71ef68d565 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java @@ -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 { + + private static final Logger log = LoggerFactory.getLogger(ToastConsumerImpl.class); + + private ToasterService toaster; + + private ConsumerContext session; + + @Override + public boolean createToast(Class type, int doneness) { + MakeToastInputBuilder toastInput = new MakeToastInputBuilder(); + toastInput.setToasterDoneness((long) doneness); + toastInput.setToasterToastType(type); + + try { + RpcResult 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 brokerRef = context.getServiceReference(BindingAwareBroker.class); + BindingAwareBroker broker = context.getService(brokerRef); + broker.registerConsumer(this, context); + Dictionary 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 index 0000000000..edce9a02d4 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml @@ -0,0 +1,132 @@ + + 4.0.0 + + sal-samples + org.opendaylight.controller.samples + 1.0-SNAPSHOT + + sample-toaster-it + + + 3.0.0 + 1.5.0 + + + + + + org.ops4j.pax.exam + maven-paxexam-plugin + + + generate-config + + generate-depends-file + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.ops4j.pax.exam + + + maven-paxexam-plugin + + + [1.2.4,) + + + + generate-depends-file + + + + + + + + + + + + + + + + + + org.opendaylight.controller.samples + sample-toaster + 1.0-SNAPSHOT + + + org.opendaylight.controller.samples + sample-toaster-consumer + 1.0-SNAPSHOT + + + org.opendaylight.controller.samples + sample-toaster-provider + 1.0-SNAPSHOT + + + org.opendaylight.controller + sal-binding-broker-impl + 1.0-SNAPSHOT + + + org.ops4j.pax.exam + pax-exam-container-native + ${exam.version} + test + + + org.ops4j.pax.exam + pax-exam-junit4 + ${exam.version} + test + + + org.ops4j.pax.exam + pax-exam-link-mvn + ${exam.version} + test + + + equinoxSDK381 + org.eclipse.osgi + 3.8.1.v20120830-144521 + test + + + org.slf4j + log4j-over-slf4j + 1.7.2 + + + ch.qos.logback + logback-core + 1.0.9 + + + ch.qos.logback + logback-classic + 1.0.9 + + + 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 index 0000000000..663e81a18e --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java @@ -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> 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 index 0000000000..49d142c79b --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + sal-samples + org.opendaylight.controller.samples + 1.0-SNAPSHOT + + sample-toaster-provider + bundle + + + + + + org.apache.felix + maven-bundle-plugin + + + org.opendaylight.controller.sample.toaster.provider.ToasterProvider + + + + + + + + + ${project.groupId} + sample-toaster + ${project.version} + + + org.opendaylight.controller + sal-binding-api + 1.0-SNAPSHOT + + + org.opendaylight.controller + sal-common-util + 1.0-SNAPSHOT + + + 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 index 0000000000..404734b96c --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java @@ -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> 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> cancelToast() { + if (currentTask != null) { + cancelToastImpl(); + } + return null; + } + + @Override + public Future> 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> inProgressError() { + RpcResult result = Rpcs. getRpcResult(false, null, Collections. 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> { + + final MakeToastInput toastRequest; + + public MakeToastTask(MakeToastInput toast) { + toastRequest = toast; + } + + @Override + public RpcResult 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. getRpcResult(true, null, Collections. 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 index 0000000000..010023a6eb --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java @@ -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 index 0000000000..08ac1494c6 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java @@ -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 getImplementations() { + return Collections.emptySet(); + } + + @Override + public Collection getFunctionality() { + return Collections.emptySet(); + } + + @Override + public void start(BundleContext context) throws Exception { + ServiceReference 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 index 0000000000..d434275f0f --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml @@ -0,0 +1,117 @@ + + 4.0.0 + + sal-samples + org.opendaylight.controller.samples + 1.0-SNAPSHOT + + sample-toaster + bundle + + + + + org.opendaylight.yangtools + yang-maven-plugin + 0.5.7-SNAPSHOT + + + + generate-sources + + + src/main/yang + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + + + target/generated-sources/sal + + + + false + + + + + + + org.opendaylight.yangtools + maven-sal-api-gen-plugin + 0.5.7-SNAPSHOT + jar + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.7 + + + generate-sources + + add-source + + + + target/generated-sources/sal + + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.opendaylight.yangtools + + + yang-maven-plugin + + + [0.5,) + + + + generate-sources + + + + + + + + + + + + + + + + + org.opendaylight.yangtools + yang-binding + + + org.opendaylight.yangtools + yang-common + + + 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 index 0000000000..fc9b6656c0 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang @@ -0,0 +1,187 @@ +module toaster { + + yang-version 1; + + namespace + "http://netconfcentral.org/ns/toaster"; + + prefix toast; + + organization "Netconf Central"; + + contact + "Andy Bierman "; + + 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 -- 2.36.6