Search in sources :

Example 1 with DataSchemaContextNode

use of org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode 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 DataSchemaContextNode

use of org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode 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)

Aggregations

DataSchemaContextNode (org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode)2 DataSchemaContextTree (org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree)2 DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2