BUG-5280: split DistributedDataStore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / config / yang / config / distributed_datastore_provider / DistributedOperationalDataStoreProviderModule.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.DistributedDataStoreInterface;
13 import org.opendaylight.controller.config.api.DependencyResolver;
14 import org.opendaylight.controller.config.api.ModuleIdentifier;
15 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.osgi.framework.BundleContext;
18
19 public class DistributedOperationalDataStoreProviderModule
20         extends AbstractDistributedOperationalDataStoreProviderModule {
21     private BundleContext bundleContext;
22
23     public DistributedOperationalDataStoreProviderModule(ModuleIdentifier identifier,
24             DependencyResolver dependencyResolver) {
25         super(identifier, dependencyResolver);
26     }
27
28     public DistributedOperationalDataStoreProviderModule(ModuleIdentifier identifier,
29             DependencyResolver dependencyResolver,DistributedOperationalDataStoreProviderModule oldModule,
30             AutoCloseable oldInstance) {
31         super(identifier, dependencyResolver, oldModule, oldInstance);
32     }
33
34     @Override
35     public void customValidation() {
36         // add custom validation form module attributes here.
37     }
38
39     @Override
40     public boolean canReuseInstance(AbstractDistributedOperationalDataStoreProviderModule oldModule) {
41         return true;
42     }
43
44     @Override
45     public java.lang.AutoCloseable createInstance() {
46         // The DistributedOperDataStore is provided via blueprint so wait for and return it here for
47         // backwards compatibility
48         WaitingServiceTracker<DistributedDataStoreInterface> tracker = WaitingServiceTracker.create(
49                 DistributedDataStoreInterface.class, bundleContext, "(type=distributed-operational)");
50         DistributedDataStoreInterface delegate = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
51         return new ForwardingDistributedDataStore(delegate, tracker);
52     }
53
54     public static DatastoreContext newDatastoreContext() {
55         return newDatastoreContext(null);
56     }
57
58     private static DatastoreContext newDatastoreContext(OperationalProperties inProps) {
59         OperationalProperties props = inProps;
60         if (props == null) {
61             props = new OperationalProperties();
62         }
63
64         return DatastoreContext.newBuilder()
65                 .logicalStoreType(LogicalDatastoreType.OPERATIONAL)
66                 .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue())
67                 .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize()
68                         .getValue().intValue())
69                 .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize()
70                         .getValue().intValue())
71                 .maxShardDataStoreExecutorQueueSize(props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue())
72                 .shardTransactionIdleTimeoutInMinutes(props.getShardTransactionIdleTimeoutInMinutes().getValue())
73                 .operationTimeoutInSeconds(props.getOperationTimeoutInSeconds().getValue())
74                 .shardJournalRecoveryLogBatchSize(props.getShardJournalRecoveryLogBatchSize()
75                         .getValue().intValue())
76                 .shardSnapshotBatchCount(props.getShardSnapshotBatchCount().getValue().intValue())
77                 .shardSnapshotDataThresholdPercentage(props.getShardSnapshotDataThresholdPercentage()
78                         .getValue().intValue())
79                 .shardHeartbeatIntervalInMillis(props.getShardHeartbeatIntervalInMillis().getValue())
80                 .shardInitializationTimeoutInSeconds(props.getShardInitializationTimeoutInSeconds().getValue())
81                 .shardLeaderElectionTimeoutInSeconds(props.getShardLeaderElectionTimeoutInSeconds().getValue())
82                 .shardTransactionCommitTimeoutInSeconds(
83                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
84                 .shardTransactionCommitQueueCapacity(
85                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
86                 .persistent(props.getPersistent().booleanValue())
87                 .shardIsolatedLeaderCheckIntervalInMillis(
88                         props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
89                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
90                 .transactionCreationInitialRateLimit(props.getTransactionCreationInitialRateLimit().getValue())
91                 .shardBatchedModificationCount(props.getShardBatchedModificationCount().getValue().intValue())
92                 .shardCommitQueueExpiryTimeoutInSeconds(
93                         props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue())
94                 .transactionDebugContextEnabled(props.getTransactionDebugContextEnabled())
95                 .customRaftPolicyImplementation(props.getCustomRaftPolicyImplementation())
96                 .shardSnapshotChunkSize(props.getShardSnapshotChunkSize().getValue().intValue())
97                 .useTellBasedProtocol(props.getUseTellBasedProtocol())
98                 .build();
99     }
100
101     public void setBundleContext(BundleContext bundleContext) {
102         this.bundleContext = bundleContext;
103     }
104
105 }