From a603f2024c3df4bafccc7bc220445f106da7a4e1 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 2 Aug 2020 10:07:40 +0200 Subject: [PATCH] Convert sal-netconf-connector to OSGi DS This is a very simple blueprint container, eliminate it in favor of OSGi components. Change-Id: I1b6636bc94b77cf33fb79fec65168c18b3c9794d Signed-off-by: Robert Varga --- netconf/sal-netconf-connector/pom.xml | 4 ++ .../impl/OSGiSchemaResourceManager.java | 48 ++++++++++++++++++ .../netconf/DeviceActionFactoryImpl.java | 6 ++- .../mapping/OSGiBaseNetconfSchemas.java | 50 +++++++++++++++++++ .../blueprint/sal-netconf-connector.xml | 40 --------------- 5 files changed, 106 insertions(+), 42 deletions(-) create mode 100644 netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/impl/OSGiSchemaResourceManager.java create mode 100644 netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/OSGiBaseNetconfSchemas.java delete mode 100644 netconf/sal-netconf-connector/src/main/resources/OSGI-INF/blueprint/sal-netconf-connector.xml diff --git a/netconf/sal-netconf-connector/pom.xml b/netconf/sal-netconf-connector/pom.xml index 2eda0f6d2f..f32904128b 100644 --- a/netconf/sal-netconf-connector/pom.xml +++ b/netconf/sal-netconf-connector/pom.xml @@ -109,6 +109,10 @@ provided true + + org.osgi + osgi.cmpn + org.xmlunit diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/impl/OSGiSchemaResourceManager.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/impl/OSGiSchemaResourceManager.java new file mode 100644 index 0000000000..e6056778c9 --- /dev/null +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/impl/OSGiSchemaResourceManager.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.netconf.sal.connect.impl; + +import com.google.common.annotations.Beta; +import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager; +import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Beta +@Component(immediate = true) +public final class OSGiSchemaResourceManager implements SchemaResourceManager { + private static final Logger LOG = LoggerFactory.getLogger(OSGiSchemaResourceManager.class); + + @Reference + YangParserFactory parserFactory; + + private DefaultSchemaResourceManager delegate; + + @Override + public SchemaResourcesDTO getSchemaResources(final NetconfNode node, final Object nodeId) { + return delegate.getSchemaResources(node, nodeId); + } + + @Activate + void activate() { + delegate = new DefaultSchemaResourceManager(parserFactory); + LOG.info("Schema Resource Manager started"); + } + + @Deactivate + void deactivate() { + delegate = null; + LOG.info("Schema Resource Manager stopped"); + } +} diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java index 8874abb0a7..73077849cb 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.sal.connect.netconf; import static java.util.Objects.requireNonNull; @@ -15,6 +14,7 @@ import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; +import javax.inject.Singleton; import org.opendaylight.mdsal.dom.api.DOMActionResult; import org.opendaylight.mdsal.dom.api.DOMActionService; import org.opendaylight.mdsal.dom.api.DOMActionServiceExtension; @@ -27,6 +27,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,8 +37,9 @@ import org.slf4j.LoggerFactory; * transforms replied NETCONF message to action result, and using {@link RemoteDeviceCommunicator} that is responsible * for sending of built RPCs to NETCONF client. */ +@Singleton +@Component(immediate = true, property = "type=default") public class DeviceActionFactoryImpl implements DeviceActionFactory { - private static final Logger LOG = LoggerFactory.getLogger(DeviceActionFactoryImpl.class); @Override diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/OSGiBaseNetconfSchemas.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/OSGiBaseNetconfSchemas.java new file mode 100644 index 0000000000..a632745205 --- /dev/null +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/OSGiBaseNetconfSchemas.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.netconf.sal.connect.netconf.schema.mapping; + +import com.google.common.annotations.Beta; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Beta +@Component(immediate = true) +public final class OSGiBaseNetconfSchemas implements BaseNetconfSchemas { + private static final Logger LOG = LoggerFactory.getLogger(OSGiBaseNetconfSchemas.class); + + @Reference + YangParserFactory parserFactory; + + private DefaultBaseNetconfSchemas delegate; + + @Override + public BaseSchema getBaseSchema() { + return delegate.getBaseSchema(); + } + + @Override + public BaseSchema getBaseSchemaWithNotifications() { + return delegate.getBaseSchemaWithNotifications(); + } + + @Activate + void activate() { + delegate = new DefaultBaseNetconfSchemas(parserFactory); + LOG.info("Base NETCONF Schemas started"); + } + + @Deactivate + void deactivate() { + delegate = null; + LOG.info("Base NETCONF Schemas stopped"); + } +} diff --git a/netconf/sal-netconf-connector/src/main/resources/OSGI-INF/blueprint/sal-netconf-connector.xml b/netconf/sal-netconf-connector/src/main/resources/OSGI-INF/blueprint/sal-netconf-connector.xml deleted file mode 100644 index 423664c4e1..0000000000 --- a/netconf/sal-netconf-connector/src/main/resources/OSGI-INF/blueprint/sal-netconf-connector.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -- 2.36.6