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