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 / DistributedOperationalDataStoreProviderModule.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 DistributedOperationalDataStoreProviderModule extends
10     org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedOperationalDataStoreProviderModule {
11     private BundleContext bundleContext;
12
13     public DistributedOperationalDataStoreProviderModule(
14         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
15         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
16         super(identifier, dependencyResolver);
17     }
18
19     public DistributedOperationalDataStoreProviderModule(
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.DistributedOperationalDataStoreProviderModule 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(AbstractDistributedOperationalDataStoreProviderModule oldModule) {
34         return true;
35     }
36
37     @Override
38     public java.lang.AutoCloseable createInstance() {
39
40         OperationalProperties props = getOperationalProperties();
41         if(props == null) {
42             props = new OperationalProperties();
43         }
44
45         DatastoreContext datastoreContext = DatastoreContext.newBuilder()
46                 .logicalStoreType(LogicalDatastoreType.OPERATIONAL)
47                 .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue())
48                 .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue())
49                 .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize().getValue().intValue())
50                 .maxShardDataStoreExecutorQueueSize(props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue())
51                 .shardTransactionIdleTimeoutInMinutes(props.getShardTransactionIdleTimeoutInMinutes().getValue())
52                 .operationTimeoutInSeconds(props.getOperationTimeoutInSeconds().getValue())
53                 .shardJournalRecoveryLogBatchSize(props.getShardJournalRecoveryLogBatchSize().
54                         getValue().intValue())
55                 .shardSnapshotBatchCount(props.getShardSnapshotBatchCount().getValue().intValue())
56                 .shardSnapshotDataThresholdPercentage(props.getShardSnapshotDataThresholdPercentage().getValue().intValue())
57                 .shardHeartbeatIntervalInMillis(props.getShardHeartbeatIntervalInMillis().getValue())
58                 .shardInitializationTimeoutInSeconds(props.getShardInitializationTimeoutInSeconds().getValue())
59                 .shardLeaderElectionTimeoutInSeconds(props.getShardLeaderElectionTimeoutInSeconds().getValue())
60                 .shardTransactionCommitTimeoutInSeconds(
61                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
62                 .shardTransactionCommitQueueCapacity(
63                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
64                 .persistent(props.getPersistent().booleanValue())
65                 .shardIsolatedLeaderCheckIntervalInMillis(
66                         props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
67                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
68                 .transactionCreationInitialRateLimit(props.getTransactionCreationInitialRateLimit().getValue())
69                 .shardBatchedModificationCount(props.getShardBatchedModificationCount().getValue().intValue())
70                 .shardCommitQueueExpiryTimeoutInSeconds(
71                         props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue())
72                 .transactionDebugContextEnabled(props.getTransactionDebugContextEnabled())
73                 .customRaftPolicyImplementation(props.getCustomRaftPolicyImplementation())
74                 .shardSnapshotChunkSize(props.getShardSnapshotChunkSize().getValue().intValue())
75                 .build();
76
77         return DistributedDataStoreFactory.createInstance(getOperationalSchemaServiceDependency(),
78                 datastoreContext, DatastoreSnapshotRestore.instance().getAndRemove(datastoreContext.getDataStoreType()),
79                 getOperationalActorSystemProviderDependency().getActorSystem(), bundleContext);
80     }
81
82     public void setBundleContext(BundleContext bundleContext) {
83         this.bundleContext = bundleContext;
84     }
85
86 }