Fix initial datastore configuration 27/93627/8
authortadei.bilan <tadei.bilan@pantheon.tech>
Fri, 6 Nov 2020 14:47:25 +0000 (16:47 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 17 Nov 2020 16:46:52 +0000 (16:46 +0000)
Shards need to be initialized with initial configuration upon creation,
otherwise they end up being reconfigured. Make sure callers are aware
of this caveat by requiring explicit properties on instantiation.

JIRA: CONTROLLER-1970
Change-Id: I3d6f96780d26435ac178ec9935f0f67befe3687a
Signed-off-by: tadei.bilan <tadei.bilan@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorFactory.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java

index c4d9c4d..4aa075f 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.cluster.datastore;
 
 import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -17,7 +18,15 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 
 abstract class AbstractDatastoreContextIntrospectorFactory implements DatastoreContextIntrospectorFactory {
     @Override
-    public final DatastoreContextIntrospector newInstance(final LogicalDatastoreType datastoreType) {
+    public DatastoreContextIntrospector newInstance(final LogicalDatastoreType datastoreType,
+            final Map<String, Object> properties) {
+        final DatastoreContextIntrospector inst = newInstance(datastoreType);
+        inst.update(properties);
+        return inst;
+    }
+
+    @VisibleForTesting
+    final DatastoreContextIntrospector newInstance(final LogicalDatastoreType datastoreType) {
         return newInstance(DatastoreContext.newBuilder()
                 .logicalStoreType(datastoreType)
                 .tempFileDirectory("./data")
index 8d2b7e7..1bc5e9d 100644 (file)
@@ -7,14 +7,25 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
-import org.eclipse.jdt.annotation.NonNull;
+import java.util.Map;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 
 /**
- * Factory for creating DatastoreContextIntrospector instances.
+ * Factory for creating {@link DatastoreContextIntrospector} instances.
  *
  * @author Thomas Pantelis
  */
+@NonNullByDefault
 public interface DatastoreContextIntrospectorFactory {
-    @NonNull DatastoreContextIntrospector newInstance(LogicalDatastoreType datastoreType);
+    /**
+     * Create a new {@link DatastoreContextIntrospector} initialized with specified properties.
+     *
+     * @param datastoreType Datastore type
+     * @param properties optional initial properties
+     * @return A new DatastoreContextIntrospector
+     */
+    DatastoreContextIntrospector newInstance(LogicalDatastoreType datastoreType,
+        @Nullable Map<String, Object> properties);
 }
index cfcffbf..1480643 100644 (file)
@@ -67,6 +67,7 @@ public final class OSGiDistributedDataStore {
 
         synchronized void updateProperties(final Map<String, Object> properties) {
             if (introspector.update(properties)) {
+                LOG.info("Distributed Datastore type {} updating context", datastoreType);
                 datastore.onDatastoreContextUpdated(introspector.newContextFactory());
             }
         }
@@ -128,10 +129,9 @@ public final class OSGiDistributedDataStore {
 
     @Activate
     void activate(final Map<String, Object> properties) {
-        configDatastore = createDatastore(LogicalDatastoreType.CONFIGURATION, "distributed-config", null);
-        operDatastore = createDatastore(LogicalDatastoreType.OPERATIONAL, "distributed-operational",
+        configDatastore = createDatastore(LogicalDatastoreType.CONFIGURATION, "distributed-config", properties, null);
+        operDatastore = createDatastore(LogicalDatastoreType.OPERATIONAL, "distributed-operational", properties,
             new ConfigurationImpl(configProvider));
-        modified(properties);
     }
 
     @Modified
@@ -150,9 +150,9 @@ public final class OSGiDistributedDataStore {
     }
 
     private DatastoreState createDatastore(final LogicalDatastoreType datastoreType, final String serviceType,
-            final Configuration config) {
+            final Map<String, Object> properties, final Configuration config) {
         LOG.info("Distributed Datastore type {} starting", datastoreType);
-        final DatastoreContextIntrospector introspector = introspectorFactory.newInstance(datastoreType);
+        final DatastoreContextIntrospector introspector = introspectorFactory.newInstance(datastoreType, properties);
         final AbstractDataStore datastore = DistributedDataStoreFactory.createInstance(actorSystemProvider,
             introspector.getContext(), introspector, snapshotRestore, config);
         datastore.setCloseable(schemaService.registerSchemaContextListener(datastore));

©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.