use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.
the class NetconfDevice method handleSalInitializationSuccess.
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void handleSalInitializationSuccess(final MountPointContext result, final NetconfSessionPreferences remoteSessionCapabilities, final DOMRpcService deviceRpc, final RemoteDeviceCommunicator<NetconfMessage> listener) {
// since salFacade.onDeviceDisconnected was already called.
if (connected) {
this.messageTransformer = new NetconfMessageTransformer(result, true, resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()));
// salFacade.onDeviceConnected has to be called before the notification handler is initialized
this.salFacade.onDeviceConnected(result, remoteSessionCapabilities, deviceRpc, this.deviceActionFactory == null ? null : this.deviceActionFactory.createDeviceAction(this.messageTransformer, listener, result.getEffectiveModelContext()));
this.notificationHandler.onRemoteSchemaUp(this.messageTransformer);
LOG.info("{}: Netconf connector initialized successfully", id);
} else {
LOG.warn("{}: Device communicator was closed before schema setup finished.", id);
}
}
use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer 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.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer 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));
}
use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.
the class NetconfToNotificationTest method testMostRecentWrongYangModel.
@Test
public void testMostRecentWrongYangModel() throws Exception {
final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), true);
messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
assertThrows(IllegalArgumentException.class, () -> messageTransformer.toNotification(userNotification));
}
use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.
the class NetconfNestedNotificationTest method testNestedNotificationToNotificationFunction.
@Test
public void testNestedNotificationToNotificationFunction() throws Exception {
final EffectiveModelContext schemaContext = getNotificationSchemaContext(Collections.singleton("/schemas/nested-notification.yang"));
final NetconfMessage notificationMessage = prepareNotification("/nested-notification-payload.xml");
NetconfMessageTransformer messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
final DOMNotification domNotification = messageTransformer.toNotification(notificationMessage);
final ContainerNode root = domNotification.getBody();
assertNotNull(root);
assertEquals(1, root.body().size());
assertEquals("interface-enabled", root.getIdentifier().getNodeType().getLocalName());
assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2008-07-08T00:01:00Z").toInstant(), ((DOMEvent) domNotification).getEventInstant());
assertEquals(Absolute.of(INTERFACES_QNAME, INTERFACE_QNAME, INTERFACE_ENABLED_NOTIFICATION_QNAME), domNotification.getType());
}
Aggregations