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);
}
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);
}
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);
}
}
}
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);
}
}
}
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));
}
Aggregations