2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.entityownership;
10 import com.google.common.annotations.Beta;
12 import java.util.Optional;
13 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
14 import org.opendaylight.controller.cluster.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfigReader;
15 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
16 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
17 import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
18 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration;
19 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
20 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration;
21 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
22 import org.osgi.service.component.annotations.Activate;
23 import org.osgi.service.component.annotations.Component;
24 import org.osgi.service.component.annotations.Deactivate;
25 import org.osgi.service.component.annotations.Reference;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 @Component(immediate = true, configurationPid = "org.opendaylight.controller.cluster.entity.owner.selection.strategies",
31 property = "type=default")
32 public final class OSGiDistributedEntityOwnershipService implements DOMEntityOwnershipService {
33 private static final Logger LOG = LoggerFactory.getLogger(OSGiDistributedEntityOwnershipService.class);
35 @Reference(target = "(type=distributed-operational)")
36 DistributedDataStoreInterface operDatastore = null;
38 private DistributedEntityOwnershipService delegate;
41 public DOMEntityOwnershipCandidateRegistration registerCandidate(final DOMEntity entity)
42 throws CandidateAlreadyRegisteredException {
43 return delegate.registerCandidate(entity);
47 public DOMEntityOwnershipListenerRegistration registerListener(final String entityType,
48 final DOMEntityOwnershipListener listener) {
49 return delegate.registerListener(entityType, listener);
53 public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
54 return delegate.getOwnershipState(forEntity);
58 public boolean isCandidateRegistered(final DOMEntity forEntity) {
59 return delegate.isCandidateRegistered(forEntity);
63 // FIXME: 3.0.0: properties are keyed by String, this should be Map<String, Object>
64 void activate(final Map<Object, Object> properties) {
65 LOG.info("Distributed Entity Ownership Service starting");
66 delegate = DistributedEntityOwnershipService.start(operDatastore.getActorUtils(),
67 EntityOwnerSelectionStrategyConfigReader.loadStrategyWithConfig(properties));
68 LOG.info("Distributed Entity Ownership Service started");
73 LOG.info("Distributed Entity Ownership Service stopping");
75 LOG.info("Distributed Entity Ownership Service stopped");