Migrate DatastoreContextIntrospectorFactory to OSGi DS
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / AbstractDatastoreContextIntrospectorFactory.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();
+}