use of org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree in project yangtools by opendaylight.
the class InMemoryDataTree method internalSetSchemaContext.
/*
* This method is synchronized to guard against user attempting to install
* multiple contexts. Otherwise it runs in a lock-free manner.
*/
private synchronized void internalSetSchemaContext(final EffectiveModelContext newSchemaContext) {
requireNonNull(newSchemaContext);
LOG.debug("Following schema contexts will be attempted {}", newSchemaContext);
final DataSchemaContextTree contextTree = DataSchemaContextTree.from(newSchemaContext);
final Optional<DataSchemaContextNode<?>> rootContextNode = contextTree.findChild(getRootPath());
if (!rootContextNode.isPresent()) {
LOG.warn("Could not find root {} in new schema context, not upgrading", getRootPath());
return;
}
final DataSchemaNode rootSchemaNode = rootContextNode.get().getDataSchemaNode();
if (!(rootSchemaNode instanceof DataNodeContainer)) {
LOG.warn("Root {} resolves to non-container type {}, not upgrading", getRootPath(), rootSchemaNode);
return;
}
final ModificationApplyOperation rootNode = getOperation(rootSchemaNode);
DataTreeState currentState;
DataTreeState newState;
do {
currentState = currentState();
newState = currentState.withSchemaContext(newSchemaContext, rootNode);
// TODO: can we lower this to compareAndSwapRelease?
} while (!STATE.compareAndSet(this, currentState, newState));
}
use of org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree in project netconf by opendaylight.
the class ReadDataTransactionUtil method prepareDataByParamWithDef.
private static NormalizedNode prepareDataByParamWithDef(final NormalizedNode result, final YangInstanceIdentifier path, final WithDefaultsParam withDefa, final EffectiveModelContext ctx) {
boolean trim;
switch(withDefa) {
case TRIM:
trim = true;
break;
case EXPLICIT:
trim = false;
break;
default:
throw new RestconfDocumentedException("Unsupported with-defaults value " + withDefa.paramValue());
}
final DataSchemaContextTree baseSchemaCtxTree = DataSchemaContextTree.from(ctx);
final DataSchemaNode baseSchemaNode = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
if (result instanceof ContainerNode) {
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) baseSchemaNode);
buildCont(builder, (ContainerNode) result, baseSchemaCtxTree, path, trim);
return builder.build();
} else {
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) baseSchemaNode);
buildMapEntryBuilder(builder, (MapEntryNode) result, baseSchemaCtxTree, path, trim, ((ListSchemaNode) baseSchemaNode).getKeyDefinition());
return builder.build();
}
}
use of org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree in project netconf by opendaylight.
the class PutDataTransactionUtilTest method setUp.
@Before
public void setUp() throws Exception {
schema = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
final QName containerQname = QName.create(baseQName, "player");
final QName leafQname = QName.create(baseQName, "gap");
final QName listQname = QName.create(baseQName, "playlist");
final QName listKeyQname = QName.create(baseQName, "name");
final NodeIdentifierWithPredicates nodeWithKey = NodeIdentifierWithPredicates.of(listQname, listKeyQname, "name of band");
final NodeIdentifierWithPredicates nodeWithKey2 = NodeIdentifierWithPredicates.of(listQname, listKeyQname, "name of band 2");
final DataSchemaContextTree tree = DataSchemaContextTree.from(schema);
iid = YangInstanceIdentifier.builder().node(baseQName).node(containerQname).node(leafQname).build();
schemaNode = tree.findChild(iid).orElseThrow().getDataSchemaNode();
iid2 = YangInstanceIdentifier.builder().node(baseQName).build();
schemaNode2 = tree.findChild(iid2).orElseThrow().getDataSchemaNode();
iid3 = YangInstanceIdentifier.builder().node(baseQName).node(listQname).node(nodeWithKey).build();
schemaNode3 = tree.findChild(iid3).orElseThrow().getDataSchemaNode();
buildLeaf = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(leafQname)).withValue(0.2).build();
final ContainerNode buildPlayerCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(containerQname)).withChild(buildLeaf).build();
buildBaseCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).build();
final LeafNode<Object> content = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "name"))).withValue("name of band").build();
final LeafNode<Object> content2 = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "description"))).withValue("band description").build();
buildListEntry = Builders.mapEntryBuilder().withNodeIdentifier(nodeWithKey).withChild(content).withChild(content2).build();
final LeafNode<Object> content3 = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "name"))).withValue("name of band 2").build();
final LeafNode<Object> content4 = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "description"))).withValue("band description 2").build();
final MapEntryNode buildListEntry2 = Builders.mapEntryBuilder().withNodeIdentifier(nodeWithKey2).withChild(content3).withChild(content4).build();
final MapNode buildList = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(listQname)).withChild(buildListEntry).withChild(buildListEntry2).build();
buildBaseContWithList = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildList).build();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).lock();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).unlock();
}
use of org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree in project yangtools by opendaylight.
the class InMemoryDataTreeFactory method getRootSchemaNode.
private static DataSchemaNode getRootSchemaNode(final EffectiveModelContext schemaContext, final YangInstanceIdentifier rootPath) {
final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
final Optional<DataSchemaContextNode<?>> rootContextNode = contextTree.findChild(rootPath);
checkArgument(rootContextNode.isPresent(), "Failed to find root %s in schema context", rootPath);
final DataSchemaNode rootSchemaNode = rootContextNode.get().getDataSchemaNode();
checkArgument(rootSchemaNode instanceof DataNodeContainer, "Root %s resolves to non-container type %s", rootPath, rootSchemaNode);
return rootSchemaNode;
}
use of org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree in project netconf by opendaylight.
the class BrokerFacade method prepareDataByParamWithDef.
private NormalizedNode prepareDataByParamWithDef(final NormalizedNode result, final YangInstanceIdentifier path, final String withDefa) {
boolean trim;
switch(withDefa) {
case "trim":
trim = true;
break;
case "explicit":
trim = false;
break;
default:
throw new RestconfDocumentedException("Bad value used with with-defaults parameter : " + withDefa);
}
final EffectiveModelContext ctx = controllerContext.getGlobalSchema();
final DataSchemaContextTree baseSchemaCtxTree = DataSchemaContextTree.from(ctx);
final DataSchemaNode baseSchemaNode = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
if (result instanceof ContainerNode) {
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) baseSchemaNode);
buildCont(builder, (ContainerNode) result, baseSchemaCtxTree, path, trim);
return builder.build();
}
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) baseSchemaNode);
buildMapEntryBuilder(builder, (MapEntryNode) result, baseSchemaCtxTree, path, trim, ((ListSchemaNode) baseSchemaNode).getKeyDefinition());
return builder.build();
}
Aggregations