Convert sal-remoterpc-provided to OSGi DS 78/91278/5
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 12 Jul 2020 10:22:35 +0000 (12:22 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 12 Jul 2020 12:14:57 +0000 (12:14 +0000)
Declarative Services offer better integration with OSGi lifecycle,
use them instead of blueprint.

Change-Id: I49b41fa0fba4714f54e097820b85aefe7da67364
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-remoterpc-connector/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/OSGiRemoteOpsProvider.java [new file with mode: 0644]
opendaylight/md-sal/sal-remoterpc-connector/src/main/resources/OSGI-INF/blueprint/remote-rpc.xml [deleted file]

index e3d0668..d83880c 100644 (file)
         <dependency>
             <groupId>com.typesafe.akka</groupId>
             <artifactId>akka-osgi_2.13</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.compendium</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>com.typesafe.akka</groupId>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
+            <artifactId>osgi.cmpn</artifactId>
         </dependency>
         <dependency>
             <groupId>org.scala-lang</groupId>
diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/OSGiRemoteOpsProvider.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/OSGiRemoteOpsProvider.java
new file mode 100644 (file)
index 0000000..6053371
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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.controller.remote.rpc;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+import akka.actor.PoisonPill;
+import org.opendaylight.controller.cluster.ActorSystemProvider;
+import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
+import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+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.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(immediate = true, configurationPid = "org.opendaylight.controller.remoterpc")
+@Designate(ocd = OSGiRemoteOpsProvider.Config.class)
+public final class OSGiRemoteOpsProvider {
+    @ObjectClassDefinition()
+    public @interface Config {
+        @AttributeDefinition(name = "enable-metric-capture")
+        boolean metricCapture() default true;
+        @AttributeDefinition(name = "bounded-mailbox-capacity")
+        int boundedMailboxCapacity() default 1000;
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiRemoteOpsProvider.class);
+
+    @Reference
+    ActorSystemProvider actorSystemProvider = null;
+    @Reference
+    DOMRpcProviderService rpcProviderService = null;
+    @Reference
+    DOMRpcService rpcService = null;
+    @Reference
+    DOMActionProviderService actionProviderService = null;
+    @Reference
+    DOMActionService actionService = null;
+
+    private ActorRef opsManager;
+
+    @Activate
+    void activate(final Config config) {
+        LOG.info("Remote Operations service starting");
+        final ActorSystem actorSystem = actorSystemProvider.getActorSystem();
+        final RemoteOpsProviderConfig opsConfig = RemoteOpsProviderConfig.newInstance(actorSystem.name(),
+            config.metricCapture(), config.boundedMailboxCapacity());
+
+        opsManager = actorSystem.actorOf(OpsManager.props(rpcProviderService, rpcService, opsConfig,
+                actionProviderService, actionService), opsConfig.getRpcManagerName());
+        LOG.debug("Ops Manager started at {}", opsManager);
+        LOG.info("Remote Operations service started");
+    }
+
+    @Deactivate
+    void deactivate() {
+        LOG.info("Remote Operations service stopping");
+        LOG.debug("Stopping Ops Manager at {}", opsManager);
+        opsManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
+        opsManager = null;
+        LOG.info("Remote Operations services stopped");
+    }
+}
diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/resources/OSGI-INF/blueprint/remote-rpc.xml b/opendaylight/md-sal/sal-remoterpc-connector/src/main/resources/OSGI-INF/blueprint/remote-rpc.xml
deleted file mode 100644 (file)
index c33659a..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
-    odl:restart-dependents-on-updates="false" odl:use-default-for-reference-types="true">
-
-  <cm:property-placeholder persistent-id="org.opendaylight.controller.remoterpc" update-strategy="none">
-    <cm:default-properties>
-      <cm:property name="enable-metric-capture" value="false"/>
-      <cm:property name="bounded-mailbox-capacity" value="1000"/>
-    </cm:default-properties>
-  </cm:property-placeholder>
-
-  <reference id="actorSystemProvider" interface="org.opendaylight.controller.cluster.ActorSystemProvider" />
-  <reference id="domRpcService" interface="org.opendaylight.mdsal.dom.api.DOMRpcService"/>
-  <reference id="domRpcRegistry" interface="org.opendaylight.mdsal.dom.api.DOMRpcProviderService"/>
-  <reference id="domActionService" interface="org.opendaylight.mdsal.dom.api.DOMActionService"/>
-  <reference id="domActionRegistry" interface="org.opendaylight.mdsal.dom.api.DOMActionProviderService"/>
-
-  <bean id="actorSystem" factory-ref="actorSystemProvider" factory-method="getActorSystem"/>
-
-  <bean id="remoteOpsProviderConfig" class="org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig"
-          factory-method="newInstance">
-    <argument>
-      <bean factory-ref="actorSystem" factory-method="name"/>
-    </argument>
-    <argument value="${enable-metric-capture}"/>
-    <argument value="${bounded-mailbox-capacity}"/>
-  </bean>
-
-  <bean id="remoteOpsProvider" class="org.opendaylight.controller.remote.rpc.RemoteOpsProviderFactory"
-          factory-method="createInstance" init-method="start" destroy-method="close">
-    <argument ref="domRpcRegistry"/>
-    <argument ref="domRpcService"/>
-    <argument ref="actorSystem"/>
-    <argument ref="remoteOpsProviderConfig"/>
-    <argument ref="domActionRegistry"/>
-    <argument ref="domActionService"/>
-  </bean>
-
-</blueprint>

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.