Search in sources :

Example 1 with EmptyMountPointContext

use of org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext in project yangtools by opendaylight.

the class AbstractMountPointContextFactory method createMountPointContext.

@Override
protected final MountPointContext createMountPointContext(final EffectiveModelContext schemaContext, final ContainerNode mountData) {
    checkArgument(SCHEMA_MOUNTS.equals(mountData.getIdentifier()), "Unexpected top-level container %s", mountData);
    final DataContainerChild mountPoint = mountData.childByArg(MOUNT_POINT);
    if (mountPoint == null) {
        LOG.debug("mount-point list not present in {}", mountData);
        return new EmptyMountPointContext(schemaContext);
    }
    checkArgument(mountPoint instanceof MapNode, "mount-point list %s is not a MapNode", mountPoint);
    return new ImmutableMountPointContext(schemaContext, ((MapNode) mountPoint).body().stream().map(entry -> {
        final String moduleName = entry.findChildByArg(MODULE).map(mod -> {
            checkArgument(mod instanceof LeafNode, "Unexpected module leaf %s", mod);
            final Object value = mod.body();
            checkArgument(value instanceof String, "Unexpected module leaf value %s", value);
            return (String) value;
        }).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry));
        final Iterator<? extends Module> it = schemaContext.findModules(moduleName).iterator();
        checkArgument(it.hasNext(), "Failed to find a module named %s", moduleName);
        final QNameModule module = it.next().getQNameModule();
        return new MountPointDefinition(MountPointIdentifier.of(QName.create(module, entry.findChildByArg(LABEL).map(lbl -> {
            checkArgument(lbl instanceof LeafNode, "Unexpected label leaf %s", lbl);
            final Object value = lbl.body();
            checkArgument(value instanceof String, "Unexpected label leaf value %s", value);
            return (String) value;
        }).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry)))), entry.findChildByArg(CONFIG).map(cfg -> {
            checkArgument(cfg instanceof LeafNode, "Unexpected config leaf %s", cfg);
            final Object value = cfg.body();
            checkArgument(value instanceof Boolean, "Unexpected config leaf value %s", cfg);
            return (Boolean) value;
        }).orElse(Boolean.TRUE), getSchema(entry.findChildByArg(SCHEMA_REF).orElseThrow(() -> new IllegalArgumentException("Missing schema-ref choice in " + entry))));
    }).collect(Collectors.toList()), this::createContextFactory);
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) SchemaMountConstants(org.opendaylight.yangtools.rfc8528.model.api.SchemaMountConstants) LoggerFactory(org.slf4j.LoggerFactory) ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) MountPointIdentifier(org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Objects.requireNonNull(java.util.Objects.requireNonNull) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MountPointContextFactory(org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) Immutable(org.opendaylight.yangtools.concepts.Immutable) ImmutableSet(com.google.common.collect.ImmutableSet) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Module(org.opendaylight.yangtools.yang.model.api.Module) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Collectors(java.util.stream.Collectors) AbstractSimpleIdentifiable(org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) QName(org.opendaylight.yangtools.yang.common.QName) Beta(com.google.common.annotations.Beta) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 2 with EmptyMountPointContext

use of org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext in project yangtools by opendaylight.

the class AbstractDynamicMountPointContextFactory method createContext.

@Override
public final MountPointContext createContext(final Map<ContainerName, MountPointChild> libraryContainers, final MountPointChild schemaMounts) throws YangParserException {
    for (Entry<ContainerName, MountPointChild> entry : libraryContainers.entrySet()) {
        // Context for the specific code word
        final Optional<EffectiveModelContext> optLibContext = findSchemaForLibrary(entry.getKey());
        if (optLibContext.isEmpty()) {
            LOG.debug("YANG Library context for mount point {} container {} not found", getIdentifier(), entry.getKey());
            continue;
        }
        final NormalizedNode libData;
        try {
            libData = entry.getValue().normalizeTo(optLibContext.get());
        } catch (IOException e) {
            throw new YangParserException("Failed to interpret yang-library data", e);
        }
        if (!(libData instanceof ContainerNode)) {
            throw new YangParserException("Invalid yang-library non-container " + libData);
        }
        final EffectiveModelContext schemaContext = bindLibrary(entry.getKey(), (ContainerNode) libData);
        if (schemaMounts == null) {
            return new EmptyMountPointContext(schemaContext);
        }
        final NormalizedNode mountData;
        try {
            mountData = schemaMounts.normalizeTo(schemaContext);
        } catch (IOException e) {
            throw new YangParserException("Failed to interpret schema-mount data", e);
        }
        if (!(mountData instanceof ContainerNode)) {
            throw new YangParserException("Invalid schema-mount non-container " + mountData);
        }
        return createMountPointContext(schemaContext, (ContainerNode) mountData);
    }
    throw new YangParserException("Failed to interpret " + libraryContainers);
}
Also used : ContainerName(org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants.ContainerName) MountPointChild(org.opendaylight.yangtools.rfc8528.data.api.MountPointChild) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) IOException(java.io.IOException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangParserException(org.opendaylight.yangtools.yang.parser.api.YangParserException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 3 with EmptyMountPointContext

use of org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext in project netconf by opendaylight.

the class NetconfDevice method createMountPointContext.

private ListenableFuture<MountPointContext> createMountPointContext(final EffectiveModelContext schemaContext, final BaseSchema baseSchema, final NetconfDeviceCommunicator listener) {
    final MountPointContext emptyContext = new EmptyMountPointContext(schemaContext);
    if (schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isEmpty()) {
        return Futures.immediateFuture(emptyContext);
    }
    // Create a temporary RPC invoker and acquire the mount point tree
    LOG.debug("{}: Acquiring available mount points", id);
    final NetconfDeviceRpc deviceRpc = new NetconfDeviceRpc(schemaContext, listener, new NetconfMessageTransformer(emptyContext, false, baseSchema));
    return Futures.transform(deviceRpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_GET_QNAME, Builders.containerBuilder().withNodeIdentifier(NETCONF_GET_NODEID).withChild(NetconfMessageTransformUtil.toFilterStructure(RFC8528_SCHEMA_MOUNTS, schemaContext)).build()), rpcResult -> processSchemaMounts(rpcResult, emptyContext), MoreExecutors.directExecutor());
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)

Example 4 with EmptyMountPointContext

use of org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext in project netconf by opendaylight.

the class MountPointEndToEndTest method testMaster.

private MasterSalFacade testMaster() throws InterruptedException, ExecutionException, TimeoutException {
    LOG.info("****** Testing master");
    writeNetconfNode(TEST_DEFAULT_SUBDIR, masterDataBroker);
    final MasterSalFacade masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS);
    final ArrayList<String> capabilities = Lists.newArrayList(NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString());
    masterSalFacade.onDeviceConnected(new EmptyMountPointContext(deviceSchemaContext), NetconfSessionPreferences.fromStrings(capabilities), deviceRpcService.getRpcService());
    DOMMountPoint masterMountPoint = awaitMountPoint(masterMountPointService);
    LOG.info("****** Testing master DOMDataBroker operations");
    testDOMDataBrokerOperations(getDOMDataBroker(masterMountPoint));
    LOG.info("****** Testing master DOMRpcService");
    testDOMRpcService(getDOMRpcService(masterMountPoint));
    return masterSalFacade;
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint)

Example 5 with EmptyMountPointContext

use of org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext in project netconf by opendaylight.

the class NetconfBaseOpsTest method setUp.

@Before
public void setUp() throws Exception {
    final InputStream okStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_ok.xml");
    final InputStream dataStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_get.xml");
    final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
    final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
    final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
    final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
    callback = new NetconfRpcFutureCallback("prefix", id);
    baseOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) Before(org.junit.Before)

Aggregations

EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)17 NetconfMessageTransformer (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer)7 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)7 Before (org.junit.Before)6 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)6 Test (org.junit.Test)5 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)4 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 NetconfSessionPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)3 NetconfBaseOps (org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps)3 DOMNotification (org.opendaylight.mdsal.dom.api.DOMNotification)2 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)2 NetconfDeviceRpc (org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc)2 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)2 QName (org.opendaylight.yangtools.yang.common.QName)2 Beta (com.google.common.annotations.Beta)1 ToStringHelper (com.google.common.base.MoreObjects.ToStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableSet (com.google.common.collect.ImmutableSet)1