Search in sources :

Example 61 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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 62 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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 63 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class BindingDOMMountPointServiceAdapter method getMountPoint.

@Override
public Optional<MountPoint> getMountPoint(InstanceIdentifier<?> mountPoint) {
    YangInstanceIdentifier domPath = codec.toYangInstanceIdentifierBlocking(mountPoint);
    Optional<DOMMountPoint> domMount = mountService.getMountPoint(domPath);
    if (domMount.isPresent()) {
        return Optional.<MountPoint>fromNullable(bindingMountpoints.getUnchecked(domMount.get()));
    }
    return Optional.absent();
}
Also used : DOMMountPoint(org.opendaylight.controller.md.sal.dom.api.DOMMountPoint) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) DOMMountPoint(org.opendaylight.controller.md.sal.dom.api.DOMMountPoint) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 64 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class AbstractForwardedDataBroker method toBinding.

protected Set<InstanceIdentifier<?>> toBinding(final InstanceIdentifier<?> path, final Set<YangInstanceIdentifier> normalized) {
    final Set<InstanceIdentifier<?>> hashSet = new HashSet<>();
    for (final YangInstanceIdentifier normalizedPath : normalized) {
        try {
            final Optional<InstanceIdentifier<? extends DataObject>> potential = getCodec().toBinding(normalizedPath);
            if (potential.isPresent()) {
                final InstanceIdentifier<? extends DataObject> binding = potential.get();
                hashSet.add(binding);
            } else if (normalizedPath.getLastPathArgument() instanceof YangInstanceIdentifier.AugmentationIdentifier) {
                hashSet.add(path);
            }
        } catch (final DeserializationException e) {
            LOG.warn("Failed to transform {}, omitting it", normalizedPath, e);
        }
    }
    return hashSet;
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DeserializationException(org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException) HashSet(java.util.HashSet)

Example 65 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class PruningDataTreeModificationTest method testDeleteOnException.

@Test
public void testDeleteOnException() {
    YangInstanceIdentifier path = CarsModel.BASE_PATH;
    doThrow(SchemaValidationFailedException.class).when(mockModification).delete(path);
    pruningDataTreeModification.delete(path);
    verify(mockModification, times(1)).delete(path);
}
Also used : YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)187 Test (org.junit.Test)111 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)34 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 ActorRef (akka.actor.ActorRef)19 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)19 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 TestActorRef (akka.testkit.TestActorRef)14 TestKit (akka.testkit.javadsl.TestKit)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)12 ArrayList (java.util.ArrayList)11 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)10 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)10 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)10 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)10 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)9 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9