From f6d37df70a6cf38c118767763e13d3f94257d450 Mon Sep 17 00:00:00 2001 From: Basheeruddin Ahmed Date: Thu, 11 Sep 2014 14:04:42 -0700 Subject: [PATCH] Bug 1826: moving clustering test application from integration branch to controller This test application is used by robo test cases for clustering patch 4: fixed the overwrite of wrong groupId fix in patch 2 Patch 3: Basheeruddin just included module-shards.conf and modules.conf for clustering test app Change-Id: Iac47e986e36662b1f61e711a194a8c72c8c76a29 Signed-off-by: Harman Singh Signed-off-by: Basheeruddin Ahmed --- features/mdsal/pom.xml | 17 +++ .../mdsal/src/main/resources/features.xml | 11 ++ .../clustering-test-app/configuration/pom.xml | 55 ++++++++ .../initial/20-clustering-test-app.xml | 47 +++++++ .../main/resources/initial/module-shards.conf | 117 ++++++++++++++++++ .../src/main/resources/initial/modules.conf | 47 +++++++ .../samples/clustering-test-app/model/pom.xml | 115 +++++++++++++++++ .../model/src/main/yang/car-people.yang | 42 +++++++ .../model/src/main/yang/car-purchase.yang | 60 +++++++++ .../model/src/main/yang/car.yang | 64 ++++++++++ .../model/src/main/yang/people.yang | 80 ++++++++++++ .../samples/clustering-test-app/pom.xml | 16 +++ .../clustering-test-app/provider/pom.xml | 102 +++++++++++++++ .../it/listener/PeopleCarListener.java | 70 +++++++++++ .../it/provider/PeopleProvider.java | 91 ++++++++++++++ .../it/provider/PurchaseCarProvider.java | 52 ++++++++ .../ClusteringItProviderModule.java | 84 +++++++++++++ .../ClusteringItProviderModuleFactory.java | 13 ++ .../src/main/yang/clustering-it-provider.yang | 60 +++++++++ opendaylight/md-sal/samples/pom.xml | 1 + 20 files changed, 1144 insertions(+) create mode 100644 opendaylight/md-sal/samples/clustering-test-app/configuration/pom.xml create mode 100644 opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/20-clustering-test-app.xml create mode 100644 opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/module-shards.conf create mode 100644 opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/modules.conf create mode 100644 opendaylight/md-sal/samples/clustering-test-app/model/pom.xml create mode 100644 opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-people.yang create mode 100644 opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-purchase.yang create mode 100644 opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car.yang create mode 100644 opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/people.yang create mode 100644 opendaylight/md-sal/samples/clustering-test-app/pom.xml create mode 100644 opendaylight/md-sal/samples/clustering-test-app/provider/pom.xml create mode 100644 opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/listener/PeopleCarListener.java create mode 100644 opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PeopleProvider.java create mode 100644 opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PurchaseCarProvider.java create mode 100644 opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModule.java create mode 100644 opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModuleFactory.java create mode 100644 opendaylight/md-sal/samples/clustering-test-app/provider/src/main/yang/clustering-it-provider.yang diff --git a/features/mdsal/pom.xml b/features/mdsal/pom.xml index 9b81f81ae4..960dfb37a1 100644 --- a/features/mdsal/pom.xml +++ b/features/mdsal/pom.xml @@ -242,6 +242,23 @@ xml config + + org.opendaylight.controller.samples + clustering-it-model + ${mdsal.version} + + + org.opendaylight.controller.samples + clustering-it-provider + ${mdsal.version} + + + org.opendaylight.controller.samples + clustering-it-config + ${mdsal.version} + xml + config + org.opendaylight.controller sal-rest-docgen diff --git a/features/mdsal/src/main/resources/features.xml b/features/mdsal/src/main/resources/features.xml index c336635df4..da246b63e3 100644 --- a/features/mdsal/src/main/resources/features.xml +++ b/features/mdsal/src/main/resources/features.xml @@ -108,4 +108,15 @@ mvn:org.opendaylight.controller/sal-clustering-config/${project.version}/xml/moduleshardconf mvn:org.opendaylight.controller/sal-clustering-config/${project.version}/xml/moduleconf + + + odl-mdsal-clustering + odl-restconf + odl-yangtools-models + mvn:org.opendaylight.controller.samples/clustering-it-model/${project.version} + mvn:org.opendaylight.controller.samples/clustering-it-provider/${project.version} + mvn:org.opendaylight.controller.samples/clustering-it-config/${project.version}/xml/config + mvn:org.opendaylight.controller.samples/clustering-it-config/${project.version}/xml/testmoduleshardconf + mvn:org.opendaylight.controller.samples/clustering-it-config/${project.version}/xml/testmoduleconf + diff --git a/opendaylight/md-sal/samples/clustering-test-app/configuration/pom.xml b/opendaylight/md-sal/samples/clustering-test-app/configuration/pom.xml new file mode 100644 index 0000000000..8d4bbbd64c --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/configuration/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + clustering-it + org.opendaylight.controller.samples + 1.1-SNAPSHOT + + clustering-it-config + jar + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/initial/20-clustering-test-app.xml + xml + config + + + ${project.build.directory}/classes/initial/module-shards.conf + xml + testmoduleshardconf + + + ${project.build.directory}/classes/initial/modules.conf + xml + testmoduleconf + + + + + + + + + diff --git a/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/20-clustering-test-app.xml b/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/20-clustering-test-app.xml new file mode 100644 index 0000000000..f01970908c --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/20-clustering-test-app.xml @@ -0,0 +1,47 @@ + + + + + + + + + + prefix:clustering-it-provider + + clustering-it-provider + + + binding:binding-rpc-registry + binding-rpc-broker + + + binding:binding-async-data-broker + binding-data-broker + + + + binding:binding-notification-service + + binding-notification-broker + + + + + + + + + urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 + urn:opendaylight:params:xml:ns:yang:controller:config:clustering-it-provider?module=clustering-it-provider&revision=2014-08-19 + + + + + diff --git a/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/module-shards.conf b/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/module-shards.conf new file mode 100644 index 0000000000..59b0be1bce --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/module-shards.conf @@ -0,0 +1,117 @@ +# This file describes which shards live on which members +# The format for a module-shards is as follows, +# { +# name = "" +# shards = [ +# { +# name="" +# replicas = [ +# "" +# ] +# ] +# } +# +# For Helium we support only one shard per module. Beyond Helium +# we will support more than 1 +# The replicas section is a collection of member names. This information +# will be used to decide on which members replicas of a particular shard will be +# located. Once replication is integrated with the distributed data store then +# this section can have multiple entries. +# +# + + +module-shards = [ + { + name = "default" + shards = [ + { + name="default" + replicas = [ + "member-1", + "member-2", + "member-3" + ] + } + ] + }, + { + name = "topology" + shards = [ + { + name="topology" + replicas = [ + "member-1", + "member-2", + "member-3" + ] + } + ] + }, + { + name = "inventory" + shards = [ + { + name="inventory" + replicas = [ + "member-1", + "member-2", + "member-3" + ] + } + ] + }, + { + name = "toaster" + shards = [ + { + name="toaster" + replicas = [ + "member-1", + "member-2", + "member-3" + ] + } + ] + } + { + name = "car" + shards = [ + { + name="car" + replicas = [ + "member-1", + "member-2", + "member-3" + ] + } + ] + } + { + name = "people" + shards = [ + { + name="people" + replicas = [ + "member-1", + "member-2", + "member-3" + ] + } + ] + } + { + name = "car-people" + shards = [ + { + name="car-people" + replicas = [ + "member-1", + "member-2", + "member-3" + ] + } + ] + } + +] diff --git a/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/modules.conf b/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/modules.conf new file mode 100644 index 0000000000..eda60d35a1 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/configuration/src/main/resources/initial/modules.conf @@ -0,0 +1,47 @@ +# This file should describe all the modules that need to be placed in a separate shard +# The format of the configuration is as follows +# { +# name = "" +# namespace = "" +# shard-strategy = "module" +# } +# +# Note that at this time the only shard-strategy we support is module which basically +# will put all the data of a single module in two shards (one for config and one for +# operational data) + +modules = [ + { + name = "inventory" + namespace = "urn:opendaylight:inventory" + shard-strategy = "module" + }, + + { + name = "topology" + namespace = "urn:TBD:params:xml:ns:yang:network-topology" + shard-strategy = "module" + }, + + { + name = "toaster" + namespace = "http://netconfcentral.org/ns/toaster" + shard-strategy = "module" + }, + { + name = "car" + namespace = "urn:opendaylight:params:xml:ns:yang:controller:config:sal-clustering-it:car" + shard-strategy = "module" + } + { + name = "people" + namespace = "urn:opendaylight:params:xml:ns:yang:controller:config:sal-clustering-it:people" + shard-strategy = "module" + } + + { + name = "car-people" + namespace = "urn:opendaylight:params:xml:ns:yang:controller:config:sal-clustering-it:car-people" + shard-strategy = "module" + } +] diff --git a/opendaylight/md-sal/samples/clustering-test-app/model/pom.xml b/opendaylight/md-sal/samples/clustering-test-app/model/pom.xml new file mode 100644 index 0000000000..a23e32df2b --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/model/pom.xml @@ -0,0 +1,115 @@ + + + 4.0.0 + + clustering-it + org.opendaylight.controller.samples + 1.1-SNAPSHOT + + clustering-it-model + bundle + + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + true + + + org.opendaylight.controller.sal-clustering-it-model + * + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${yangtools.version} + + + + generate-sources + + + src/main/yang + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + target/generated-sources/sal + + + true + + + + + + org.opendaylight.yangtools + maven-sal-api-gen-plugin + ${yangtools.version} + jar + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.opendaylight.yangtools + yang-maven-plugin + [0.5,) + + generate-sources + + + + + + + + + + + + + + + + org.opendaylight.yangtools + yang-binding + ${yangtools.version} + + + org.opendaylight.yangtools + yang-common + ${yangtools.version} + + + org.opendaylight.yangtools.model + ietf-inet-types + ${ietf-inet-types.version} + + + org.opendaylight.yangtools.model + ietf-yang-types + ${ietf-yang-types.version} + + + org.opendaylight.yangtools.model + yang-ext + ${yang-ext.version} + + + diff --git a/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-people.yang b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-people.yang new file mode 100644 index 0000000000..899724658f --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-people.yang @@ -0,0 +1,42 @@ +module car-people { + + yang-version 1; + + namespace "urn:opendaylight:params:xml:ns:yang:controller:config:sal-clustering-it:car-people"; + + prefix car; + + import ietf-inet-types { prefix "inet"; revision-date 2010-09-24; } + import car { prefix "c"; revision-date 2014-08-18; } + import people { prefix "people"; revision-date 2014-08-18; } + + organization "Netconf Central"; + + contact + "Harman Singh "; + + description + "YANG model for car for test application"; + + revision "2014-08-18" { + description + "Clustering sample app"; + } + + container car-people { + description + "Top-level container for all people car map"; + + list car-person { + key "car-id person-id"; + description "A mapping of cars and people."; + leaf car-id { + type c:car-id; + } + + leaf person-id { + type people:person-id; + } + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-purchase.yang b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-purchase.yang new file mode 100644 index 0000000000..f6a8797098 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car-purchase.yang @@ -0,0 +1,60 @@ +module car-purchase { + + yang-version 1; + + namespace "urn:opendaylight:params:xml:ns:yang:controller:config:sal-clustering-it:car-purchase"; + + prefix cp; + + import ietf-inet-types { prefix "inet"; revision-date 2010-09-24; } + import car { prefix "car"; revision-date 2014-08-18; } + import people { prefix "person"; revision-date 2014-08-18; } + import yang-ext {prefix "ext"; revision-date "2013-07-09";} + + organization "Netconf Central"; + + contact + "Harman Singh "; + + description + "YANG model for car purchase for test application"; + + revision "2014-08-18" { + description + "Clustering sample app"; + } + + rpc buy-car { + description + "buy a new car"; + input { + leaf person { + ext:context-reference "person:person-context"; + type person:person-ref; + description "A reference to a particular person."; + } + + leaf car-id { + type car:car-id; + description "identifier of car."; + } + leaf person-id { + type person:person-id; + description "identifier of person."; + } + } + } + + notification carBought { + description + "Indicates that a person bought a car."; + leaf car-id { + type car:car-id; + description "identifier of car."; + } + leaf person-id { + type person:person-id; + description "identifier of person."; + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car.yang b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car.yang new file mode 100644 index 0000000000..d9cfb6b1d5 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car.yang @@ -0,0 +1,64 @@ +module car { + + yang-version 1; + + namespace "urn:opendaylight:params:xml:ns:yang:controller:config:sal-clustering-it:car"; + + prefix car; + + import ietf-inet-types { prefix "inet"; revision-date 2010-09-24; } + + organization "Netconf Central"; + + contact + "Harman Singh "; + + description + "YANG model for car for test application"; + + revision "2014-08-18" { + description + "Clustering sample app"; + } + + typedef car-id { + type inet:uri; + description "An identifier for car entry."; + } + + grouping car-entry { + description "Describes the contents of a car entry - + Details of the car manufacturer, model etc"; + leaf id { + type car-id; + description "identifier of single list of entries."; + } + + leaf model { + type string; + } + leaf manufacturer { + type string; + } + + leaf year { + type uint32; + } + + leaf category { + type string; + } + } + + container cars { + description + "Top-level container for all car objects."; + list car-entry { + key "id"; + description "A list of cars (as defined by the 'grouping car-entry')."; + uses car-entry; + } + } + + +} \ No newline at end of file diff --git a/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/people.yang b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/people.yang new file mode 100644 index 0000000000..6c8f24703f --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/people.yang @@ -0,0 +1,80 @@ +module people { + + yang-version 1; + + namespace "urn:opendaylight:params:xml:ns:yang:controller:config:sal-clustering-it:people"; + + prefix people; + + import ietf-inet-types { prefix "inet"; revision-date 2010-09-24; } + + organization "Netconf Central"; + + contact + "Harman Singh "; + + description + "YANG model for person for test application"; + + revision "2014-08-18" { + description + "Clustering sample app"; + } + + typedef person-id { + type inet:uri; + description "An identifier for person."; + } + + typedef person-ref { + type instance-identifier; + description "A reference that points to an people:people/person in the data tree."; + } + identity person-context { + description "A person-context is a classifier for person elements which allows an RPC to provide a service on behalf of a particular element in the data tree."; + } + + grouping person { + description "Describes the details of the person"; + + leaf id { + type person-id; + description "identifier of single list of entries."; + } + + leaf gender { + type string; + } + + leaf age { + type uint32; + } + + leaf address { + type string; + } + + leaf contactNo { + type string; + } + } + + container people { + description + "Top-level container for all people"; + + list person { + key "id"; + description "A list of people (as defined by the 'grouping person')."; + uses person; + } + } + + rpc add-person { + description + "Add a person entry into database"; + input { + uses person; + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/samples/clustering-test-app/pom.xml b/opendaylight/md-sal/samples/clustering-test-app/pom.xml new file mode 100644 index 0000000000..863bbecdf9 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + org.opendaylight.controller.samples + sal-samples + 1.1-SNAPSHOT + + clustering-it + pom + + configuration + model + provider + + diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/pom.xml b/opendaylight/md-sal/samples/clustering-test-app/provider/pom.xml new file mode 100644 index 0000000000..093b681125 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + clustering-it + org.opendaylight.controller.samples + 1.1-SNAPSHOT + + clustering-it-provider + bundle + + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + true + + + org.opendaylight.controller.config.yang.config.clustering_it_provider + * + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${yangtools.version} + + + config + + generate-sources + + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + ${jmxGeneratorPath} + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + ${salGeneratorPath} + + + true + + + + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${config.version} + + + org.opendaylight.yangtools + maven-sal-api-gen-plugin + ${yangtools.version} + + + + + + + + + org.opendaylight.controller.samples + clustering-it-model + ${version} + + + org.opendaylight.controller + config-api + ${config.version} + + + org.opendaylight.controller + sal-binding-config + ${mdsal.version} + + + org.opendaylight.controller + sal-binding-api + ${mdsal.version} + + + org.opendaylight.controller + sal-common-util + ${mdsal.version} + + + equinoxSDK381 + org.eclipse.osgi + 3.8.1.v20120830-144521 + + + diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/listener/PeopleCarListener.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/listener/PeopleCarListener.java new file mode 100644 index 0000000000..4737d6eb49 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/listener/PeopleCarListener.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2014 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.clustering.it.listener; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.CarPeople; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPerson; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPersonBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPersonKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarBought; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseListener; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class PeopleCarListener implements CarPurchaseListener { + + private static final Logger log = LoggerFactory.getLogger(PeopleCarListener.class); + + private DataBroker dataProvider; + + + + public void setDataProvider(final DataBroker salDataProvider) { + this.dataProvider = salDataProvider; + } + + @Override + public void onCarBought(CarBought notification) { + log.info("onCarBought notification : Adding car person entry"); + + final CarPersonBuilder carPersonBuilder = new CarPersonBuilder(); + carPersonBuilder.setCarId(notification.getCarId()); + carPersonBuilder.setPersonId(notification.getPersonId()); + CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId()); + carPersonBuilder.setKey(key); + final CarPerson carPerson = carPersonBuilder.build(); + + InstanceIdentifier carPersonIId = + InstanceIdentifier.builder(CarPeople.class).child(CarPerson.class, carPerson.getKey()).build(); + + + WriteTransaction tx = dataProvider.newWriteOnlyTransaction(); + tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson); + + Futures.addCallback(tx.submit(), new FutureCallback() { + @Override + public void onSuccess(final Void result) { + log.info("Car bought, entry added to map of people and car [{}]", carPerson); + } + + @Override + public void onFailure(final Throwable t) { + log.info("Car bought, Failed entry addition to map of people and car [{}]", carPerson); + } + }); + + } +} diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PeopleProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PeopleProvider.java new file mode 100644 index 0000000000..e0d3f75349 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PeopleProvider.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2014 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.clustering.it.provider; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.People; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PeopleService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PersonContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.Person; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.PersonBuilder; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.Future; + +public class PeopleProvider implements PeopleService, AutoCloseable { + + private static final Logger log = LoggerFactory.getLogger(PeopleProvider.class); + + private DataBroker dataProvider; + + private BindingAwareBroker.RoutedRpcRegistration rpcRegistration; + + public void setDataProvider(final DataBroker salDataProvider) { + this.dataProvider = salDataProvider; + } + + + public void setRpcRegistration(BindingAwareBroker.RoutedRpcRegistration rpcRegistration) { + this.rpcRegistration = rpcRegistration; + } + + @Override + public Future> addPerson(AddPersonInput input) { + log.info("RPC addPerson : adding person [{}]", input); + + PersonBuilder builder = new PersonBuilder(input); + final Person person = builder.build(); + final SettableFuture> futureResult = SettableFuture.create(); + + // Each entry will be identifiable by a unique key, we have to create that identifier + final InstanceIdentifier.InstanceIdentifierBuilder personIdBuilder = + InstanceIdentifier.builder(People.class) + .child(Person.class, person.getKey()); + final InstanceIdentifier personId = personIdBuilder.build(); + // Place entry in data store tree + WriteTransaction tx = dataProvider.newWriteOnlyTransaction(); + tx.put(LogicalDatastoreType.CONFIGURATION, personId, person); + + Futures.addCallback(tx.submit(), new FutureCallback() { + @Override + public void onSuccess(final Void result) { + log.info("RPC addPerson : person added successfully [{}]", person); + rpcRegistration.registerPath(PersonContext.class, personId); + log.info("RPC addPerson : routed rpc registered for instance ID [{}]", personId); + futureResult.set(RpcResultBuilder.success().build()); + } + + @Override + public void onFailure(final Throwable t) { + log.info("RPC addPerson : person addition failed [{}]", person); + futureResult.set(RpcResultBuilder.failed() + .withError(RpcError.ErrorType.APPLICATION, t.getMessage()).build()); + } + }); + return futureResult; + } + + @Override + public void close() throws Exception { + + } +} diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PurchaseCarProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PurchaseCarProvider.java new file mode 100644 index 0000000000..74a0aa68ed --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PurchaseCarProvider.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014 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.clustering.it.provider; + +import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarBoughtBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.Future; + + +public class PurchaseCarProvider implements CarPurchaseService, AutoCloseable{ + + private static final Logger log = LoggerFactory.getLogger(PurchaseCarProvider.class); + + private NotificationProviderService notificationProvider; + + + public void setNotificationProvider(final NotificationProviderService salService) { + this.notificationProvider = salService; + } + + + @Override + public Future> buyCar(BuyCarInput input) { + log.info("Routed RPC buyCar : generating notification for buying car [{}]", input); + SettableFuture> futureResult = SettableFuture.create(); + CarBoughtBuilder carBoughtBuilder = new CarBoughtBuilder(); + carBoughtBuilder.setCarId(input.getCarId()); + carBoughtBuilder.setPersonId(input.getPersonId()); + notificationProvider.publish(carBoughtBuilder.build()); + futureResult.set(RpcResultBuilder.success().build()); + return futureResult; + } + + @Override + public void close() throws Exception { + + } +} diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModule.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModule.java new file mode 100644 index 0000000000..d91d40a34d --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModule.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.config.yang.config.clustering_it_provider; + + +import org.opendaylight.controller.clustering.it.listener.PeopleCarListener; +import org.opendaylight.controller.clustering.it.provider.PeopleProvider; +import org.opendaylight.controller.clustering.it.provider.PurchaseCarProvider; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PeopleService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.NotificationListener; + +public class ClusteringItProviderModule extends org.opendaylight.controller.config.yang.config.clustering_it_provider.AbstractClusteringItProviderModule { + public ClusteringItProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public ClusteringItProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.clustering_it_provider.ClusteringItProviderModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + DataBroker dataBrokerService = getDataBrokerDependency(); + NotificationProviderService notificationProvider = getNotificationServiceDependency(); + + // Add routed RPC registration for car purchase + final PurchaseCarProvider purchaseCar = new PurchaseCarProvider(); + purchaseCar.setNotificationProvider(notificationProvider); + + final BindingAwareBroker.RoutedRpcRegistration purchaseCarRpc = getRpcRegistryDependency() + .addRoutedRpcImplementation(CarPurchaseService.class, purchaseCar); + + // Add people provider registration + final PeopleProvider people = new PeopleProvider(); + people.setDataProvider(dataBrokerService); + + people.setRpcRegistration(purchaseCarRpc); + + final BindingAwareBroker.RpcRegistration peopleRpcReg = getRpcRegistryDependency() + .addRpcImplementation(PeopleService.class, people); + + + + final PeopleCarListener peopleCarListener = new PeopleCarListener(); + peopleCarListener.setDataProvider(dataBrokerService); + + final ListenerRegistration listenerReg = + getNotificationServiceDependency().registerNotificationListener( peopleCarListener ); + + // Wrap toaster as AutoCloseable and close registrations to md-sal at + // close() + final class AutoCloseableToaster implements AutoCloseable { + + @Override + public void close() throws Exception { + peopleRpcReg.close(); + purchaseCarRpc.close(); + people.close(); + purchaseCar.close(); + listenerReg.close(); + } + } + + AutoCloseable ret = new AutoCloseableToaster(); + return ret; + } + +} diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModuleFactory.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModuleFactory.java new file mode 100644 index 0000000000..642263c773 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/config/yang/config/clustering_it_provider/ClusteringItProviderModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: clustering-it-provider yang module local name: clustering-it-provider +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Tue Aug 19 14:44:46 PDT 2014 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.config.clustering_it_provider; +public class ClusteringItProviderModuleFactory extends org.opendaylight.controller.config.yang.config.clustering_it_provider.AbstractClusteringItProviderModuleFactory { + +} diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/yang/clustering-it-provider.yang b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/yang/clustering-it-provider.yang new file mode 100644 index 0000000000..ff3f9a8e5c --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/yang/clustering-it-provider.yang @@ -0,0 +1,60 @@ +module clustering-it-provider { + + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:config:clustering-it-provider"; + prefix "clustering-it-provider"; + + import config { prefix config; revision-date 2013-04-05; } + import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } + + description + "This module contains the base YANG definitions for + clustering-it-provider implementation."; + + revision "2014-08-19" { + description + "Initial revision."; + } + + // This is the definition of the service implementation as a module identity. + identity clustering-it-provider { + base config:module-type; + + // Specifies the prefix for generated java classes. + config:java-name-prefix ClusteringItProvider; + } + + // Augments the 'configuration' choice node under modules/module. + augment "/config:modules/config:module/config:configuration" { + case clustering-it-provider { + when "/config:modules/config:module/config:type = 'clustering-it-provider'"; + + container rpc-registry { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity mdsal:binding-rpc-registry; + } + } + } + + container notification-service { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity mdsal:binding-notification-service; + } + } + } + + container data-broker { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity mdsal:binding-async-data-broker; + } + } + } + } + } +} diff --git a/opendaylight/md-sal/samples/pom.xml b/opendaylight/md-sal/samples/pom.xml index ae7d323480..d13200e4e8 100644 --- a/opendaylight/md-sal/samples/pom.xml +++ b/opendaylight/md-sal/samples/pom.xml @@ -17,6 +17,7 @@ toaster-provider toaster-config l2switch + clustering-test-app scm:git:ssh://git.opendaylight.org:29418/controller.git -- 2.36.6