8a874667eeb0e47a7ed9979852e362fe17596164
[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(final ModuleIdentifier identifier,
24             final DependencyResolver dependencyResolver) {
25         super(identifier, dependencyResolver);
26     }
27
28     public DistributedOperationalDataStoreProviderModule(final ModuleIdentifier identifier,
29             final DependencyResolver dependencyResolver,final DistributedOperationalDataStoreProviderModule oldModule,
30             final 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(final 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(final 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                 .tempFileDirectory("./data")
67                 .fileBackedStreamingThresholdInMegabytes(props.getFileBackedStreamingThresholdInMegabytes()
68                         .getValue().intValue())
69                 .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue())
70                 .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize()
71                         .getValue().intValue())
72                 .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize()
73                         .getValue().intValue())
74                 .maxShardDataStoreExecutorQueueSize(props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue())
75                 .shardTransactionIdleTimeoutInMinutes(props.getShardTransactionIdleTimeoutInMinutes().getValue())
76                 .operationTimeoutInSeconds(props.getOperationTimeoutInSeconds().getValue())
77                 .shardJournalRecoveryLogBatchSize(props.getShardJournalRecoveryLogBatchSize()
78                         .getValue().intValue())
79                 .shardSnapshotBatchCount(props.getShardSnapshotBatchCount().getValue().intValue())
80                 .shardSnapshotDataThresholdPercentage(props.getShardSnapshotDataThresholdPercentage()
81                         .getValue().intValue())
82                 .shardHeartbeatIntervalInMillis(props.getShardHeartbeatIntervalInMillis().getValue())
83                 .shardInitializationTimeoutInSeconds(props.getShardInitializationTimeoutInSeconds().getValue())
84                 .shardLeaderElectionTimeoutInSeconds(props.getShardLeaderElectionTimeoutInSeconds().getValue())
85                 .shardTransactionCommitTimeoutInSeconds(
86                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
87                 .shardTransactionCommitQueueCapacity(
88                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
89                 .persistent(props.getPersistent().booleanValue())
90                 .shardIsolatedLeaderCheckIntervalInMillis(
91                         props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
92                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
93                 .transactionCreationInitialRateLimit(props.getTransactionCreationInitialRateLimit().getValue())
94                 .shardBatchedModificationCount(props.getShardBatchedModificationCount().getValue().intValue())
95                 .shardCommitQueueExpiryTimeoutInSeconds(
96                         props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue())
97                 .transactionDebugContextEnabled(props.getTransactionDebugContextEnabled())
98                 .customRaftPolicyImplementation(props.getCustomRaftPolicyImplementation())
99                 .maximumMessageSliceSize(props.getMaximumMessageSliceSize().getValue().intValue())
100                 .useTellBasedProtocol(props.getUseTellBasedProtocol())
101                 .syncIndexThreshold(props.getSyncIndexThreshold().getValue())
102                 .backendAlivenessTimerIntervalInSeconds(props.getBackendAlivenessTimerIntervalInSeconds().getValue())
103                 .frontendRequestTimeoutInSeconds(props.getFrontendRequestTimeoutInSeconds().getValue())
104                 .frontendNoProgressTimeoutInSeconds(props.getFrontendNoProgressTimeoutInSeconds().getValue())
105                 .build();
106     }
107
108     public void setBundleContext(final BundleContext bundleContext) {
109         this.bundleContext = bundleContext;
110     }
111
112 }