use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class NormalizedNodePrunerTest method testInnerListNodeWithFullPathNotPruned.
@Test
public void testInnerListNodeWithFullPathNotPruned() throws IOException {
YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME).node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).node(TestModel.INNER_LIST_QNAME).build();
NormalizedNodePruner pruner = prunerFullSchema(path);
MapNode input = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild(ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build();
NormalizedNodeWriter.forStreamWriter(pruner).write(input);
NormalizedNode<?, ?> actual = pruner.normalizedNode();
assertEquals("normalizedNode", input, actual);
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DOMBrokerPerformanceTest method measureSeparateWritesOneLevel.
private void measureSeparateWritesOneLevel(final int txNum, final int innerNum) throws Exception {
final List<DOMDataReadWriteTransaction> transactions = measure("Txs:" + txNum + " Allocate", () -> {
List<DOMDataReadWriteTransaction> builder = new ArrayList<>(txNum);
for (int i = 0; i < txNum; i++) {
DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
builder.add(writeTx);
}
return builder;
});
assertEquals(txNum, transactions.size());
measure("Txs:" + txNum + " Writes:1", (Callable<Void>) () -> {
int index = 0;
for (DOMDataReadWriteTransaction writeTx : transactions) {
// Writes /test/outer-list/i in writeTx
writeTx.put(OPERATIONAL, outerListPath(index), outerList(index));
index++;
}
return null;
});
measure("Txs:" + txNum + " Writes:" + innerNum, (Callable<Void>) () -> {
int index = 0;
for (DOMDataReadWriteTransaction writeTx : transactions) {
// Writes /test/outer-list/i in writeTx
YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(index)).node(TestModel.INNER_LIST_QNAME).build();
writeTx.put(OPERATIONAL, path, ImmutableNodes.mapNodeBuilder(TestModel.INNER_LIST_QNAME).build());
for (int j = 0; j < innerNum; j++) {
YangInstanceIdentifier innerPath = YangInstanceIdentifier.builder(path).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
writeTx.put(OPERATIONAL, innerPath, ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)));
}
index++;
}
return null;
});
measure("Txs:" + txNum + " Submit, Finish", (Callable<Void>) () -> {
List<ListenableFuture<?>> allFutures = measure(txNum + " Submits", () -> {
List<ListenableFuture<?>> builder = new ArrayList<>(txNum);
for (DOMDataReadWriteTransaction tx : transactions) {
builder.add(tx.submit());
}
return builder;
});
Futures.allAsList(allFutures).get();
return null;
});
final DOMDataReadTransaction readTx = measure("Txs:1 (ro), Allocate", (Callable<DOMDataReadTransaction>) () -> domBroker.newReadOnlyTransaction());
measure("Txs:1 (ro) Reads:" + txNum + " (1-level)", (Callable<Void>) () -> {
for (int i = 0; i < txNum; i++) {
ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, outerListPath(i));
assertTrue("outerList/" + i, potential.get().isPresent());
}
return null;
});
measure("Txs:1 (ro) Reads:" + txNum * innerNum + " (2-level)", (Callable<Void>) () -> {
for (int i = 0; i < txNum; i++) {
for (int j = 0; j < innerNum; j++) {
YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(i)).node(TestModel.INNER_LIST_QNAME).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, path);
assertTrue("outer-list/" + i + "/inner-list/" + j, potential.get().isPresent());
}
}
return null;
});
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DataStoreAppConfigDefaultXMLReader method createDefaultInstance.
@SuppressWarnings("unchecked")
public T createDefaultInstance(final FallbackConfigProvider fallback) throws ConfigXMLReaderException, URISyntaxException, ParserConfigurationException, XMLStreamException, SAXException, IOException {
YangInstanceIdentifier yangPath = bindingSerializer.toYangInstanceIdentifier(bindingContext.appConfigPath);
LOG.debug("{}: Creating app config instance from path {}, Qname: {}", logName, yangPath, bindingContext.bindingQName);
checkNotNull(schemaService, "%s: Could not obtain the SchemaService OSGi service", logName);
SchemaContext schemaContext = schemaService.getGlobalContext();
Module module = schemaContext.findModule(bindingContext.bindingQName.getModule()).orElse(null);
checkNotNull(module, "%s: Could not obtain the module schema for namespace %s, revision %s", logName, bindingContext.bindingQName.getNamespace(), bindingContext.bindingQName.getRevision());
DataSchemaNode dataSchema = module.getDataChildByName(bindingContext.bindingQName);
checkNotNull(dataSchema, "%s: Could not obtain the schema for %s", logName, bindingContext.bindingQName);
checkCondition(bindingContext.schemaType.isAssignableFrom(dataSchema.getClass()), "%s: Expected schema type %s for %s but actual type is %s", logName, bindingContext.schemaType, bindingContext.bindingQName, dataSchema.getClass());
NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigXMLFile(schemaContext, dataSchema);
if (dataNode == null) {
dataNode = fallback.get(schemaService.getGlobalContext(), dataSchema);
}
DataObject appConfig = bindingSerializer.fromNormalizedNode(yangPath, dataNode).getValue();
// This shouldn't happen but need to handle it in case...
checkNotNull(appConfig, "%s: Could not create instance for app config binding %s", logName, bindingContext.appConfigBindingClass);
return (T) appConfig;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class SimpletxDomRead 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));
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
try {
Optional<NormalizedNode<?, ?>> optionalDataObject = submitFuture.checkedGet();
if (optionalDataObject != null && optionalDataObject.isPresent()) {
NormalizedNode<?, ?> ret = optionalDataObject.get();
LOG.trace("optionalDataObject is {}", ret);
txOk++;
} else {
txError++;
LOG.warn("optionalDataObject is either null or .isPresent is false");
}
} catch (final ReadFailedException e) {
LOG.warn("failed to ....", e);
txError++;
}
}
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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++;
}
}
}
}
Aggregations