From: Moiz Raja Date: Thu, 5 Feb 2015 23:38:38 +0000 (-0800) Subject: Store the datastore type in dataStoreContext X-Git-Tag: release/lithium~591^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=122ee6a8b24794b6fd7a07977afa6cd777ca50b4 Store the datastore type in dataStoreContext This way we do not need to pass it to DistributedDataStoreFactory, DistributedDataStore and ShardManager as it is already present in dataStoreContext Change-Id: Id9aa1541728f3632a46d67f3bdbacb87fd39783f Signed-off-by: Moiz Raja --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/pom.xml b/opendaylight/md-sal/sal-distributed-datastore/pom.xml index d6030ea457..e27546f5dc 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/pom.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/pom.xml @@ -148,6 +148,11 @@ org.opendaylight.yangtools yang-data-impl + + org.apache.commons + commons-lang3 + + diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java index 9341625fde..cee781fb88 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore; import akka.util.Timeout; import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.text.WordUtils; import org.opendaylight.controller.cluster.datastore.config.ConfigurationReader; import org.opendaylight.controller.cluster.datastore.config.FileConfigurationReader; import org.opendaylight.controller.cluster.raft.ConfigParams; @@ -40,6 +41,7 @@ public class DatastoreContext { public static final int DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE = 12; public static final int DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR = 2; public static final int DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT = 100; + public static final String UNKNOWN_DATA_STORE_TYPE = "unknown"; private InMemoryDOMDataStoreConfigProperties dataStoreProperties; private Duration shardTransactionIdleTimeout = DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT; @@ -53,6 +55,7 @@ public class DatastoreContext { private ConfigurationReader configurationReader = DEFAULT_CONFIGURATION_READER; private long transactionCreationInitialRateLimit = DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT; private DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl(); + private String dataStoreType = UNKNOWN_DATA_STORE_TYPE; private DatastoreContext(){ setShardJournalRecoveryLogBatchSize(DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE); @@ -114,6 +117,9 @@ public class DatastoreContext { return raftConfig.getElectionTimeoutFactor(); } + public String getDataStoreType(){ + return dataStoreType; + } public long getTransactionCreationInitialRateLimit() { return transactionCreationInitialRateLimit; @@ -234,6 +240,12 @@ public class DatastoreContext { return this; } + public Builder dataStoreType(String dataStoreType){ + datastoreContext.dataStoreType = dataStoreType; + datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreType) + "Datastore"; + return this; + } + public DatastoreContext build() { return datastoreContext; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java index e9038ed4f0..107c959112 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java @@ -39,22 +39,23 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener, Au private final ActorContext actorContext; - public DistributedDataStore(ActorSystem actorSystem, String type, ClusterWrapper cluster, + public DistributedDataStore(ActorSystem actorSystem, ClusterWrapper cluster, Configuration configuration, DatastoreContext datastoreContext) { Preconditions.checkNotNull(actorSystem, "actorSystem should not be null"); - Preconditions.checkNotNull(type, "type should not be null"); Preconditions.checkNotNull(cluster, "cluster should not be null"); Preconditions.checkNotNull(configuration, "configuration should not be null"); Preconditions.checkNotNull(datastoreContext, "datastoreContext should not be null"); + String type = datastoreContext.getDataStoreType(); + String shardManagerId = ShardManagerIdentifier.builder().type(type).build().toString(); LOG.info("Creating ShardManager : {}", shardManagerId); actorContext = new ActorContext(actorSystem, actorSystem.actorOf( - ShardManager.props(type, cluster, configuration, datastoreContext) + ShardManager.props(cluster, configuration, datastoreContext) .withMailbox(ActorContext.MAILBOX), shardManagerId ), - cluster, configuration, datastoreContext, type); + cluster, configuration, datastoreContext); } public DistributedDataStore(ActorContext actorContext) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java index 5d63c92e88..a9a735ede7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java @@ -22,13 +22,13 @@ public class DistributedDataStoreFactory { private static volatile ActorSystem persistentActorSystem = null; - public static DistributedDataStore createInstance(String name, SchemaService schemaService, + public static DistributedDataStore createInstance(SchemaService schemaService, DatastoreContext datastoreContext, BundleContext bundleContext) { ActorSystem actorSystem = getOrCreateInstance(bundleContext, datastoreContext.getConfigurationReader()); Configuration config = new ConfigurationImpl("module-shards.conf", "modules.conf"); final DistributedDataStore dataStore = - new DistributedDataStore(actorSystem, name, new ClusterWrapperImpl(actorSystem), + new DistributedDataStore(actorSystem, new ClusterWrapperImpl(actorSystem), config, datastoreContext); ShardStrategyFactory.setConfiguration(config); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java index 9c8f0b2444..3dbac003b9 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java @@ -96,17 +96,15 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering { private final DataPersistenceProvider dataPersistenceProvider; /** - * @param type defines the kind of data that goes into shards created by this shard manager. Examples of type would be - * configuration or operational */ - protected ShardManager(String type, ClusterWrapper cluster, Configuration configuration, + protected ShardManager(ClusterWrapper cluster, Configuration configuration, DatastoreContext datastoreContext) { - this.type = Preconditions.checkNotNull(type, "type should not be null"); this.cluster = Preconditions.checkNotNull(cluster, "cluster should not be null"); this.configuration = Preconditions.checkNotNull(configuration, "configuration should not be null"); this.datastoreContext = datastoreContext; this.dataPersistenceProvider = createDataPersistenceProvider(datastoreContext.isPersistent()); + this.type = datastoreContext.getDataStoreType(); // Subscribe this actor to cluster member events cluster.subscribeToMemberEvents(getSelf()); @@ -118,16 +116,15 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering { return (persistent) ? new PersistentDataProvider() : new NonPersistentDataProvider(); } - public static Props props(final String type, + public static Props props( final ClusterWrapper cluster, final Configuration configuration, final DatastoreContext datastoreContext) { - Preconditions.checkNotNull(type, "type should not be null"); Preconditions.checkNotNull(cluster, "cluster should not be null"); Preconditions.checkNotNull(configuration, "configuration should not be null"); - return Props.create(new ShardManagerCreator(type, cluster, configuration, datastoreContext)); + return Props.create(new ShardManagerCreator(cluster, configuration, datastoreContext)); } @Override @@ -529,14 +526,12 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering { private static class ShardManagerCreator implements Creator { private static final long serialVersionUID = 1L; - final String type; final ClusterWrapper cluster; final Configuration configuration; final DatastoreContext datastoreContext; - ShardManagerCreator(String type, ClusterWrapper cluster, + ShardManagerCreator(ClusterWrapper cluster, Configuration configuration, DatastoreContext datastoreContext) { - this.type = type; this.cluster = cluster; this.configuration = configuration; this.datastoreContext = datastoreContext; @@ -544,7 +539,7 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering { @Override public ShardManager create() throws Exception { - return new ShardManager(type, cluster, configuration, datastoreContext); + return new ShardManager(cluster, configuration, datastoreContext); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java index 7138a4a6e7..cb06c898fd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java @@ -85,7 +85,6 @@ public class ActorContext { private final ClusterWrapper clusterWrapper; private final Configuration configuration; private final DatastoreContext datastoreContext; - private final String dataStoreType; private final FiniteDuration operationDuration; private final Timeout operationTimeout; private final String selfAddressHostPort; @@ -100,18 +99,17 @@ public class ActorContext { public ActorContext(ActorSystem actorSystem, ActorRef shardManager, ClusterWrapper clusterWrapper, Configuration configuration) { this(actorSystem, shardManager, clusterWrapper, configuration, - DatastoreContext.newBuilder().build(), UNKNOWN_DATA_STORE_TYPE); + DatastoreContext.newBuilder().build()); } public ActorContext(ActorSystem actorSystem, ActorRef shardManager, ClusterWrapper clusterWrapper, Configuration configuration, - DatastoreContext datastoreContext, String dataStoreType) { + DatastoreContext datastoreContext) { this.actorSystem = actorSystem; this.shardManager = shardManager; this.clusterWrapper = clusterWrapper; this.configuration = configuration; this.datastoreContext = datastoreContext; - this.dataStoreType = dataStoreType; this.txRateLimiter = RateLimiter.create(datastoreContext.getTransactionCreationInitialRateLimit()); operationDuration = Duration.create(datastoreContext.getOperationTimeoutInSeconds(), TimeUnit.SECONDS); @@ -471,7 +469,7 @@ public class ActorContext { * @return */ public Timer getOperationTimer(String operationName){ - final String rate = MetricRegistry.name(DISTRIBUTED_DATA_STORE_METRIC_REGISTRY, dataStoreType, operationName, METRIC_RATE); + final String rate = MetricRegistry.name(DISTRIBUTED_DATA_STORE_METRIC_REGISTRY, datastoreContext.getDataStoreType(), operationName, METRIC_RATE); return metricRegistry.timer(rate); } @@ -481,7 +479,7 @@ public class ActorContext { * @return */ public String getDataStoreType() { - return dataStoreType; + return datastoreContext.getDataStoreType(); } /** diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java index 253422122d..7e8307465b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java @@ -41,7 +41,7 @@ public class DistributedConfigDataStoreProviderModule extends } DatastoreContext datastoreContext = DatastoreContext.newBuilder() - .dataStoreMXBeanType("DistributedConfigDatastore") + .dataStoreType("config") .dataStoreProperties(InMemoryDOMDataStoreConfigProperties.create( props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue(), props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue(), @@ -70,7 +70,7 @@ public class DistributedConfigDataStoreProviderModule extends .transactionCreationInitialRateLimit(props.getTxCreationInitialRateLimit().getValue()) .build(); - return DistributedDataStoreFactory.createInstance("config", getConfigSchemaServiceDependency(), + return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(), datastoreContext, bundleContext); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java index d41b83d0d2..0655468531 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java @@ -41,7 +41,7 @@ public class DistributedOperationalDataStoreProviderModule extends } DatastoreContext datastoreContext = DatastoreContext.newBuilder() - .dataStoreMXBeanType("DistributedOperationalDatastore") + .dataStoreType("operational") .dataStoreProperties(InMemoryDOMDataStoreConfigProperties.create( props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue(), props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue(), @@ -70,8 +70,8 @@ public class DistributedOperationalDataStoreProviderModule extends .transactionCreationInitialRateLimit(props.getTxCreationInitialRateLimit().getValue()) .build(); - return DistributedDataStoreFactory.createInstance("operational", - getOperationalSchemaServiceDependency(), datastoreContext, bundleContext); + return DistributedDataStoreFactory.createInstance(getOperationalSchemaServiceDependency(), + datastoreContext, bundleContext); } public void setBundleContext(BundleContext bundleContext) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java index 9f5aded352..1ad2be7af1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java @@ -790,8 +790,11 @@ public class DistributedDataStoreIntegrationTest extends AbstractActorTest { Configuration config = new ConfigurationImpl("module-shards.conf", "modules.conf"); ShardStrategyFactory.setConfiguration(config); + datastoreContextBuilder.dataStoreType(typeName); + DatastoreContext datastoreContext = datastoreContextBuilder.build(); - DistributedDataStore dataStore = new DistributedDataStore(getSystem(), typeName, cluster, + + DistributedDataStore dataStore = new DistributedDataStore(getSystem(), cluster, config, datastoreContext); SchemaContext schemaContext = SchemaContextHelper.full(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java index 8c56efd413..596761ddc8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java @@ -1,5 +1,10 @@ package org.opendaylight.controller.cluster.datastore; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import akka.actor.ActorRef; import akka.actor.Props; import akka.japi.Creator; @@ -11,6 +16,13 @@ import akka.util.Timeout; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.common.util.concurrent.Uninterruptibles; +import java.net.URI; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -35,20 +47,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import scala.concurrent.Await; import scala.concurrent.Future; -import java.net.URI; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - public class ShardManagerTest extends AbstractActorTest { private static int ID_COUNTER = 1; @@ -73,8 +71,10 @@ public class ShardManagerTest extends AbstractActorTest { } private Props newShardMgrProps() { - return ShardManager.props(shardMrgIDSuffix, new MockClusterWrapper(), new MockConfiguration(), - DatastoreContext.newBuilder().build()); + + DatastoreContext.Builder builder = DatastoreContext.newBuilder(); + builder.dataStoreType(shardMrgIDSuffix); + return ShardManager.props(new MockClusterWrapper(), new MockConfiguration(), builder.build()); } @Test @@ -351,10 +351,8 @@ public class ShardManagerTest extends AbstractActorTest { public void testRecoveryApplicable(){ new JavaTestKit(getSystem()) { { - final Props persistentProps = ShardManager.props(shardMrgIDSuffix, - new MockClusterWrapper(), - new MockConfiguration(), - DatastoreContext.newBuilder().persistent(true).build()); + final Props persistentProps = ShardManager.props(new MockClusterWrapper(), new MockConfiguration(), + DatastoreContext.newBuilder().persistent(true).dataStoreType(shardMrgIDSuffix).build()); final TestActorRef persistentShardManager = TestActorRef.create(getSystem(), persistentProps); @@ -362,10 +360,8 @@ public class ShardManagerTest extends AbstractActorTest { assertTrue("Recovery Applicable", dataPersistenceProvider1.isRecoveryApplicable()); - final Props nonPersistentProps = ShardManager.props(shardMrgIDSuffix, - new MockClusterWrapper(), - new MockConfiguration(), - DatastoreContext.newBuilder().persistent(false).build()); + final Props nonPersistentProps = ShardManager.props(new MockClusterWrapper(), new MockConfiguration(), + DatastoreContext.newBuilder().persistent(false).dataStoreType(shardMrgIDSuffix).build()); final TestActorRef nonPersistentShardManager = TestActorRef.create(getSystem(), nonPersistentProps); @@ -386,7 +382,8 @@ public class ShardManagerTest extends AbstractActorTest { private static final long serialVersionUID = 1L; @Override public ShardManager create() throws Exception { - return new ShardManager(shardMrgIDSuffix, new MockClusterWrapper(), new MockConfiguration(), DatastoreContext.newBuilder().build()) { + return new ShardManager(new MockClusterWrapper(), new MockConfiguration(), + DatastoreContext.newBuilder().dataStoreType(shardMrgIDSuffix).build()) { @Override protected DataPersistenceProvider createDataPersistenceProvider(boolean persistent) { DataPersistenceProviderMonitor dataPersistenceProviderMonitor @@ -426,8 +423,8 @@ public class ShardManagerTest extends AbstractActorTest { private final CountDownLatch recoveryComplete = new CountDownLatch(1); TestShardManager(String shardMrgIDSuffix) { - super(shardMrgIDSuffix, new MockClusterWrapper(), new MockConfiguration(), - DatastoreContext.newBuilder().build()); + super(new MockClusterWrapper(), new MockConfiguration(), + DatastoreContext.newBuilder().dataStoreType(shardMrgIDSuffix).build()); } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java index 16db2be185..eae46da2ee 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java @@ -273,10 +273,11 @@ public class ActorContextTest extends AbstractActorTest{ DatastoreContext mockDataStoreContext = mock(DatastoreContext.class); doReturn(155L).when(mockDataStoreContext).getTransactionCreationInitialRateLimit(); + doReturn("config").when(mockDataStoreContext).getDataStoreType(); ActorContext actorContext = new ActorContext(getSystem(), mock(ActorRef.class), mock(ClusterWrapper.class), - mock(Configuration.class), mockDataStoreContext, "config"); + mock(Configuration.class), mockDataStoreContext); // Check that the initial value is being picked up from DataStoreContext assertEquals(mockDataStoreContext.getTransactionCreationInitialRateLimit(), actorContext.getTxCreationLimit(), 1e-15);