Search in sources :

Example 6 with OuterList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList in project controller by opendaylight.

the class TxchainBaDelete method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final BindingTransactionChain chain = bindingDataBroker.createTransactionChain(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++;
            Futures.addCallback(tx.submit(), new FutureCallback<Void>() {

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

                @Override
                public void onFailure(final Throwable t) {
                    LOG.error("Transaction failed, {}", t);
                    txError++;
                }
            });
            tx = chain.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    // We need to empty the chain before closing it
    try {
        if (writeCnt > 0) {
            txSubmitted++;
        }
        tx.submit().checkedGet();
    } catch (final TransactionCommitFailedException 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.controller.md.sal.binding.api.WriteTransaction) BindingTransactionChain(org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain) OuterList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) 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.controller.md.sal.common.api.data.LogicalDatastoreType)

Example 7 with OuterList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList in project controller by opendaylight.

the class TxchainBaRead method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    try (ReadOnlyTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
        for (long l = 0; l < outerListElem; l++) {
            InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey((int) l));
            CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
            try {
                Optional<OuterList> optionalDataObject = submitFuture.checkedGet();
                if (optionalDataObject != null && optionalDataObject.isPresent()) {
                    OuterList outerList = optionalDataObject.get();
                    String[] objectsArray = new String[outerList.getInnerList().size()];
                    for (InnerList innerList : outerList.getInnerList()) {
                        if (objectsArray[innerList.getName()] != null) {
                            LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue());
                        }
                        objectsArray[innerList.getName()] = innerList.getValue();
                    }
                    for (int i = 0; i < outerList.getInnerList().size(); i++) {
                        String itemStr = objectsArray[i];
                        if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
                            LOG.error("innerList: name: {}, value: {}", i, itemStr);
                            break;
                        }
                    }
                    txOk++;
                } else {
                    txError++;
                }
            } catch (final ReadFailedException e) {
                LOG.warn("failed to ....", e);
                txError++;
            }
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) InnerList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList) Optional(com.google.common.base.Optional) OuterList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList) OuterListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) TestExec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)

Aggregations

TestExec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec)7 OuterList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5 OuterListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey)4 Optional (com.google.common.base.Optional)2 BindingTransactionChain (org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain)2 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 InnerList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList)2 TestExecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExecBuilder)1