Search in sources :

Example 26 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.

the class PeopleCarListener method onCarBought.

@Override
public void onCarBought(final CarBought notification) {
    final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
    carPersonBuilder.setCarId(notification.getCarId());
    carPersonBuilder.setPersonId(notification.getPersonId());
    CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
    carPersonBuilder.withKey(key);
    final CarPerson carPerson = carPersonBuilder.build();
    LOG.info("Car bought, adding car-person entry: [{}]", carPerson);
    InstanceIdentifier<CarPerson> carPersonIId = InstanceIdentifier.builder(CarPeople.class).child(CarPerson.class, carPerson.key()).build();
    WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson);
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.info("Successfully added car-person entry: [{}]", carPerson);
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error("Failed to add car-person entry: [{}]", carPerson, ex);
        }
    }, MoreExecutors.directExecutor());
}
Also used : CarPersonKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPersonKey) CarPerson(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPerson) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) CarPersonBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPersonBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 27 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.

the class CarProvider method stressTest.

@Override
public ListenableFuture<RpcResult<StressTestOutput>> stressTest(final StressTestInput input) {
    final int inputRate;
    final long inputCount;
    // If rate is not provided, or given as zero, then just return.
    if (input.getRate() == null || input.getRate().toJava() == 0) {
        LOG_PURCHASE_CAR.info("Exiting stress test as no rate is given.");
        return Futures.immediateFuture(RpcResultBuilder.<StressTestOutput>failed().withError(ErrorType.PROTOCOL, "invalid rate").build());
    }
    inputRate = input.getRate().toJava();
    if (input.getCount() != null) {
        inputCount = input.getCount().toJava();
    } else {
        inputCount = 0;
    }
    LOG_PURCHASE_CAR.info("Stress test starting : rate: {} count: {}", inputRate, inputCount);
    stopThread();
    // clear counters
    succcessCounter.set(0);
    failureCounter.set(0);
    WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
    InstanceIdentifier<Cars> carsId = InstanceIdentifier.create(Cars.class);
    tx.merge(LogicalDatastoreType.CONFIGURATION, carsId, new CarsBuilder().build());
    try {
        tx.commit().get(5, TimeUnit.SECONDS);
    } catch (TimeoutException | InterruptedException | ExecutionException e) {
        LOG_PURCHASE_CAR.error("Put Cars failed", e);
        return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build());
    }
    stopThread = false;
    final long sleep = TimeUnit.NANOSECONDS.convert(1000, TimeUnit.MILLISECONDS) / inputRate;
    final Stopwatch sw = Stopwatch.createUnstarted();
    testThread = new Thread(() -> {
        sw.start();
        AtomicLong count = new AtomicLong();
        while (!stopThread) {
            long id = count.incrementAndGet();
            WriteTransaction tx1 = dataProvider.newWriteOnlyTransaction();
            CarEntry car = new CarEntryBuilder().setId(new CarId("car" + id)).build();
            tx1.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.key()).build(), car);
            tx1.commit().addCallback(new FutureCallback<CommitInfo>() {

                @Override
                public void onSuccess(final CommitInfo result) {
                    // Transaction succeeded
                    succcessCounter.getAndIncrement();
                }

                @Override
                public void onFailure(final Throwable ex) {
                    // Transaction failed
                    failureCounter.getAndIncrement();
                    LOG_CAR_PROVIDER.error("Put Cars failed", ex);
                }
            }, MoreExecutors.directExecutor());
            try {
                TimeUnit.NANOSECONDS.sleep(sleep);
            } catch (InterruptedException e) {
                break;
            }
            if (count.get() % 1000 == 0) {
                LOG_PURCHASE_CAR.info("Cars created {}, time: {}", count.get(), sw.elapsed(TimeUnit.SECONDS));
            }
            // Check if a count is specified in input and we have created that many cars.
            if (inputCount != 0 && count.get() >= inputCount) {
                stopThread = true;
            }
        }
        LOG_PURCHASE_CAR.info("Stress test thread stopping after creating {} cars.", count.get());
    });
    testThread.start();
    return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Cars(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars) Stopwatch(com.google.common.base.Stopwatch) StopStressTestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTestOutputBuilder) StressTestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StressTestOutputBuilder) CarEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntry) AtomicLong(java.util.concurrent.atomic.AtomicLong) CarId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarId) CarsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarsBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) ExecutionException(java.util.concurrent.ExecutionException) CarEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntryBuilder) FutureCallback(com.google.common.util.concurrent.FutureCallback) TimeoutException(java.util.concurrent.TimeoutException)

Example 28 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.

the class PeopleProvider method addPerson.

@Override
public ListenableFuture<RpcResult<AddPersonOutput>> addPerson(final AddPersonInput input) {
    LOG.info("RPC addPerson : adding person [{}]", input);
    PersonBuilder builder = new PersonBuilder(input);
    final Person person = builder.build();
    final SettableFuture<RpcResult<AddPersonOutput>> futureResult = SettableFuture.create();
    // Each entry will be identifiable by a unique key, we have to create that identifier
    final InstanceIdentifier<Person> personId = InstanceIdentifier.builder(People.class).child(Person.class, person.key()).build();
    // Place entry in data store tree
    WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, personId, person);
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.info("RPC addPerson : person added successfully [{}]", person);
            regs.add(rpcProviderService.registerRpcImplementation(CarPurchaseService.class, rpcImplementation, ImmutableSet.of(personId)));
            LOG.info("RPC addPerson : routed rpc registered for instance ID [{}]", personId);
            futureResult.set(RpcResultBuilder.success(new AddPersonOutputBuilder().build()).build());
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error("RPC addPerson : person addition failed [{}]", person, ex);
            futureResult.set(RpcResultBuilder.<AddPersonOutput>failed().withError(RpcError.ErrorType.APPLICATION, ex.getMessage()).build());
        }
    }, MoreExecutors.directExecutor());
    return futureResult;
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) PersonBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.PersonBuilder) AddPersonOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddPersonOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonOutput) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) Person(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.Person)

Example 29 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.

the class TxchainDomDelete method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    final DOMTransactionChain chain = domDataBroker.createMergingTransactionChain(this);
    DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (int l = 0; l < outerListElem; l++) {
        YangInstanceIdentifier yid = pid.node(NodeIdentifierWithPredicates.of(OuterList.QNAME, olId, l));
        tx.delete(dsType, yid);
        writeCnt++;
        if (writeCnt == writesPerTx) {
            txSubmitted++;
            tx.commit().addCallback(new FutureCallback<CommitInfo>() {

                @Override
                public void onSuccess(final CommitInfo result) {
                    txOk++;
                }

                @Override
                public void onFailure(final Throwable cause) {
                    LOG.error("Transaction failed", cause);
                    txError++;
                }
            }, MoreExecutors.directExecutor());
            tx = chain.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    // We need to empty the transaction chain before closing it
    try {
        txSubmitted++;
        tx.commit().get();
        txOk++;
    } catch (final InterruptedException | ExecutionException e) {
        LOG.error("Transaction failed", e);
        txError++;
    }
    try {
        chain.close();
    } catch (final IllegalStateException e) {
        LOG.error("Transaction close failed,", e);
    }
    LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) ExecutionException(java.util.concurrent.ExecutionException)

Example 30 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.

the class TxchainBaDelete method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final TransactionChain chain = bindingDataBroker.createMergingTransactionChain(this);
    WriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (int l = 0; l < outerListElem; l++) {
        InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey(l));
        tx.delete(dsType, iid);
        writeCnt++;
        if (writeCnt == writesPerTx) {
            txSubmitted++;
            tx.commit().addCallback(new FutureCallback<CommitInfo>() {

                @Override
                public void onSuccess(final CommitInfo result) {
                    txOk++;
                }

                @Override
                public void onFailure(final Throwable cause) {
                    LOG.error("Transaction failed", cause);
                    txError++;
                }
            }, MoreExecutors.directExecutor());
            tx = chain.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    // We need to empty the chain before closing it
    try {
        if (writeCnt > 0) {
            txSubmitted++;
        }
        tx.commit().get();
    } catch (final InterruptedException | ExecutionException e) {
        LOG.error("Transaction failed", e);
    }
    try {
        chain.close();
    } catch (final IllegalStateException e) {
        LOG.error("Transaction close failed", e);
    }
    LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) OuterList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) OuterListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey) TestExec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)59 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)26 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)23 ReadWriteTransaction (org.opendaylight.mdsal.binding.api.ReadWriteTransaction)12 ExecutionException (java.util.concurrent.ExecutionException)10 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)7 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)5 TransactionChain (org.opendaylight.mdsal.binding.api.TransactionChain)4 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)4 FluentFuture (com.google.common.util.concurrent.FluentFuture)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)3 Collection (java.util.Collection)3 Stopwatch (com.google.common.base.Stopwatch)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2