Search in sources :

Example 31 with ReadWriteTransaction

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

the class Bug3090MultiKeyList method write.

private void write(final LogicalDatastoreType store) {
    final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
    final List<ListInRoot> listInRoots = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        listInRoots.add(new ListInRootBuilder().setLeafA("leaf a" + i).setLeafC("leaf c" + i).setLeafB("leaf b" + i).build());
    }
    final Root root = new RootBuilder().setListInRoot(listInRoots).build();
    readWriteTransaction.put(store, ROOT_PATH, root);
    assertCommit(readWriteTransaction.submit());
}
Also used : RootBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.RootBuilder) ListInRootBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder) Root(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.Root) ListInRoot(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot) ArrayList(java.util.ArrayList) ListInRootBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ListInRoot(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot)

Example 32 with ReadWriteTransaction

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

the class ListInsertionDataChangeListenerTest method putTopBarNodeSubtreeListeners.

@Test
public void putTopBarNodeSubtreeListeners() {
    TestListener topListener = createListener(CONFIGURATION, TOP, DataChangeScope.SUBTREE);
    TestListener allListener = createListener(CONFIGURATION, WILDCARDED, DataChangeScope.SUBTREE, false);
    TestListener fooListener = createListener(CONFIGURATION, TOP_FOO, DataChangeScope.SUBTREE);
    TestListener barListener = createListener(CONFIGURATION, TOP_BAR, DataChangeScope.SUBTREE, false);
    ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
    writeTx.put(CONFIGURATION, TOP_BAR, topLevelList(TOP_BAR_KEY));
    assertCommit(writeTx.submit());
    verifyBarOnlyAdded(topListener, allListener, fooListener, barListener);
}
Also used : ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 33 with ReadWriteTransaction

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

the class AbstractTopologyBuilder method onDataTreeChanged.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void onDataTreeChanged(final Collection<DataTreeModification<T>> changes) {
    if (this.closed) {
        LOG.trace("Transaction chain was already closed, skipping update.");
        return;
    }
    // check if the transaction chain needed to be restarted due to a previous error
    if (restartTransactionChainOnDemand()) {
        LOG.debug("The data change {} is disregarded due to restart of listener {}", changes, this);
        return;
    }
    final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
    LOG.trace("Received data change {} event with transaction {}", changes, trans.getIdentifier());
    final AtomicBoolean transactionInError = new AtomicBoolean(false);
    for (final DataTreeModification<T> change : changes) {
        try {
            routeChanged(change, trans);
        } catch (final RuntimeException exc) {
            LOG.warn("Data change {} (transaction {}) was not completely propagated to listener {}", change, trans.getIdentifier(), this, exc);
            // trans.cancel() is not supported by PingPongTransactionChain, so we just skip the problematic change
            // trans.submit() must be called first to unlock the current transaction chain, to make the chain
            // closable so we cannot exit the #onDataTreeChanged() yet
            transactionInError.set(true);
            break;
        }
    }
    Futures.addCallback(trans.submit(), new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void result) {
            // the data loss will not be able to be recovered. Thus we schedule a listener restart here
            if (transactionInError.get()) {
                LOG.warn("Transaction {} committed successfully while exception captured. Rescheduling a restart" + " of listener {}", trans.getIdentifier(), AbstractTopologyBuilder.this);
                scheduleListenerRestart();
            } else {
                LOG.trace("Transaction {} committed successfully", trans.getIdentifier());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            // we do nothing but print out the log. Transaction chain restart will be done in
            // #onTransactionChainFailed()
            LOG.error("Failed to propagate change (transaction {}) by listener {}", trans.getIdentifier(), AbstractTopologyBuilder.this, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 34 with ReadWriteTransaction

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

the class HwvtepNodeBaseListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
    HAJobScheduler.getInstance().submitJob(() -> {
        ReadWriteTransaction tx = getTx();
        try {
            processConnectedNodes(changes, tx);
            processUpdatedNodes(changes, tx);
            processDisconnectedNodes(changes, tx);
            tx.submit().get();
        } catch (InterruptedException | ExecutionException | ReadFailedException e) {
            LOG.error("Error processing data-tree changes", e);
        }
    });
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with ReadWriteTransaction

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

the class StatisticsImpl method releaseElementCountersRequestHandler.

@Override
public Future<RpcResult<ReleaseElementCountersRequestHandlerOutput>> releaseElementCountersRequestHandler(ReleaseElementCountersRequestHandlerInput input) {
    InstanceIdentifier<CounterRequests> ingressPath = InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
    InstanceIdentifier<CounterRequests> egressPath = InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
    ReadWriteTransaction tx = db.newReadWriteTransaction();
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> ingressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, ingressPath);
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> egressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, egressPath);
    CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
    CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
    try {
        Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
        Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
        if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
            LOG.warn("Couldn't read element counters config data from DB");
            StatisticsPluginImplCounters.failed_reading_counter_data_from_config.inc();
            return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Couldn't read element counters config data from DB").buildFuture();
        }
        if (!ingressRequestData.get().isPresent() && !egressRequestData.get().isPresent()) {
            LOG.warn("Handler does not exists");
            StatisticsPluginImplCounters.unknown_request_handler.inc();
            return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Handler does not exists").buildFuture();
        }
        String generatedKey = null;
        if (ingressRequestData.get().isPresent()) {
            handleReleaseTransaction(input, ingressPath, ingressRequestData, iecrcOpt.get().getCounterRequests());
            generatedKey = ingressRequestData.get().get().getGeneratedUniqueId();
        }
        if (egressRequestData.get().isPresent()) {
            handleReleaseTransaction(input, egressPath, egressRequestData, eecrcOpt.get().getCounterRequests());
            generatedKey = egressRequestData.get().get().getGeneratedUniqueId();
        }
        releaseId(generatedKey);
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
    }
    return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>success().buildFuture();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) Optional(com.google.common.base.Optional) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ExecutionException(java.util.concurrent.ExecutionException) ReleaseElementCountersRequestHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerOutput)

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