Convert DatastoreSnapshotRestore to OSGi DS
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / AbstractDatastoreContextIntrospectorFactory.java
1 /*
2  * Copyright (c) 2018 Inocybe Technologies and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
10 import com.google.common.annotations.VisibleForTesting;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev140612.DataStorePropertiesContainer;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
17
18 abstract class AbstractDatastoreContextIntrospectorFactory implements DatastoreContextIntrospectorFactory {
19     @Override
20     public final DatastoreContextIntrospector newInstance(final LogicalDatastoreType datastoreType) {
21         return newInstance(DatastoreContext.newBuilder()
22                 .logicalStoreType(datastoreType)
23                 .tempFileDirectory("./data")
24                 .build());
25     }
26
27     @VisibleForTesting
28     final @NonNull DatastoreContextIntrospector newInstance(final DatastoreContext context) {
29         final DataStorePropertiesContainer defaultPropsContainer = (DataStorePropertiesContainer)
30                 serializer().fromNormalizedNode(YangInstanceIdentifier.of(DataStorePropertiesContainer.QNAME),
31                     ImmutableNodes.containerNode(DataStorePropertiesContainer.QNAME)).getValue();
32
33         return new DatastoreContextIntrospector(context, defaultPropsContainer);
34     }
35
36     abstract BindingNormalizedNodeSerializer serializer();
37 }