Search in sources :

Example 6 with LogicalDatastoreType

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType 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 7 with LogicalDatastoreType

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

the class TxchainDomRead method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
        for (int l = 0; l < outerListElem; l++) {
            YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
            Optional<NormalizedNode<?, ?>> optionalDataObject;
            CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
            try {
                optionalDataObject = submitFuture.checkedGet();
                if (optionalDataObject != null && optionalDataObject.isPresent()) {
                    txOk++;
                }
            } catch (final ReadFailedException e) {
                LOG.warn("failed to ....", e);
                txError++;
            }
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 8 with LogicalDatastoreType

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

the class TxchainDomWrite method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
    DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (MapEntryNode element : this.list) {
        YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues()));
        if (oper == StartTestInput.Operation.PUT) {
            tx.put(dsType, yid, element);
        } else {
            tx.merge(dsType, yid, element);
        }
        writeCnt++;
        // Start performing the operation; submit the transaction at every n-th operation
        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;
        }
    }
    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 : DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 9 with LogicalDatastoreType

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

the class BindingDOMDataBrokerAdapterTest method testClusteredDataChangeListernerRegisteration.

@Test
public void testClusteredDataChangeListernerRegisteration() {
    final BindingToNormalizedNodeCodec codec = new BindingToNormalizedNodeCodec(this.classLoadingStrategy, this.codecRegistry);
    try (BindingDOMDataBrokerAdapter bindingDOMDataBrokerAdapter = new BindingDOMDataBrokerAdapter(this.dataBroker, codec)) {
        Mockito.when(this.codecRegistry.toYangInstanceIdentifier(TOP_PATH)).thenReturn(this.yangInstanceIdentifier);
        final ArgumentCaptor<ClusteredDOMDataChangeListener> clusteredDOMListener = ArgumentCaptor.forClass(ClusteredDOMDataChangeListener.class);
        final ArgumentCaptor<LogicalDatastoreType> logicalDatastoreType = ArgumentCaptor.forClass(LogicalDatastoreType.class);
        final ArgumentCaptor<AsyncDataBroker.DataChangeScope> dataChangeScope = ArgumentCaptor.forClass(AsyncDataBroker.DataChangeScope.class);
        final ArgumentCaptor<YangInstanceIdentifier> yangIidCapture = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
        final TestListener listener = new TestListener();
        bindingDOMDataBrokerAdapter.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, TOP_PATH, listener, AsyncDataBroker.DataChangeScope.BASE);
        Mockito.verify(this.dataBroker).registerDataChangeListener(logicalDatastoreType.capture(), yangIidCapture.capture(), clusteredDOMListener.capture(), dataChangeScope.capture());
    }
}
Also used : AsyncDataBroker(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker) BindingToNormalizedNodeCodec(org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec) BindingDOMDataBrokerAdapter(org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ClusteredDOMDataChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataChangeListener) Test(org.junit.Test)

Example 10 with LogicalDatastoreType

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

the class DomInmemoryDataBrokerModule method createInstance.

@Override
public java.lang.AutoCloseable createInstance() {
    // Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
    DOMStore operStore = getOperationalDataStoreDependency();
    if (operStore == null) {
        // we will default to InMemoryDOMDataStore creation
        operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency());
    }
    DOMStore configStore = getConfigDataStoreDependency();
    if (configStore == null) {
        // we will default to InMemoryDOMDataStore creation
        configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency());
    }
    final Map<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
    datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
    datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
    /*
         * We use an executor for commit ListenableFuture callbacks that favors reusing available
         * threads over creating new threads at the expense of execution time. The assumption is
         * that most ListenableFuture callbacks won't execute a lot of business logic where we want
         * it to run quicker - many callbacks will likely just handle error conditions and do
         * nothing on success. The executor queue capacity is bounded and, if the capacity is
         * reached, subsequent submitted tasks will block the caller.
         */
    ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(getMaxDataBrokerFutureCallbackPoolSize(), getMaxDataBrokerFutureCallbackQueueSize(), "CommitFutures", SerializedDOMDataBroker.class);
    final List<AbstractMXBean> mBeans = Lists.newArrayList();
    final DurationStatisticsTracker commitStatsTracker;
    /*
         * We use a single-threaded executor for commits with a bounded queue capacity. If the
         * queue capacity is reached, subsequent commit tasks will be rejected and the commits will
         * fail. This is done to relieve back pressure. This should be an extreme scenario - either
         * there's deadlock(s) somewhere and the controller is unstable or some rogue component is
         * continuously hammering commits too fast or the controller is just over-capacity for the
         * system it's running on.
         */
    ExecutorService commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(getMaxDataBrokerCommitQueueSize(), "WriteTxCommit", SerializedDOMDataBroker.class);
    SerializedDOMDataBroker sdb = new SerializedDOMDataBroker(datastores, new DeadlockDetectingListeningExecutorService(commitExecutor, TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, listenableFutureExecutor));
    commitStatsTracker = sdb.getCommitStatsTracker();
    final AbstractMXBean commitExecutorStatsMXBean = ThreadExecutorStatsMXBeanImpl.create(commitExecutor, "CommitExecutorStats", JMX_BEAN_TYPE, null);
    if (commitExecutorStatsMXBean != null) {
        mBeans.add(commitExecutorStatsMXBean);
    }
    if (commitStatsTracker != null) {
        final CommitStatsMXBeanImpl commitStatsMXBean = new CommitStatsMXBeanImpl(commitStatsTracker, JMX_BEAN_TYPE);
        commitStatsMXBean.registerMBean();
        mBeans.add(commitStatsMXBean);
    }
    final AbstractMXBean commitFutureStatsMXBean = ThreadExecutorStatsMXBeanImpl.create(listenableFutureExecutor, "CommitFutureExecutorStats", JMX_BEAN_TYPE, null);
    if (commitFutureStatsMXBean != null) {
        mBeans.add(commitFutureStatsMXBean);
    }
    sdb.setCloseable(() -> mBeans.forEach(AbstractMXBean::unregisterMBean));
    return sdb;
}
Also used : AbstractMXBean(org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean) DOMStore(org.opendaylight.controller.sal.core.spi.data.DOMStore) DeadlockDetectingListeningExecutorService(org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) DurationStatisticsTracker(org.opendaylight.yangtools.util.DurationStatisticsTracker) EnumMap(java.util.EnumMap) SerializedDOMDataBroker(org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker) DeadlockDetectingListeningExecutorService(org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService) CommitStatsMXBeanImpl(org.opendaylight.controller.md.sal.dom.broker.impl.jmx.CommitStatsMXBeanImpl)

Aggregations

LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)27 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)12 Optional (com.google.common.base.Optional)11 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 DOMStore (org.opendaylight.controller.sal.core.spi.data.DOMStore)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)6 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)6 TestExec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec)6 OuterList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList)6 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)6 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 InMemoryDOMDataStore (org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore)5 Nonnull (javax.annotation.Nonnull)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 QName (org.opendaylight.yangtools.yang.common.QName)4 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3