Convert sal-distributed-eos to OSGi DS 72/91772/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 14:56:40 +0000 (16:56 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 15:35:10 +0000 (17:35 +0200)
This is a simple component, there is just no need to use blueprint.

JIRA: CONTROLLER-1882
Change-Id: If64faff3cab0e66303b5e2d5db4af7f9ea2a2b50
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-eos/pom.xml
opendaylight/md-sal/sal-distributed-eos/src/main/java/org/opendaylight/controller/cluster/entityownership/OSGiDistributedEntityOwnershipService.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-eos/src/main/resources/OSGI-INF/blueprint/distributed-eos.xml [deleted file]

index 98b0fdf..bfc1888 100644 (file)
@@ -19,7 +19,7 @@
 
     <dependency>
       <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.core</artifactId>
+      <artifactId>osgi.cmpn</artifactId>
     </dependency>
 
     <dependency>
diff --git a/opendaylight/md-sal/sal-distributed-eos/src/main/java/org/opendaylight/controller/cluster/entityownership/OSGiDistributedEntityOwnershipService.java b/opendaylight/md-sal/sal-distributed-eos/src/main/java/org/opendaylight/controller/cluster/entityownership/OSGiDistributedEntityOwnershipService.java
new file mode 100644 (file)
index 0000000..cceae6c
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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.cluster.entityownership;
+
+import com.google.common.annotations.Beta;
+import java.util.Map;
+import java.util.Optional;
+import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
+import org.opendaylight.controller.cluster.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfigReader;
+import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
+import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
+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, configurationPid = "org.opendaylight.controller.cluster.entity.owner.selection.strategies",
+    property = "type=default")
+public final class OSGiDistributedEntityOwnershipService implements DOMEntityOwnershipService {
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiDistributedEntityOwnershipService.class);
+
+    @Reference(target = "(type=distributed-operational)")
+    DistributedDataStoreInterface operDatastore = null;
+
+    private DistributedEntityOwnershipService delegate;
+
+    @Override
+    public DOMEntityOwnershipCandidateRegistration registerCandidate(final DOMEntity entity)
+            throws CandidateAlreadyRegisteredException {
+        return delegate.registerCandidate(entity);
+    }
+
+    @Override
+    public DOMEntityOwnershipListenerRegistration registerListener(final String entityType,
+            final DOMEntityOwnershipListener listener) {
+        return delegate.registerListener(entityType, listener);
+    }
+
+    @Override
+    public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
+        return delegate.getOwnershipState(forEntity);
+    }
+
+    @Override
+    public boolean isCandidateRegistered(final DOMEntity forEntity) {
+        return delegate.isCandidateRegistered(forEntity);
+    }
+
+    @Activate
+    // FIXME: 3.0.0: properties are keyed by String, this should be Map<String, Object>
+    void activate(final Map<Object, Object> properties) {
+        LOG.info("Distributed Entity Ownership Service starting");
+        delegate = DistributedEntityOwnershipService.start(operDatastore.getActorUtils(),
+            EntityOwnerSelectionStrategyConfigReader.loadStrategyWithConfig(properties));
+        LOG.info("Distributed Entity Ownership Service started");
+    }
+
+    @Deactivate
+    void deactivate() {
+        LOG.info("Distributed Entity Ownership Service stopping");
+        delegate.close();
+        LOG.info("Distributed Entity Ownership Service stopped");
+    }
+}
diff --git a/opendaylight/md-sal/sal-distributed-eos/src/main/resources/OSGI-INF/blueprint/distributed-eos.xml b/opendaylight/md-sal/sal-distributed-eos/src/main/resources/OSGI-INF/blueprint/distributed-eos.xml
deleted file mode 100644 (file)
index aeb10b5..0000000
+++ /dev/null
@@ -1,26 +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.2.0">
-
-  <!-- Distributed EntityOwnershipService -->
-  <cm:cm-properties id="strategiesProps" persistent-id="org.opendaylight.controller.cluster.entity.owner.selection.strategies" />
-
-  <reference id="operDatastore" interface="org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface" odl:type="distributed-operational"/>
-
-  <bean id="selectionStrategyConfig" class="org.opendaylight.controller.cluster.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfigReader"
-          factory-method="loadStrategyWithConfig">
-    <argument ref="strategiesProps"/>
-  </bean>
-
-  <bean id="distributedEntityOwnershipService" class="org.opendaylight.controller.cluster.entityownership.DistributedEntityOwnershipService"
-          factory-method="start" destroy-method="close">
-    <argument>
-      <bean factory-ref="operDatastore" factory-method="getActorUtils"/>
-    </argument>
-    <argument ref="selectionStrategyConfig"/>
-  </bean>
-
-  <service ref="distributedEntityOwnershipService" interface="org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService"
-        odl:type="default"/>
-</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.