From 573c2787dab036b72f7e2a020216d5398888d122 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 30 Jul 2020 16:56:40 +0200 Subject: [PATCH] Convert sal-distributed-eos to OSGi DS This is a simple component, there is just no need to use blueprint. JIRA: CONTROLLER-1882 Change-Id: If64faff3cab0e66303b5e2d5db4af7f9ea2a2b50 Signed-off-by: Robert Varga --- .../md-sal/sal-distributed-eos/pom.xml | 2 +- ...OSGiDistributedEntityOwnershipService.java | 77 +++++++++++++++++++ .../OSGI-INF/blueprint/distributed-eos.xml | 26 ------- 3 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 opendaylight/md-sal/sal-distributed-eos/src/main/java/org/opendaylight/controller/cluster/entityownership/OSGiDistributedEntityOwnershipService.java delete mode 100644 opendaylight/md-sal/sal-distributed-eos/src/main/resources/OSGI-INF/blueprint/distributed-eos.xml diff --git a/opendaylight/md-sal/sal-distributed-eos/pom.xml b/opendaylight/md-sal/sal-distributed-eos/pom.xml index 98b0fdfca4..bfc1888706 100644 --- a/opendaylight/md-sal/sal-distributed-eos/pom.xml +++ b/opendaylight/md-sal/sal-distributed-eos/pom.xml @@ -19,7 +19,7 @@ org.osgi - org.osgi.core + osgi.cmpn 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 index 0000000000..cceae6c06c --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-eos/src/main/java/org/opendaylight/controller/cluster/entityownership/OSGiDistributedEntityOwnershipService.java @@ -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 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 + void activate(final Map 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 index aeb10b5082..0000000000 --- a/opendaylight/md-sal/sal-distributed-eos/src/main/resources/OSGI-INF/blueprint/distributed-eos.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - -- 2.36.6