Convert sal-netconf-connector to OSGi DS 13/91813/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 2 Aug 2020 08:07:40 +0000 (10:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 2 Aug 2020 08:12:21 +0000 (10:12 +0200)
This is a very simple blueprint container, eliminate it in favor
of OSGi components.

Change-Id: I1b6636bc94b77cf33fb79fec65168c18b3c9794d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/pom.xml
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/impl/OSGiSchemaResourceManager.java [new file with mode: 0644]
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/OSGiBaseNetconfSchemas.java [new file with mode: 0644]
netconf/sal-netconf-connector/src/main/resources/OSGI-INF/blueprint/sal-netconf-connector.xml [deleted file]

index 2eda0f6d2f71043bbe71be9c8830f1b70ea0dcd9..f32904128b5cf1791dc89dc9a17533c1affc6c2b 100644 (file)
       <scope>provided</scope>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>org.xmlunit</groupId>
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 (file)
index 0000000..e605677
--- /dev/null
@@ -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");
+    }
+}
index 8874abb0a7b7cdfd83a64effab4452c5f0e29d45..73077849cba91ddd0dca9213a983af21711f86a0 100644 (file)
@@ -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 (file)
index 0000000..a632745
--- /dev/null
@@ -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 (file)
index 423664c..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2019 FRINX s.r.o. 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
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:use-default-for-reference-types="true">
-
-    <reference id="parserFactory"
-               interface="org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory"/>
-
-    <bean id="deviceActionFactory"
-          class="org.opendaylight.netconf.sal.connect.netconf.DeviceActionFactoryImpl">
-    </bean>
-
-    <service ref="deviceActionFactory"
-             interface="org.opendaylight.netconf.sal.connect.api.DeviceActionFactory"
-             odl:type="default"/>
-
-    <bean id="schemaResourceManager"
-          class="org.opendaylight.netconf.sal.connect.impl.DefaultSchemaResourceManager">
-        <argument ref="parserFactory"/>
-    </bean>
-
-    <service ref="schemaResourceManager"
-             interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
-
-    <bean id="baseNetconfSchemas"
-          class="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas">
-        <argument ref="parserFactory"/>
-    </bean>
-
-    <service ref="baseNetconfSchemas"
-             interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
-</blueprint>