Search in sources :

Example 86 with YangInstanceIdentifier

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

the class IdentifierUtilsTest method testPeerPath.

@Test
public void testPeerPath() throws Exception {
    final YangInstanceIdentifier result = IdentifierUtils.peerPath(YII_PEER);
    assertEquals(YII_PEER, result);
}
Also used : YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 87 with YangInstanceIdentifier

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

the class MultiPathAbstractRIBSupportTest method setUp.

@Before
public void setUp() {
    this.routesMap = new HashMap<>();
    MockitoAnnotations.initMocks(this);
    this.emptyTree = Mockito.mock(DataTreeCandidateNode.class);
    this.emptySubTree = Mockito.mock(DataTreeCandidateNode.class);
    this.subTree = Mockito.mock(DataTreeCandidateNode.class);
    final DataTreeCandidateNode emptyNode = Mockito.mock(DataTreeCandidateNode.class);
    final DataTreeCandidateNode node = Mockito.mock(DataTreeCandidateNode.class);
    doReturn(null).when(this.emptyTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
    doReturn(emptyNode).when(this.emptySubTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
    doReturn(null).when(emptyNode).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
    doReturn(node).when(this.subTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
    doReturn(node).when(node).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
    final Collection<DataTreeCandidateNode> emptyCollection = new HashSet<>();
    doReturn(emptyCollection).when(node).getChildNodes();
    this.tx = Mockito.mock(DOMDataWriteTransaction.class);
    this.nlri = Mockito.mock(ContainerNode.class);
    this.attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern()))).build();
    final ContainerNode destination = Mockito.mock(ContainerNode.class);
    final ChoiceNode destinations = Mockito.mock(ChoiceNode.class);
    final ContainerNode route = Mockito.mock(ContainerNode.class);
    final Optional<?> optional = Optional.of(destination);
    final Optional<?> destinationOptional = Optional.of(destinations);
    final Optional<?> destinationsOptional = Optional.of(route);
    doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(WithdrawnRoutes.QNAME));
    doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(AdvertizedRoutes.QNAME));
    doReturn(destinationOptional).when(destination).getChild(new NodeIdentifier(DestinationType.QNAME));
    doReturn(destinationsOptional).when(destinations).getChild(new NodeIdentifier(Ipv4Prefixes.QNAME));
    doReturn(emptyCollection).when(route).getValue();
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        MultiPathAbstractRIBSupportTest.this.routesMap.remove(args[1]);
        return args[1];
    }).when(this.tx).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        final NormalizedNode<?, ?> node1 = (NormalizedNode<?, ?>) args[2];
        MultiPathAbstractRIBSupportTest.this.routesMap.put((YangInstanceIdentifier) args[1], node1);
        return args[1];
    }).when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    this.mapEntryNode = Mockito.mock(MapEntryNode.class);
}
Also used : MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 88 with YangInstanceIdentifier

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

the class SimpletxDomDelete 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();
    DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
    long writeCnt = 0;
    for (int l = 0; l < outerListElem; l++) {
        YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
        tx.delete(dsType, yid);
        writeCnt++;
        if (writeCnt == writesPerTx) {
            try {
                tx.submit().checkedGet();
                txOk++;
            } catch (final TransactionCommitFailedException e) {
                LOG.error("Transaction failed: {}", e);
                txError++;
            }
            tx = domDataBroker.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    if (writeCnt != 0) {
        try {
            tx.submit().checkedGet();
        } catch (final TransactionCommitFailedException e) {
            LOG.error("Transaction failed: {}", e);
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 89 with YangInstanceIdentifier

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

the class SimpletxDomWrite method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
    long 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++;
        if (writeCnt == writesPerTx) {
            try {
                tx.submit().checkedGet();
                txOk++;
            } catch (final TransactionCommitFailedException e) {
                LOG.error("Transaction failed", e);
                txError++;
            }
            tx = domDataBroker.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    if (writeCnt != 0) {
        try {
            tx.submit().checkedGet();
        } catch (final TransactionCommitFailedException e) {
            LOG.error("Transaction failed", e);
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) 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) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 90 with YangInstanceIdentifier

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

the class TxchainDomDelete 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();
    final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
    DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (int l = 0; l < outerListElem; l++) {
        YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
        tx.delete(dsType, yid);
        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 : DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) 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)

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