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