Search in sources :

Example 1 with DataSchemaContextTree

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));
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) DataSchemaContextNode(org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) DataSchemaContextTree(org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree)

Example 2 with DataSchemaContextTree

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();
    }
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) DataSchemaContextTree(org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree)

Example 3 with DataSchemaContextTree

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();
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) DataSchemaContextTree(org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree) Before(org.junit.Before)

Example 4 with DataSchemaContextTree

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;
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) DataSchemaContextNode(org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) DataSchemaContextTree(org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree)

Example 5 with DataSchemaContextTree

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();
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) DataSchemaContextTree(org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

DataSchemaContextTree (org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree)5 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)4 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)3 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)2 DataSchemaContextNode (org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode)2 DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)2 Before (org.junit.Before)1 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)1 QName (org.opendaylight.yangtools.yang.common.QName)1 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1