Search in sources :

Example 6 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfToNotificationTest method testToNotificationFunction.

@Test
public void testToNotificationFunction() throws Exception {
    final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), false);
    messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
    final DOMNotification domNotification = messageTransformer.toNotification(userNotification);
    final ContainerNode root = domNotification.getBody();
    assertNotNull(root);
    assertEquals(6, root.body().size());
    assertEquals("user-visited-page", root.getIdentifier().getNodeType().getLocalName());
    assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2015-10-23T09:42:27.67175+00:00").toInstant(), ((DOMEvent) domNotification).getEventInstant());
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 7 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfDeviceRpcTest method setUp.

@Before
public void setUp() throws Exception {
    NetconfMessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
    final NetconfMessage reply = new NetconfMessage(XmlUtil.readXmlToDocument("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\">\n" + "<data>\n" + "</data>\n" + "</rpc-reply>"));
    RpcResult<NetconfMessage> result = RpcResultBuilder.success(reply).build();
    doReturn(Futures.immediateFuture(result)).when(communicator).sendRequest(any(NetconfMessage.class), any(QName.class));
    rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, communicator, transformer);
    type = QName.create("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "get-config");
    expectedReply = transformer.toRpcResult(reply, type);
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) QName(org.opendaylight.yangtools.yang.common.QName) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) Before(org.junit.Before)

Example 8 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfDataTreeServiceImplTest method setUp.

@Before
public void setUp() {
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult())).when(rpcService).invokeRpc(any(), any());
    netconService = getNetconService();
    final EffectiveModelContext model = BindingRuntimeHelpers.createEffectiveModel(IetfNetconfService.class, NetconfState.class);
    netconfMessageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(model), true, BASE_SCHEMAS.getBaseSchema());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Before(org.junit.Before)

Example 9 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfDevice method onRemoteSessionUp.

@Override
public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities, final NetconfDeviceCommunicator listener) {
    // SchemaContext setup has to be performed in a dedicated thread since
    // we are in a netty thread in this method
    // Yang models are being downloaded in this method and it would cause a
    // deadlock if we used the netty thread
    // http://netty.io/wiki/thread-model.html
    setConnected(true);
    LOG.debug("{}: Session to remote device established with {}", id, remoteSessionCapabilities);
    final BaseSchema baseSchema = resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported());
    final NetconfDeviceRpc initRpc = new NetconfDeviceRpc(baseSchema.getEffectiveModelContext(), listener, new NetconfMessageTransformer(baseSchema.getMountPointContext(), false, baseSchema));
    final ListenableFuture<DeviceSources> sourceResolverFuture = processingExecutor.submit(new DeviceSourcesResolver(id, baseSchema, initRpc, remoteSessionCapabilities, stateSchemasResolver));
    if (shouldListenOnSchemaChange(remoteSessionCapabilities)) {
        registerToBaseNetconfStream(initRpc, listener);
    }
    // Set up the SchemaContext for the device
    final ListenableFuture<EffectiveModelContext> futureSchema = Futures.transformAsync(sourceResolverFuture, deviceSources -> assembleSchemaContext(deviceSources, remoteSessionCapabilities), processingExecutor);
    // Potentially acquire mount point list and interpret it
    final ListenableFuture<MountPointContext> futureContext = Futures.transformAsync(futureSchema, schemaContext -> createMountPointContext(schemaContext, baseSchema, listener), processingExecutor);
    Futures.addCallback(futureContext, new FutureCallback<MountPointContext>() {

        @Override
        public void onSuccess(final MountPointContext result) {
            handleSalInitializationSuccess(result, remoteSessionCapabilities, getDeviceSpecificRpc(result, listener, baseSchema), listener);
        }

        @Override
        public void onFailure(final Throwable cause) {
            LOG.warn("{}: Unexpected error resolving device sources", id, cause);
            // No more sources, fail or try to reconnect
            if (cause instanceof EmptySchemaContextException) {
                if (nodeOptional != null && nodeOptional.getIgnoreMissingSchemaSources().getAllowed()) {
                    eventExecutor.schedule(() -> {
                        LOG.warn("Reconnection is allowed! This can lead to unexpected errors at runtime.");
                        LOG.warn("{} : No more sources for schema context.", id);
                        LOG.info("{} : Try to remount device.", id);
                        onRemoteSessionDown();
                        salFacade.onDeviceReconnected(remoteSessionCapabilities, node);
                    }, nodeOptional.getIgnoreMissingSchemaSources().getReconnectTime().toJava(), TimeUnit.MILLISECONDS);
                    return;
                }
            }
            handleSalInitializationFailure(cause, listener);
            salFacade.onDeviceFailed(cause);
        }
    }, MoreExecutors.directExecutor());
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) BaseSchema(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

NetconfMessageTransformer (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer)9 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)8 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)5 Before (org.junit.Before)3 Test (org.junit.Test)3 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)3 NetconfDeviceRpc (org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc)3 DOMNotification (org.opendaylight.mdsal.dom.api.DOMNotification)2 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 InputStream (java.io.InputStream)1 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)1 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)1 BaseSchema (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema)1 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)1 QName (org.opendaylight.yangtools.yang.common.QName)1