Search in sources :

Example 1 with TransactionChain

use of org.opendaylight.mdsal.binding.api.TransactionChain in project controller by opendaylight.

the class TxchainBaWrite method executeList.

@Override
public void executeList() {
    final TransactionChain chain = bindingDataBroker.createMergingTransactionChain(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.key());
        if (oper == StartTestInput.Operation.PUT) {
            tx.put(dsType, iid, element);
        } else {
            tx.merge(dsType, iid, element);
        }
        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 : 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) 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)

Example 2 with TransactionChain

use of org.opendaylight.mdsal.binding.api.TransactionChain in project bgpcep by opendaylight.

the class TopologyStatsProviderImpl method updateStats.

@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void updateStats() {
    final TransactionChain chain = accessChain();
    if (chain == null) {
        // Already closed, do not bother
        return;
    }
    final WriteTransaction tx = chain.newWriteOnlyTransaction();
    try {
        for (Entry<KeyedInstanceIdentifier<Node, NodeKey>, PcepSessionState> entry : statsMap.entrySet()) {
            if (!statsPendingDelete.contains(entry.getKey())) {
                tx.put(LogicalDatastoreType.OPERATIONAL, entry.getKey().augmentation(PcepTopologyNodeStatsAug.class), new PcepTopologyNodeStatsAugBuilder().setPcepSessionState(new PcepSessionStateBuilder(entry.getValue()).build()).build());
            }
        }
    } catch (Exception e) {
        LOG.warn("Failed to prepare Tx for PCEP stats update", e);
        tx.cancel();
        return;
    }
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Successfully committed Topology stats update");
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error("Failed to commit Topology stats update", ex);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) PcepSessionState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.PcepSessionState) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) ExecutionException(java.util.concurrent.ExecutionException) PcepTopologyNodeStatsAugBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev181109.PcepTopologyNodeStatsAugBuilder) PcepTopologyNodeStatsAug(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev181109.PcepTopologyNodeStatsAug) PcepSessionStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.grouping.PcepSessionStateBuilder) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 3 with TransactionChain

use of org.opendaylight.mdsal.binding.api.TransactionChain in project bgpcep by opendaylight.

the class TopologyStatsProviderImpl method unbind.

@Override
public synchronized void unbind(final KeyedInstanceIdentifier<Node, NodeKey> nodeId) {
    final TransactionChain chain = accessChain();
    if (chain == null) {
        // Already closed, do not bother
        LOG.debug("Ignoring unbind of Pcep Node {}", nodeId);
        return;
    }
    final PcepSessionState node = statsMap.remove(nodeId);
    if (node == null) {
        LOG.debug("Ignoring duplicate unbind of Pcep Node {}", nodeId);
        return;
    }
    statsPendingDelete.add(nodeId);
    final WriteTransaction wTx = chain.newWriteOnlyTransaction();
    wTx.delete(LogicalDatastoreType.OPERATIONAL, nodeId);
    wTx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Successfully removed Pcep Node stats {}.", nodeId.getKey().getNodeId());
            statsPendingDelete.remove(nodeId);
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.warn("Failed to remove Pcep Node stats {}.", nodeId.getKey().getNodeId(), ex);
            statsPendingDelete.remove(nodeId);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) PcepSessionState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.PcepSessionState) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 4 with TransactionChain

use of org.opendaylight.mdsal.binding.api.TransactionChain 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)

Example 5 with TransactionChain

use of org.opendaylight.mdsal.binding.api.TransactionChain in project bgpcep by opendaylight.

the class TopologyStatsProviderImpl method shutdown.

private synchronized void shutdown() throws InterruptedException, ExecutionException {
    // Try to get a transaction chain and indicate we are done
    final TransactionChain chain = accessChain();
    transactionChain = null;
    dataBroker = null;
    if (chain == null) {
        // Belt & suspenders so we do not error out elsewhere
        LOG.warn("Cannot acquire transaction chain, skipping cleanup");
        return;
    }
    // Issue deletes for all registered stats
    final WriteTransaction wTx = chain.newWriteOnlyTransaction();
    for (final KeyedInstanceIdentifier<Node, NodeKey> statId : statsMap.keySet()) {
        wTx.delete(LogicalDatastoreType.OPERATIONAL, statId);
    }
    statsMap.clear();
    // Fire the transaction commit ...
    final FluentFuture<?> future = wTx.commit();
    // ... close the transaction chain ...
    chain.close();
    // ... and wait for transaction commit to complete
    LOG.debug("Awaiting finish of TopologyStatsProvider cleanup");
    future.get();
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) TransactionChain(org.opendaylight.mdsal.binding.api.TransactionChain) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)

Aggregations

TransactionChain (org.opendaylight.mdsal.binding.api.TransactionChain)5 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)5 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)4 ExecutionException (java.util.concurrent.ExecutionException)3 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)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 PcepSessionState (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.PcepSessionState)2 OuterListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey)1 PcepSessionStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.grouping.PcepSessionStateBuilder)1 PcepTopologyNodeStatsAug (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev181109.PcepTopologyNodeStatsAug)1 PcepTopologyNodeStatsAugBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev181109.PcepTopologyNodeStatsAugBuilder)1 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)1 NodeKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)1 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)1