Search in sources :

Example 66 with ReadWriteTransaction

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

the class ManagedNewTransactionRunnerImpl method callWithNewReadWriteTransactionAndSubmit.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public <E extends Exception> ListenableFuture<Void> callWithNewReadWriteTransactionAndSubmit(CheckedConsumer<ReadWriteTransaction, E> txRunner) {
    ReadWriteTransaction realTx = broker.newReadWriteTransaction();
    ReadWriteTransaction wrappedTx = new NonSubmitCancelableReadWriteTransaction(realTx);
    try {
        txRunner.accept(wrappedTx);
        return realTx.submit();
    // catch Exception for both the <E extends Exception> thrown by accept() as well as any RuntimeException
    } catch (Exception e) {
        if (!realTx.cancel()) {
            LOG.error("Transaction.cancel() returned false, which should never happen here");
        }
        return immediateFailedFuture(e);
    }
}
Also used : ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 67 with ReadWriteTransaction

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

the class TransportZoneListener method initializeTZNode.

@SuppressWarnings("checkstyle:IllegalCatch")
private void initializeTZNode(DataBroker db) {
    ReadWriteTransaction transaction = db.newReadWriteTransaction();
    InstanceIdentifier<TransportZones> path = InstanceIdentifier.create(TransportZones.class);
    CheckedFuture<Optional<TransportZones>, ReadFailedException> tzones = transaction.read(LogicalDatastoreType.CONFIGURATION, path);
    try {
        if (!tzones.get().isPresent()) {
            TransportZonesBuilder tzb = new TransportZonesBuilder();
            transaction.put(LogicalDatastoreType.CONFIGURATION, path, tzb.build());
            transaction.submit();
        } else {
            transaction.cancel();
        }
    } catch (Exception e) {
        LOG.error("Error initializing TransportZones {}", e);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) TransportZonesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZonesBuilder) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) NotHostedTransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.NotHostedTransportZones) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Aggregations

ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)67 Optional (com.google.common.base.Optional)21 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)17 Test (org.junit.Test)16 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)13 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)13 CountDownLatch (java.util.concurrent.CountDownLatch)11 Mockito.doReturn (org.mockito.Mockito.doReturn)11 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)11 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)11 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)10 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)9 DataTreeModification (org.opendaylight.controller.md.sal.binding.api.DataTreeModification)8 TestUtils.newInvNodeKey (org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newInvNodeKey)8 NodeKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)8 TestUtils.newLink (org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newLink)7 Link (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)7 ArrayList (java.util.ArrayList)6 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)6 NodeBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)6