From: Robert Varga Date: Fri, 17 Jul 2020 17:21:41 +0000 (+0200) Subject: Migrate DatastoreContextIntrospectorFactory to OSGi DS X-Git-Tag: v2.0.4~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=b65e66f7b1bafb0d0c5fbe1c569835eb890f672a Migrate DatastoreContextIntrospectorFactory to OSGi DS 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 --- 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 index 0000000000..c4d9c4da99 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java @@ -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(); +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java index 0d5fc9db0f..a6f5f01930 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java @@ -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 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, Method>> entry: DATA_STORE_PROP_INFO.entrySet()) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorFactory.java index 0a2c85525b..8d2b7e7391 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorFactory.java @@ -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 index 0000000000..5f56457a04 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DefaultDatastoreContextIntrospectorFactory.java @@ -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 index 0000000000..8332bcf29e --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDatastoreContextIntrospectorFactory.java @@ -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"); + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml b/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml index ef7bc2e54c..18fcc75254 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml @@ -12,14 +12,9 @@ - - - - - - + diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java index 40ceda29ce..ba62f8dba1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java @@ -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() {