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);
}
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);
}
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());
}
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;
}
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));
}
Aggregations