Search in sources :

Example 1 with BindingTransactionChain

use of org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain in project controller by opendaylight.

the class TxchainBaWrite method executeList.

@Override
public void executeList() {
    final BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
    final LogicalDatastoreType dsType = getDataStoreType();
    WriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (OuterList element : this.list) {
        InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, element.getKey());
        if (oper == StartTestInput.Operation.PUT) {
            tx.put(dsType, iid, element);
        } else {
            tx.merge(dsType, iid, element);
        }
        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 transaction chain before closing it
    try {
        txSubmitted++;
        tx.submit().checkedGet();
        txOk++;
    } catch (final TransactionCommitFailedException 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 : 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) 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 2 with BindingTransactionChain

use of org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain in project bgpcep by opendaylight.

the class RIBImpl method onTransactionChainFailed.

@Override
public synchronized void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction, final Throwable cause) {
    LOG.error("Broken chain in RIB {} transaction {}", getInstanceIdentifier(), transaction != null ? transaction.getIdentifier() : null, cause);
    if (this.txChainToLocRibWriter.containsKey(chain)) {
        final LocRibWriter locRibWriter = this.txChainToLocRibWriter.remove(chain);
        final BindingTransactionChain newChain = createPeerChain(this);
        startLocRib(locRibWriter.getTableKey());
        locRibWriter.restart(newChain);
        this.txChainToLocRibWriter.put(newChain, locRibWriter);
    }
}
Also used : BindingTransactionChain(org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain)

Example 3 with BindingTransactionChain

use of org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain in project openflowplugin by opendaylight.

the class FlowWriterTxChainTest method setUp.

@Before
public void setUp() throws Exception {
    Mockito.doAnswer(invocation -> {
        ((Runnable) invocation.getArguments()[0]).run();
        return null;
    }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
    final BindingTransactionChain mockedTxChain = mock(BindingTransactionChain.class);
    when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
    doReturn(mockedTxChain).when(mockDataBroker).createTransactionChain(Matchers.<TransactionChainListener>any());
    when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
    flowWriterTxChain = new FlowWriterTxChain(mockDataBroker, mockFlowPusher);
}
Also used : BindingTransactionChain(org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain) Before(org.junit.Before)

Example 4 with BindingTransactionChain

use of org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain 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 5 with BindingTransactionChain

use of org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain in project bgpcep by opendaylight.

the class RIBImpl method createLocRibWriter.

private synchronized void createLocRibWriter(final TablesKey key) {
    final RIBSupport ribSupport = this.ribContextRegistry.getRIBSupport(key);
    if (ribSupport == null) {
        return;
    }
    LOG.debug("Creating LocRIB writer for key {}", key);
    final BindingTransactionChain txChain = createPeerChain(this);
    PathSelectionMode pathSelectionStrategy = this.bestPathSelectionStrategies.get(key);
    if (pathSelectionStrategy == null) {
        pathSelectionStrategy = BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker);
    }
    final LocRibWriter locRibWriter = LocRibWriter.create(ribSupport, key, txChain, getInstanceIdentifier(), this.localAs, getDataBroker(), this.ribPolicies, this.peerTracker, pathSelectionStrategy);
    registerTotalPathCounter(key, locRibWriter);
    registerTotalPrefixesCounter(key, locRibWriter);
    this.txChainToLocRibWriter.put(txChain, locRibWriter);
}
Also used : BindingTransactionChain(org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) PathSelectionMode(org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)

Aggregations

BindingTransactionChain (org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 TestExec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec)2 OuterList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList)2 GuardedBy (javax.annotation.concurrent.GuardedBy)1 Before (org.junit.Before)1 TransactionChain (org.opendaylight.controller.md.sal.common.api.data.TransactionChain)1 PathSelectionMode (org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)1 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)1 OuterListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey)1