Bug 4564: Implement datastore restore from backup file
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / config / yang / config / distributed_datastore_provider / DistributedConfigDataStoreProviderModule.java
1 package org.opendaylight.controller.config.yang.config.distributed_datastore_provider;
2
3 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
4 import org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore;
5 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory;
6 import org.osgi.framework.BundleContext;
7
8 public class DistributedConfigDataStoreProviderModule extends
9     org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedConfigDataStoreProviderModule {
10     private BundleContext bundleContext;
11
12     public DistributedConfigDataStoreProviderModule(
13         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
14         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
15         super(identifier, dependencyResolver);
16     }
17
18     public DistributedConfigDataStoreProviderModule(
19         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
20         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
21         org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule oldModule,
22         java.lang.AutoCloseable oldInstance) {
23         super(identifier, dependencyResolver, oldModule, oldInstance);
24     }
25
26     @Override
27     public void customValidation() {
28         // add custom validation form module attributes here.
29     }
30
31     @Override
32     public boolean canReuseInstance(AbstractDistributedConfigDataStoreProviderModule oldModule) {
33         return true;
34     }
35
36     @Override
37     public java.lang.AutoCloseable createInstance() {
38         ConfigProperties props = getConfigProperties();
39         if(props == null) {
40             props = new ConfigProperties();
41         }
42
43         DatastoreContext datastoreContext = DatastoreContext.newBuilder()
44                 .dataStoreType("config")
45                 .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue())
46                 .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue())
47                 .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize().getValue().intValue())
48                 .maxShardDataStoreExecutorQueueSize(props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue())
49                 .shardTransactionIdleTimeoutInMinutes(props.getShardTransactionIdleTimeoutInMinutes().getValue())
50                 .operationTimeoutInSeconds(props.getOperationTimeoutInSeconds().getValue())
51                 .shardJournalRecoveryLogBatchSize(props.getShardJournalRecoveryLogBatchSize().
52                         getValue().intValue())
53                 .shardSnapshotBatchCount(props.getShardSnapshotBatchCount().getValue().intValue())
54                 .shardSnapshotDataThresholdPercentage(props.getShardSnapshotDataThresholdPercentage().getValue().intValue())
55                 .shardHeartbeatIntervalInMillis(props.getShardHeartbeatIntervalInMillis().getValue())
56                 .shardInitializationTimeoutInSeconds(props.getShardInitializationTimeoutInSeconds().getValue())
57                 .shardLeaderElectionTimeoutInSeconds(props.getShardLeaderElectionTimeoutInSeconds().getValue())
58                 .shardTransactionCommitTimeoutInSeconds(
59                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
60                 .shardTransactionCommitQueueCapacity(
61                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
62                 .persistent(props.getPersistent().booleanValue())
63                 .shardIsolatedLeaderCheckIntervalInMillis(
64                     props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
65                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
66                 .transactionCreationInitialRateLimit(props.getTransactionCreationInitialRateLimit().getValue())
67                 .shardBatchedModificationCount(props.getShardBatchedModificationCount().getValue().intValue())
68                 .shardCommitQueueExpiryTimeoutInSeconds(
69                         props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue())
70                 .transactionDebugContextEnabled(props.getTransactionDebugContextEnabled())
71                 .customRaftPolicyImplementation(props.getCustomRaftPolicyImplementation())
72                 .shardSnapshotChunkSize(props.getShardSnapshotChunkSize().getValue().intValue())
73                 .build();
74
75         return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(),
76                 datastoreContext, DatastoreSnapshotRestore.instance().getAndRemove(datastoreContext.getDataStoreType()),
77                 getConfigActorSystemProviderDependency().getActorSystem(), bundleContext);
78     }
79
80     public void setBundleContext(BundleContext bundleContext) {
81         this.bundleContext = bundleContext;
82     }
83 }