Only one node should be master of initializing the DCS store
Change-Id: I4862eb1401203d5ab65034bd0cccd3a4bd3f8de9
diff --git a/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java b/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java
index 074f8d4..a12a72f 100644
--- a/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java
+++ b/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java
@@ -15,6 +15,10 @@
*/
package org.onosproject.config.impl;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.Leadership;
+import org.onosproject.cluster.LeadershipService;
+import org.onosproject.cluster.NodeId;
import org.onosproject.config.DynamicConfigEvent;
import org.onosproject.config.DynamicConfigListener;
import org.onosproject.config.DynamicConfigService;
@@ -63,6 +67,7 @@
extends AbstractListenerManager<DynamicConfigEvent, DynamicConfigListener>
implements DynamicConfigService, RpcRegistry {
+ protected static final String DCS_STORE_INIT = "dcs-store-init";
private final Logger log = getLogger(getClass());
private final DynamicConfigStoreDelegate storeDelegate = new InternalStoreDelegate();
@@ -72,12 +77,24 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected SchemaContextProvider contextProvider;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected LeadershipService leadershipService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected ClusterService clusterService;
+
+
+
// FIXME is it OK this is not using the Store?
private ConcurrentHashMap<String, RpcService> handlerRegistry = new ConcurrentHashMap<>();
@Activate
public void activate() {
- initStore();
+ NodeId localnodeId = clusterService.getLocalNode().id();
+ Leadership leadership = leadershipService.runForLeadership(DCS_STORE_INIT);
+ if (leadership.leaderNodeId().equals(localnodeId)) {
+ initStore();
+ }
store.setDelegate(storeDelegate);
eventDispatcher.addSink(DynamicConfigEvent.class, listenerRegistry);
log.info("Started");