From 88f763ec4ec2bcc1e0fd414ccb2f105f7490b8e9 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 13 Nov 2015 18:15:08 +0100 Subject: [PATCH] BUG-1014: clean up DatastoreContext.dataStoreType() This is not really a type, but rather a name. Introduce logicalStoreType() and dataStoreName() to disambiguate the two uses. Change-Id: Ibd454ce1dd4428908ada92cb504c478d10ace779 Signed-off-by: Robert Varga --- .../cluster/datastore/DatastoreContext.java | 58 ++++++++++++++++--- ...tributedConfigDataStoreProviderModule.java | 3 +- ...tedOperationalDataStoreProviderModule.java | 3 +- .../DatastoreContextIntrospectorTest.java | 19 ++++-- .../cluster/datastore/IntegrationTestKit.java | 2 +- .../cluster/datastore/ShardManagerTest.java | 2 +- ...DistributedEntityOwnershipServiceTest.java | 4 +- .../datastore/utils/ActorContextTest.java | 10 +++- 8 files changed, 78 insertions(+), 23 deletions(-) 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 c8be6aba9d..cb65d5f7e1 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 com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -19,6 +20,7 @@ import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationRea import org.opendaylight.controller.cluster.raft.ConfigParams; import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl; import org.opendaylight.controller.cluster.raft.PeerAddressResolver; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties; import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; @@ -51,7 +53,7 @@ public class DatastoreContext { public static final long DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS = TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES); public static final int DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE = 2048000; - private static Set globalDatastoreTypes = Sets.newConcurrentHashSet(); + private static final Set globalDatastoreTypes = Sets.newConcurrentHashSet(); private InMemoryDOMDataStoreConfigProperties dataStoreProperties; private Duration shardTransactionIdleTimeout = DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT; @@ -65,7 +67,8 @@ public class DatastoreContext { private AkkaConfigurationReader configurationReader = DEFAULT_CONFIGURATION_READER; private long transactionCreationInitialRateLimit = DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT; private final DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl(); - private String dataStoreType = UNKNOWN_DATA_STORE_TYPE; + private String dataStoreName = UNKNOWN_DATA_STORE_TYPE; + private LogicalDatastoreType logicalStoreType = LogicalDatastoreType.OPERATIONAL; private int shardBatchedModificationCount = DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT; private boolean writeOnlyTransactionOptimizationsEnabled = true; private long shardCommitQueueExpiryTimeoutInMillis = DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS; @@ -98,7 +101,8 @@ public class DatastoreContext { this.persistent = other.persistent; this.configurationReader = other.configurationReader; this.transactionCreationInitialRateLimit = other.transactionCreationInitialRateLimit; - this.dataStoreType = other.dataStoreType; + this.dataStoreName = other.dataStoreName; + this.logicalStoreType = other.logicalStoreType; this.shardBatchedModificationCount = other.shardBatchedModificationCount; this.writeOnlyTransactionOptimizationsEnabled = other.writeOnlyTransactionOptimizationsEnabled; this.shardCommitQueueExpiryTimeoutInMillis = other.shardCommitQueueExpiryTimeoutInMillis; @@ -172,8 +176,20 @@ public class DatastoreContext { return raftConfig.getElectionTimeoutFactor(); } + public String getDataStoreName(){ + return dataStoreName; + } + + public LogicalDatastoreType getLogicalStoreType() { + return logicalStoreType; + } + + /** + * @deprecated Use {@link #getDataStoreName()} or {@link #getLogicalStoreType()} instead. + */ + @Deprecated public String getDataStoreType(){ - return dataStoreType; + return getDataStoreName(); } public long getTransactionCreationInitialRateLimit() { @@ -377,9 +393,35 @@ public class DatastoreContext { return this; } + /** + * @deprecated Use {@link #logicalStoreType(LogicalDatastoreType)} or {@link #dataStoreName(String)}. + */ + @Deprecated public Builder dataStoreType(String dataStoreType){ - datastoreContext.dataStoreType = dataStoreType; - datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreType) + "Datastore"; + return dataStoreName(dataStoreType); + } + + public Builder logicalStoreType(LogicalDatastoreType logicalStoreType){ + datastoreContext.logicalStoreType = Preconditions.checkNotNull(logicalStoreType); + + // Retain compatible naming + switch (logicalStoreType) { + case CONFIGURATION: + dataStoreName("config"); + break; + case OPERATIONAL: + dataStoreName("operational"); + break; + default: + dataStoreName(logicalStoreType.name()); + } + + return this; + } + + public Builder dataStoreName(String dataStoreName){ + datastoreContext.dataStoreName = Preconditions.checkNotNull(dataStoreName); + datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreName) + "Datastore"; return this; } @@ -443,8 +485,8 @@ public class DatastoreContext { maxShardDataChangeExecutorPoolSize, maxShardDataChangeExecutorQueueSize, maxShardDataChangeListenerQueueSize, maxShardDataStoreExecutorQueueSize); - if(datastoreContext.dataStoreType != null) { - globalDatastoreTypes.add(datastoreContext.dataStoreType); + if(datastoreContext.dataStoreName != null) { + globalDatastoreTypes.add(datastoreContext.dataStoreName); } return datastoreContext; 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 e028887a3c..43e6723e8d 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 @@ -3,6 +3,7 @@ package org.opendaylight.controller.config.yang.config.distributed_datastore_pro import org.opendaylight.controller.cluster.datastore.DatastoreContext; import org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore; import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.osgi.framework.BundleContext; public class DistributedConfigDataStoreProviderModule extends @@ -41,7 +42,7 @@ public class DistributedConfigDataStoreProviderModule extends } DatastoreContext datastoreContext = DatastoreContext.newBuilder() - .dataStoreType("config") + .logicalStoreType(LogicalDatastoreType.CONFIGURATION) .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue()) .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue()) .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize().getValue().intValue()) 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 e89708f211..d9225ab265 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 @@ -3,6 +3,7 @@ package org.opendaylight.controller.config.yang.config.distributed_datastore_pro import org.opendaylight.controller.cluster.datastore.DatastoreContext; import org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore; import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.osgi.framework.BundleContext; public class DistributedOperationalDataStoreProviderModule extends @@ -42,7 +43,7 @@ public class DistributedOperationalDataStoreProviderModule extends } DatastoreContext datastoreContext = DatastoreContext.newBuilder() - .dataStoreType("operational") + .logicalStoreType(LogicalDatastoreType.OPERATIONAL) .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue()) .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue()) .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize().getValue().intValue()) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java index 2bd2e61296..9ae1e0a9a8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java @@ -17,6 +17,7 @@ import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEF import java.util.Dictionary; import java.util.Hashtable; import org.junit.Test; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties; /** @@ -28,7 +29,8 @@ public class DatastoreContextIntrospectorTest { @Test public void testUpdate() { - DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build(); + DatastoreContext context = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context ); Dictionary properties = new Hashtable<>(); @@ -117,7 +119,8 @@ public class DatastoreContextIntrospectorTest { @Test public void testUpdateWithInvalidValues() { - DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build(); + DatastoreContext context = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context ); Dictionary properties = new Hashtable<>(); @@ -165,7 +168,8 @@ public class DatastoreContextIntrospectorTest { properties.put("persistent", "false"); // global setting properties.put("operational.Persistent", "true"); // operational override - DatastoreContext operContext = DatastoreContext.newBuilder().dataStoreType("operational").build(); + DatastoreContext operContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext); boolean updated = operIntrospector.update(properties); assertEquals("updated", true, updated); @@ -175,7 +179,8 @@ public class DatastoreContextIntrospectorTest { assertEquals(true, operContext.isPersistent()); assertEquals(333, operContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize()); - DatastoreContext configContext = DatastoreContext.newBuilder().dataStoreType("config").build(); + DatastoreContext configContext = DatastoreContext.newBuilder() + .logicalStoreType(LogicalDatastoreType.CONFIGURATION).build(); DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext); updated = configIntrospector.update(properties); assertEquals("updated", true, updated); @@ -194,7 +199,8 @@ public class DatastoreContextIntrospectorTest { properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override properties.put("topology.shard-transaction-idle-timeout-in-minutes", "55"); // global shard override - DatastoreContext operContext = DatastoreContext.newBuilder().dataStoreType("operational").build(); + DatastoreContext operContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext); DatastoreContext shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology"); @@ -207,7 +213,8 @@ public class DatastoreContextIntrospectorTest { shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology"); assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes()); - DatastoreContext configContext = DatastoreContext.newBuilder().dataStoreType("config").build(); + DatastoreContext configContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.CONFIGURATION).build(); DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext); configIntrospector.update(properties); configContext = configIntrospector.getContext(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java index 9cc6d838c8..ada0fba10e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java @@ -68,7 +68,7 @@ public class IntegrationTestKit extends ShardTestKit { ClusterWrapper cluster = new ClusterWrapperImpl(getSystem()); Configuration config = new ConfigurationImpl(moduleShardsConfig, "modules.conf"); - datastoreContextBuilder.dataStoreType(typeName); + datastoreContextBuilder.dataStoreName(typeName); DatastoreContext datastoreContext = datastoreContextBuilder.build(); DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class); 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 5bccee198d..cef38b9c1b 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 @@ -137,7 +137,7 @@ public class ShardManagerTest extends AbstractActorTest { private static String mockShardName; private final DatastoreContext.Builder datastoreContextBuilder = DatastoreContext.newBuilder(). - dataStoreType(shardMrgIDSuffix).shardInitializationTimeout(600, TimeUnit.MILLISECONDS) + dataStoreName(shardMrgIDSuffix).shardInitializationTimeout(600, TimeUnit.MILLISECONDS) .shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(6); private final Collection actorSystems = new ArrayList<>(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java index 31accd12ee..63e576944b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java @@ -78,12 +78,12 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh static int ID_COUNTER = 1; static final QName QNAME = QName.create("test", "2015-08-11", "foo"); - private final String dataStoreType = "config" + ID_COUNTER++; + private final String dataStoreName = "config" + ID_COUNTER++; private DistributedDataStore dataStore; @Before public void setUp() { - DatastoreContext datastoreContext = DatastoreContext.newBuilder().dataStoreType(dataStoreType). + DatastoreContext datastoreContext = DatastoreContext.newBuilder().dataStoreName(dataStoreName). shardInitializationTimeout(10, TimeUnit.SECONDS).build(); Configuration configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()) { 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 093f0fa6df..a2794bde9c 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 @@ -56,6 +56,7 @@ import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; import org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound; import org.opendaylight.controller.cluster.raft.utils.EchoActor; import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -397,7 +398,8 @@ public class ActorContextTest extends AbstractActorTest{ TestActorRef shardManager = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). + DatastoreContext dataStoreContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.CONFIGURATION). shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); final String expPrimaryPath = "akka://test-system/find-primary-shard"; @@ -439,7 +441,8 @@ public class ActorContextTest extends AbstractActorTest{ TestActorRef shardManager = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). + DatastoreContext dataStoreContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.CONFIGURATION). shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); final DataTree mockDataTree = Mockito.mock(DataTree.class); @@ -490,7 +493,8 @@ public class ActorContextTest extends AbstractActorTest{ TestActorRef shardManager = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). + DatastoreContext dataStoreContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.CONFIGURATION). shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); ActorContext actorContext = -- 2.36.6