Migrate DatastoreContextIntrospectorFactory to OSGi DS 97/91397/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 17 Jul 2020 17:21:41 +0000 (19:21 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 29 Jul 2020 01:01:19 +0000 (01:01 +0000)
We are slowly converting hand-written blueprint config to OSGi DS,
so that we can end up ditching blueprint completely. This is the
next small step towards that goal.

Change-Id: I398d71344bccfef752128c561d6d2ff851edc5c2
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 [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.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/DefaultDatastoreContextIntrospectorFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDatastoreContextIntrospectorFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java

diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java
new file mode 100644 (file)
index 0000000..c4d9c4d
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 Inocybe Technologies 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.datastore;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev140612.DataStorePropertiesContainer;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+
+abstract class AbstractDatastoreContextIntrospectorFactory implements DatastoreContextIntrospectorFactory {
+    @Override
+    public final DatastoreContextIntrospector newInstance(final LogicalDatastoreType datastoreType) {
+        return newInstance(DatastoreContext.newBuilder()
+                .logicalStoreType(datastoreType)
+                .tempFileDirectory("./data")
+                .build());
+    }
+
+    @VisibleForTesting
+    final @NonNull DatastoreContextIntrospector newInstance(final DatastoreContext context) {
+        final DataStorePropertiesContainer defaultPropsContainer = (DataStorePropertiesContainer)
+                serializer().fromNormalizedNode(YangInstanceIdentifier.of(DataStorePropertiesContainer.QNAME),
+                    ImmutableNodes.containerNode(DataStorePropertiesContainer.QNAME)).getValue();
+
+        return new DatastoreContextIntrospector(context, defaultPropsContainer);
+    }
+
+    abstract BindingNormalizedNodeSerializer serializer();
+}
index 0d5fc9db0f3a7974bdc6e1999fba802ce4ce30b0..a6f5f019307097835d3bc699ccb723da737d0e97 100644 (file)
@@ -34,15 +34,12 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.WordUtils;
 import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev140612.DataStoreProperties;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev140612.DataStorePropertiesContainer;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.common.Uint64;
 import org.opendaylight.yangtools.yang.common.Uint8;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -212,10 +209,7 @@ public class DatastoreContextIntrospector {
     private Map<String, Object> currentProperties;
 
     public DatastoreContextIntrospector(final DatastoreContext context,
-            final BindingNormalizedNodeSerializer bindingSerializer) {
-        final DataStorePropertiesContainer defaultPropsContainer = (DataStorePropertiesContainer)
-                bindingSerializer.fromNormalizedNode(YangInstanceIdentifier.of(DataStorePropertiesContainer.QNAME),
-                ImmutableNodes.containerNode(DataStorePropertiesContainer.QNAME)).getValue();
+            final DataStorePropertiesContainer defaultPropsContainer) {
 
         final Builder builder = DatastoreContext.newBuilderFrom(context);
         for (Entry<String, Entry<Class<?>, Method>> entry: DATA_STORE_PROP_INFO.entrySet()) {
index 0a2c85525b5790b14955cae9c09d60b851c0da9d..8d2b7e7391b94f2ed0748d26e84e07cdfdcb2870 100644 (file)
@@ -7,10 +7,7 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 
 /**
@@ -18,22 +15,6 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
  *
  * @author Thomas Pantelis
  */
-public class DatastoreContextIntrospectorFactory {
-    private final BindingNormalizedNodeSerializer serializer;
-
-    public DatastoreContextIntrospectorFactory(final BindingNormalizedNodeSerializer serializer) {
-        this.serializer = requireNonNull(serializer);
-    }
-
-    public DatastoreContextIntrospector newInstance(final LogicalDatastoreType datastoreType) {
-        return newInstance(DatastoreContext.newBuilder()
-                .logicalStoreType(datastoreType)
-                .tempFileDirectory("./data")
-                .build());
-    }
-
-    @VisibleForTesting
-    DatastoreContextIntrospector newInstance(final DatastoreContext context) {
-        return new DatastoreContextIntrospector(context, serializer);
-    }
+public interface DatastoreContextIntrospectorFactory {
+    @NonNull DatastoreContextIntrospector newInstance(LogicalDatastoreType datastoreType);
 }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultDatastoreContextIntrospectorFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultDatastoreContextIntrospectorFactory.java
new file mode 100644 (file)
index 0000000..5f56457
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Inocybe Technologies 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.datastore;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+
+@Beta
+public final class DefaultDatastoreContextIntrospectorFactory extends AbstractDatastoreContextIntrospectorFactory {
+    private final BindingNormalizedNodeSerializer serializer;
+
+    public DefaultDatastoreContextIntrospectorFactory(final BindingNormalizedNodeSerializer serializer) {
+        this.serializer = requireNonNull(serializer);
+    }
+
+    @Override
+    BindingNormalizedNodeSerializer serializer() {
+        return serializer;
+    }
+}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDatastoreContextIntrospectorFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDatastoreContextIntrospectorFactory.java
new file mode 100644 (file)
index 0000000..8332bcf
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.datastore;
+
+import static com.google.common.base.Verify.verifyNotNull;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+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, service = DatastoreContextIntrospectorFactory.class)
+public final class OSGiDatastoreContextIntrospectorFactory extends AbstractDatastoreContextIntrospectorFactory {
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiDatastoreContextIntrospectorFactory.class);
+
+    @Reference
+    volatile BindingNormalizedNodeSerializer serializer = null;
+
+    @Override
+    BindingNormalizedNodeSerializer serializer() {
+        return verifyNotNull(serializer);
+    }
+
+    @Activate
+    @SuppressWarnings("static-method")
+    void activate() {
+        LOG.info("Datastore Context Introspector activated");
+    }
+
+    @Deactivate
+    @SuppressWarnings("static-method")
+    void deactivate() {
+        LOG.info("Datastore Context Introspector deactivated");
+    }
+}
index ef7bc2e54c7cf162ea41ec5c687c78e1cdc72274..18fcc75254073cf423e03755ee1cc54a5c2dec16 100644 (file)
 
   <odl:static-reference id="schemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService" />
 
-  <reference id="bindingSerializer" interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer"/>
-
-  <bean id="introspectorFactory" class="org.opendaylight.controller.cluster.datastore.DatastoreContextIntrospectorFactory">
-    <argument ref="bindingSerializer"/>
-  </bean>
-
   <!-- Datastore properties -->
   <reference id="actorSystemProvider" interface="org.opendaylight.controller.cluster.ActorSystemProvider"/>
+  <reference id="introspectorFactory" interface="org.opendaylight.controller.cluster.datastore.DatastoreContextIntrospectorFactory"/>
 
   <cm:cm-properties id="datastoreProps" persistent-id="org.opendaylight.controller.cluster.datastore"/>
 
index 40ceda29ce787a1f331ddc28fd137d1dda53661d..ba62f8dba15312762905318735c053701b8ef8f2 100644 (file)
@@ -32,8 +32,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
  * @author Thomas Pantelis
  */
 public class DatastoreContextIntrospectorTest {
-    static final DatastoreContextIntrospectorFactory INTROSPECTOR_FACTORY = new DatastoreContextIntrospectorFactory(
-        new BindingCodecContext(BindingRuntimeHelpers.createRuntimeContext(DataStorePropertiesContainer.class)));
+    static final AbstractDatastoreContextIntrospectorFactory INTROSPECTOR_FACTORY =
+            new DefaultDatastoreContextIntrospectorFactory(new BindingCodecContext(
+                BindingRuntimeHelpers.createRuntimeContext(DataStorePropertiesContainer.class)));
 
     @Test
     public void testYangDefaults() {