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