From 7030ae1a3c8fcc19e2b88d874a18faf73496682e Mon Sep 17 00:00:00 2001 From: Moiz Raja Date: Thu, 7 Jan 2016 14:07:02 -0800 Subject: [PATCH] Fix reading of EntityOwnerSelectionStrategy 1. The pid used for reading a config admin file should not have hyphens so replaced them with dots 2. The config admin returns properties that are not from the file so we need a way to ignore them. I specifically look for the a prefix of "entity.type." and ignore the other properties Change-Id: I26a66176583ec39cbdb78fec749022429218e005 Signed-off-by: Moiz Raja --- .../entityownership/EntityOwnershipShard.java | 7 +++++++ .../EntityOwnerSelectionStrategyConfigReader.java | 13 ++++++++++--- ...ntityOwnerSelectionStrategyConfigReaderTest.java | 10 +++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java index 74cc6717dc..89b7518a03 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java @@ -139,6 +139,8 @@ class EntityOwnershipShard extends Shard { } private void onSelectOwner(SelectOwner selectOwner) { + LOG.debug("{}: onSelectOwner: {}", persistenceId(), selectOwner); + String currentOwner = getCurrentOwner(selectOwner.getEntityPath()); if(Strings.isNullOrEmpty(currentOwner)) { String entityType = EntityOwnersModel.entityTypeFromEntityPath(selectOwner.getEntityPath()); @@ -325,6 +327,8 @@ class EntityOwnershipShard extends Shard { String currentOwner = getCurrentOwner(message.getEntityPath()); EntityOwnerSelectionStrategy strategy = getEntityOwnerElectionStrategy(message.getEntityPath()); + + LOG.debug("{}: Using strategy {} to select owner", persistenceId(), strategy); if(Strings.isNullOrEmpty(currentOwner)){ if(strategy.getSelectionDelayInMillis() == 0L) { String entityType = EntityOwnersModel.entityTypeFromEntityPath(message.getEntityPath()); @@ -443,6 +447,9 @@ class EntityOwnershipShard extends Shard { if(lastScheduledTask != null && !lastScheduledTask.isCancelled()){ lastScheduledTask.cancel(); } + + LOG.debug("{}: Scheduling owner selection after {} ms", persistenceId(), strategy.getSelectionDelayInMillis()); + lastScheduledTask = context().system().scheduler().scheduleOnce( FiniteDuration.apply(strategy.getSelectionDelayInMillis(), TimeUnit.MILLISECONDS) , self(), new SelectOwner(entityPath, allCandidates, strategy) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java index b6092b2e00..cc9ff63aba 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReader.java @@ -21,9 +21,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class EntityOwnerSelectionStrategyConfigReader { - public static final String CONFIG_ID = "org.opendaylight.controller.cluster.entity-owner-selection-strategies"; + public static final String CONFIG_ID = "org.opendaylight.controller.cluster.entity.owner.selection.strategies"; private static final Logger LOG = LoggerFactory.getLogger(EntityOwnerSelectionStrategyConfigReader.class); + private static final String ENTITY_TYPE_PREFIX = "entity.type."; + private final BundleContext bundleContext; private final EntityOwnerSelectionStrategyConfig config; @@ -51,7 +53,7 @@ public class EntityOwnerSelectionStrategyConfigReader { String key = keys.nextElement(); String strategyProps = (String) properties.get(key); String[] strategyClassAndDelay = strategyProps.split(","); - if(strategyClassAndDelay.length >= 1) { + if(key.startsWith(ENTITY_TYPE_PREFIX)) { @SuppressWarnings("unchecked") Class aClass = (Class) getClass().getClassLoader().loadClass(strategyClassAndDelay[0]); @@ -59,9 +61,14 @@ public class EntityOwnerSelectionStrategyConfigReader { if(strategyClassAndDelay.length > 1){ delay = Long.parseLong(strategyClassAndDelay[1]); } - builder.addStrategy(key, aClass, delay); + String entityType = key.substring(key.lastIndexOf(".") + 1); + builder.addStrategy(entityType, aClass, delay); + } else { + LOG.debug("Ignoring non-conforming property key : {}, value : {}", key, strategyProps); } } + } else { + LOG.error("Could not read strategy configuration file, will use default configuration"); } } catch(Exception e){ LOG.warn("Failed to read selection strategy configuration file. All configuration will be ignored.", e); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReaderTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReaderTest.java index 252e7b7cb1..61613c7761 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReaderTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReaderTest.java @@ -49,7 +49,7 @@ public class EntityOwnerSelectionStrategyConfigReaderTest { @Test public void testReadStrategies(){ Hashtable props = new Hashtable<>(); - props.put("test", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy,100"); + props.put("entity.type.test", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy,100"); doReturn(props).when(mockConfig).getProperties(); @@ -92,7 +92,7 @@ public class EntityOwnerSelectionStrategyConfigReaderTest { @Test public void testReadStrategiesInvalidDelay(){ Hashtable props = new Hashtable<>(); - props.put("test", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy,foo"); + props.put("entity.type.test", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy,foo"); doReturn(props).when(mockConfig).getProperties(); @@ -104,7 +104,7 @@ public class EntityOwnerSelectionStrategyConfigReaderTest { @Test public void testReadStrategiesInvalidClassType(){ Hashtable props = new Hashtable<>(); - props.put("test", "String,100"); + props.put("entity.type.test", "String,100"); doReturn(props).when(mockConfig).getProperties(); @@ -116,8 +116,8 @@ public class EntityOwnerSelectionStrategyConfigReaderTest { @Test public void testReadStrategiesMissingDelay(){ Hashtable props = new Hashtable<>(); - props.put("test", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy,100"); - props.put("test1", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy"); + props.put("entity.type.test", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy,100"); + props.put("entity.type.test1", "org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy"); doReturn(props).when(mockConfig).getProperties(); -- 2.36.6