Merge "BUG-2600 Dynamic schemas in netconf server"
[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 java.util.concurrent.TimeUnit;
4
5 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
6 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory;
7 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties;
8 import org.osgi.framework.BundleContext;
9
10 import scala.concurrent.duration.Duration;
11
12 public class DistributedConfigDataStoreProviderModule extends
13     org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedConfigDataStoreProviderModule {
14     private BundleContext bundleContext;
15
16     public DistributedConfigDataStoreProviderModule(
17         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
18         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
19         super(identifier, dependencyResolver);
20     }
21
22     public DistributedConfigDataStoreProviderModule(
23         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
24         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
25         org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule oldModule,
26         java.lang.AutoCloseable oldInstance) {
27         super(identifier, dependencyResolver, oldModule, oldInstance);
28     }
29
30     @Override
31     public void customValidation() {
32         // add custom validation form module attributes here.
33     }
34
35     @Override
36     public java.lang.AutoCloseable createInstance() {
37
38         ConfigProperties props = getConfigProperties();
39         if(props == null) {
40             props = new ConfigProperties();
41         }
42
43         DatastoreContext datastoreContext = DatastoreContext.newBuilder()
44                 .dataStoreType("config")
45                 .dataStoreProperties(InMemoryDOMDataStoreConfigProperties.create(
46                         props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue(),
47                         props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue(),
48                         props.getMaxShardDataChangeListenerQueueSize().getValue().intValue(),
49                         props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue()))
50                 .shardTransactionIdleTimeout(Duration.create(
51                         props.getShardTransactionIdleTimeoutInMinutes().getValue(), TimeUnit.MINUTES))
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.getShardHearbeatIntervalInMillis().getValue())
58                 .shardInitializationTimeout(props.getShardInitializationTimeoutInSeconds().getValue(),
59                         TimeUnit.SECONDS)
60                 .shardLeaderElectionTimeout(props.getShardLeaderElectionTimeoutInSeconds().getValue(),
61                         TimeUnit.SECONDS)
62                 .shardTransactionCommitTimeoutInSeconds(
63                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
64                 .shardTransactionCommitQueueCapacity(
65                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
66                 .persistent(props.getPersistent().booleanValue())
67                 .shardIsolatedLeaderCheckIntervalInMillis(
68                     props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
69                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
70                 .transactionCreationInitialRateLimit(props.getTxCreationInitialRateLimit().getValue())
71                 .build();
72
73         return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(),
74                 datastoreContext, bundleContext);
75     }
76
77     public void setBundleContext(BundleContext bundleContext) {
78         this.bundleContext = bundleContext;
79     }
80 }