}
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());
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());
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)
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;
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<? extends EntityOwnerSelectionStrategy> aClass
= (Class<? extends EntityOwnerSelectionStrategy>) getClass().getClassLoader().loadClass(strategyClassAndDelay[0]);
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);
@Test
public void testReadStrategies(){
Hashtable<String, Object> 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();
@Test
public void testReadStrategiesInvalidDelay(){
Hashtable<String, Object> 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();
@Test
public void testReadStrategiesInvalidClassType(){
Hashtable<String, Object> props = new Hashtable<>();
- props.put("test", "String,100");
+ props.put("entity.type.test", "String,100");
doReturn(props).when(mockConfig).getProperties();
@Test
public void testReadStrategiesMissingDelay(){
Hashtable<String, Object> 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();