X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tools%2Fodl-mdsal-clustering-tests%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Flistener%2FPeopleCarListener.java;fp=tools%2Fodl-mdsal-clustering-tests%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Flistener%2FPeopleCarListener.java;h=4737d6eb49254ed6a2ded147d3429848d9a2bb4c;hb=59e81c38620fa1b61e15771191e35771450b9499;hp=0000000000000000000000000000000000000000;hpb=072f6e3a8d1bdf8f4c663843589c22d93ba07791;p=integration%2Ftest.git diff --git a/tools/odl-mdsal-clustering-tests/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/listener/PeopleCarListener.java b/tools/odl-mdsal-clustering-tests/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/tools/odl-mdsal-clustering-tests/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); + } + }); + + } +}