Search in sources :

Example 61 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapterTest method testReadWriteTransaction.

@Test
public void testReadWriteTransaction() throws Exception {
    DOMDataReadWriteTransaction tx = adapter.newReadWriteTransaction();
    CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = tx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
    assertEquals("isPresent", true, readOptional.isPresent());
    assertEquals("NormalizedNode", dataNode, readOptional.get());
    tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
    verify(mockReadWriteTx).write(TestModel.TEST_PATH, dataNode);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
    submitFuture.get(5, TimeUnit.SECONDS);
    InOrder inOrder = inOrder(mockCommitCohort);
    inOrder.verify(mockCommitCohort).canCommit();
    inOrder.verify(mockCommitCohort).preCommit();
    inOrder.verify(mockCommitCohort).commit();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) InOrder(org.mockito.InOrder) Optional(com.google.common.base.Optional) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 62 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project controller by opendaylight.

the class CarProvider method stressTest.

@Override
public Future<RpcResult<Void>> 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() == 0) {
        LOG_PURCHASE_CAR.info("Exiting stress test as no rate is given.");
        return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withError(ErrorType.PROTOCOL, "invalid rate").build());
    }
    inputRate = input.getRate();
    if (input.getCount() != null) {
        inputCount = input.getCount();
    } 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.<Cars>builder(Cars.class).build();
    tx.merge(LogicalDatastoreType.CONFIGURATION, carsId, new CarsBuilder().build());
    try {
        tx.submit().checkedGet(5, TimeUnit.SECONDS);
    } catch (TransactionCommitFailedException | TimeoutException e) {
        LOG_PURCHASE_CAR.error("Put Cars failed", e);
        return Futures.immediateFuture(RpcResultBuilder.<Void>success().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.getKey()).build(), car);
            CheckedFuture<Void, TransactionCommitFailedException> future = tx1.submit();
            Futures.addCallback(future, new FutureCallback<Void>() {

                @Override
                public void onSuccess(final Void 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.<Void>success().build());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.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) CarEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntry) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) 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) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) 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 63 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project bgpcep by opendaylight.

the class BmpRouterImpl method tearDown.

@GuardedBy("this")
@SuppressWarnings("checkstyle:IllegalCatch")
private synchronized void tearDown() {
    // the session has been teared down before
    if (this.session == null) {
        return;
    }
    // we want to display remote router's IP here, as sometimes this.session.close() is already
    // invoked before tearDown(), and session channel is null in this case, which leads to unuseful
    // log information
    LOG.info("BMP Session with remote router {} ({}) went down.", this.routerIp, this.session);
    this.session = null;
    final Iterator<BmpRouterPeer> it = this.peers.values().iterator();
    try {
        while (it.hasNext()) {
            it.next().close();
            it.remove();
        }
        this.domTxChain.close();
    } catch (final Exception e) {
        LOG.error("Failed to properly close BMP application.", e);
    } finally {
        // as the routerId is the same for both connection
        if (isDatastoreWritable()) {
            try {
                // it means the session was closed before it was written to datastore
                final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction();
                wTx.delete(LogicalDatastoreType.OPERATIONAL, this.routerYangIId);
                wTx.submit().checkedGet();
            } catch (final TransactionCommitFailedException e) {
                LOG.error("Failed to remove BMP router data from DS.", e);
            }
            this.sessionManager.removeSessionListener(this);
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) BmpRouterPeer(org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 64 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project bgpcep by opendaylight.

the class RIBImpl method instantiateServiceInstance.

public synchronized void instantiateServiceInstance() {
    this.isServiceInstantiated = true;
    setActive(true);
    this.domChain = this.domDataBroker.createTransactionChain(this);
    LOG.debug("Instantiating RIB table {} at {}", this.ribId, this.yangRibId);
    final ContainerNode bgpRib = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BgpRib.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Rib.QNAME).build()).build();
    final MapEntryNode ribInstance = Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(Rib.QNAME, RIB_ID_QNAME, this.ribId.getValue())).addChild(ImmutableNodes.leafNode(RIB_ID_QNAME, this.ribId.getValue())).addChild(ImmutableNodes.mapNodeBuilder(Peer.QNAME).build()).addChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(LocRib.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build()).build()).build();
    final DOMDataWriteTransaction trans = this.domChain.newWriteOnlyTransaction();
    // merge empty BgpRib + Rib, to make sure the top-level parent structure is present
    trans.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BgpRib.QNAME).build(), bgpRib);
    trans.put(LogicalDatastoreType.OPERATIONAL, this.yangRibId, ribInstance);
    try {
        trans.submit().checkedGet();
    } catch (final TransactionCommitFailedException e) {
        LOG.error("Failed to initiate RIB {}", this.yangRibId, e);
    }
    LOG.debug("Effective RIB created.");
    this.localTablesKeys.forEach(this::startLocRib);
    this.localTablesKeys.forEach(this::createLocRibWriter);
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 65 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project bgpcep by opendaylight.

the class TopologyDataChangeCounter method close.

@Override
public void close() {
    this.registration.close();
    final WriteTransaction wTx = this.dataBroker.newWriteOnlyTransaction();
    wTx.delete(LogicalDatastoreType.OPERATIONAL, this.counterInstanceId);
    try {
        wTx.submit().checkedGet();
    } catch (final TransactionCommitFailedException except) {
        LOG.warn("Error on remove data change counter {}", this.counterId, except);
    }
    this.bindingTx.close();
    LOG.debug("Data change counter {} removed", this.counterId);
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)

Aggregations

TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)117 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)32 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)21 Test (org.junit.Test)19 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)16 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)13 ArrayList (java.util.ArrayList)12 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)12 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)11 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)9 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)9 OptimisticLockFailedException (org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)8 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)8 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)8 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)7 Optional (com.google.common.base.Optional)6 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)6 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)6 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)6