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