import akka.actor.Cancellable;
import akka.actor.Props;
import akka.pattern.Patterns;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import java.util.ArrayList;
}
protected EntityOwnershipShard(ShardIdentifier name, Map<String, String> peerAddresses,
- DatastoreContext datastoreContext, SchemaContext schemaContext, String localMemberName) {
+ DatastoreContext datastoreContext, SchemaContext schemaContext, String localMemberName,
+ EntityOwnerSelectionStrategyConfig strategyConfig) {
super(name, peerAddresses, noPersistenceDatastoreContext(datastoreContext), schemaContext);
this.localMemberName = localMemberName;
this.commitCoordinator = new EntityOwnershipShardCommitCoordinator(localMemberName, LOG);
this.listenerSupport = new EntityOwnershipListenerSupport(getContext(), persistenceId());
- this.strategyConfig = EntityOwnerSelectionStrategyConfig.newBuilder().build();
+ this.strategyConfig = strategyConfig;
for(String peerId: peerAddresses.keySet()) {
ShardIdentifier shardId = ShardIdentifier.builder().fromShardIdString(peerId).build();
return null;
}
- @VisibleForTesting
- void addEntityOwnerSelectionStrategy(String entityType,
- Class<? extends EntityOwnerSelectionStrategy> clazz,
- long delay){
- EntityOwnerSelectionStrategyConfig config = EntityOwnerSelectionStrategyConfig.newBuilder()
- .addStrategy(entityType, clazz, delay).build();
- this.strategyConfig = config;
- }
-
public static Props props(final ShardIdentifier name, final Map<String, String> peerAddresses,
- final DatastoreContext datastoreContext, final SchemaContext schemaContext, final String localMemberName) {
- return Props.create(new Creator(name, peerAddresses, datastoreContext, schemaContext, localMemberName));
+ final DatastoreContext datastoreContext, final SchemaContext schemaContext,
+ final String localMemberName, final EntityOwnerSelectionStrategyConfig strategyConfig) {
+ return Props.create(new Creator(name, peerAddresses, datastoreContext, schemaContext, localMemberName, strategyConfig));
}
private static class Creator extends AbstractShardCreator {
private static final long serialVersionUID = 1L;
private final String localMemberName;
+ private final EntityOwnerSelectionStrategyConfig strategyConfig;
Creator(final ShardIdentifier name, final Map<String, String> peerAddresses,
final DatastoreContext datastoreContext, final SchemaContext schemaContext,
- final String localMemberName) {
+ final String localMemberName, EntityOwnerSelectionStrategyConfig strategyConfig) {
super(name, peerAddresses, datastoreContext, schemaContext);
this.localMemberName = localMemberName;
+ this.strategyConfig = strategyConfig;
}
@Override
public Shard create() throws Exception {
- return new EntityOwnershipShard(name, peerAddresses, datastoreContext, schemaContext, localMemberName);
+ return new EntityOwnershipShard(name, peerAddresses, datastoreContext, schemaContext, localMemberName, strategyConfig);
}
}
import org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal;
import org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterCandidateLocal;
import org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterListenerLocal;
+import org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig;
import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
import org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree;
import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
static class TestShardPropsCreator extends EntityOwnershipShardPropsCreator {
TestShardPropsCreator() {
- super("member-1");
+ super("member-1", EntityOwnerSelectionStrategyConfig.newBuilder().build());
}
private final AtomicReference<CountDownLatch> messageReceived = new AtomicReference<>();
DatastoreContext datastoreContext, SchemaContext schemaContext, String localMemberName,
AtomicReference<Class<?>> messageClass, AtomicReference<CountDownLatch> messageReceived,
AtomicReference<Object> receivedMessage, AtomicReference<DataTree> dataTree) {
- super(name, peerAddresses, datastoreContext, schemaContext, localMemberName);
+ super(name, peerAddresses, datastoreContext, schemaContext, localMemberName, EntityOwnerSelectionStrategyConfig.newBuilder().build());
this.messageClass = messageClass;
this.messageReceived = messageReceived;
this.receivedMessage = receivedMessage;
import org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal;
import org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterCandidateLocal;
import org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterListenerLocal;
+import org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig;
import org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.LastCandidateSelectionStrategy;
import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
TestActorRef<EntityOwnershipShard> peer1 = actorFactory.createTestActor(newShardProps(peerId1,
ImmutableMap.<String, String>builder().put(leaderId.toString(), ""). put(peerId2.toString(), "").build(),
- peerMemberName1).withDispatcher(Dispatchers.DefaultDispatcherId()), peerId1.toString());
+ peerMemberName1, EntityOwnerSelectionStrategyConfig.newBuilder().build()).withDispatcher(Dispatchers.DefaultDispatcherId()), peerId1.toString());
TestActorRef<EntityOwnershipShard> peer2 = actorFactory.createTestActor(newShardProps(peerId2,
ImmutableMap.<String, String>builder().put(leaderId.toString(), ""). put(peerId1.toString(), "").build(),
- peerMemberName2). withDispatcher(Dispatchers.DefaultDispatcherId()), peerId2.toString());
+ peerMemberName2, EntityOwnerSelectionStrategyConfig.newBuilder().build()). withDispatcher(Dispatchers.DefaultDispatcherId()), peerId2.toString());
TestActorRef<EntityOwnershipShard> leader = actorFactory.createTestActor(newShardProps(leaderId,
ImmutableMap.<String, String>builder().put(peerId1.toString(), peer1.path().toString()).
- put(peerId2.toString(), peer2.path().toString()).build(), LOCAL_MEMBER_NAME).
+ put(peerId2.toString(), peer2.path().toString()).build(), LOCAL_MEMBER_NAME, EntityOwnerSelectionStrategyConfig.newBuilder().build()).
withDispatcher(Dispatchers.DefaultDispatcherId()), leaderId.toString());
leader.tell(new ElectionTimeout(), leader);
peer2 = actorFactory.createTestActor(newShardProps(peerId2,
ImmutableMap.<String, String>builder().put(leaderId.toString(), ""). put(peerId1.toString(), "").build(),
- peerMemberName2). withDispatcher(Dispatchers.DefaultDispatcherId()), peerId2.toString());
+ peerMemberName2, EntityOwnerSelectionStrategyConfig.newBuilder().build()). withDispatcher(Dispatchers.DefaultDispatcherId()), peerId2.toString());
leader.tell(new PeerUp(peerMemberName2, peerId2.toString()), ActorRef.noSender());
// Send PeerUp again - should be noop
leader.tell(new PeerUp(peerMemberName2, peerId2.toString()), ActorRef.noSender());
peer1 = actorFactory.createTestActor(newShardProps(peerId1,
ImmutableMap.<String, String>builder().put(leaderId.toString(), ""). put(peerId2.toString(), "").build(),
- peerMemberName1).withDispatcher(Dispatchers.DefaultDispatcherId()), peerId1.toString());
+ peerMemberName1, EntityOwnerSelectionStrategyConfig.newBuilder().build()).withDispatcher(Dispatchers.DefaultDispatcherId()), peerId1.toString());
leader.tell(new PeerUp(peerMemberName1, peerId1.toString()), ActorRef.noSender());
verifyOwner(leader, ENTITY_TYPE, ENTITY_ID4, "");
TestActorRef<EntityOwnershipShard> leader = actorFactory.createTestActor(newShardProps(leaderId,
ImmutableMap.<String, String>builder().put(localId.toString(), shard.path().toString()).build(),
- LOCAL_MEMBER_NAME).withDispatcher(Dispatchers.DefaultDispatcherId()), leaderId.toString());
+ LOCAL_MEMBER_NAME, EntityOwnerSelectionStrategyConfig.newBuilder().build()).withDispatcher(Dispatchers.DefaultDispatcherId()), leaderId.toString());
leader.tell(new ElectionTimeout(), leader);
kit.waitUntilLeader(leader);
return newShardProps(Collections.<String,String>emptyMap());
}
+ private Props newShardProps(EntityOwnerSelectionStrategyConfig strategyConfig) {
+ return newShardProps(newShardId(LOCAL_MEMBER_NAME), Collections.<String,String>emptyMap(),
+ LOCAL_MEMBER_NAME, strategyConfig);
+ }
+
private Props newShardProps(Map<String,String> peers) {
- return newShardProps(newShardId(LOCAL_MEMBER_NAME), peers, LOCAL_MEMBER_NAME);
+ return newShardProps(newShardId(LOCAL_MEMBER_NAME), peers, LOCAL_MEMBER_NAME, EntityOwnerSelectionStrategyConfig.newBuilder().build());
}
- private Props newShardProps(ShardIdentifier shardId, Map<String,String> peers, String memberName) {
+ private Props newShardProps(ShardIdentifier shardId, Map<String, String> peers, String memberName,
+ EntityOwnerSelectionStrategyConfig strategyConfig) {
return EntityOwnershipShard.props(shardId, peers, dataStoreContextBuilder.build(),
- SCHEMA_CONTEXT, memberName);
+ SCHEMA_CONTEXT, memberName, strategyConfig);
}
private ShardIdentifier newShardId(String memberName) {
TestEntityOwnershipShard(ShardIdentifier name, Map<String, String> peerAddresses,
DatastoreContext datastoreContext) {
- super(name, peerAddresses, datastoreContext, SCHEMA_CONTEXT, LOCAL_MEMBER_NAME);
+ super(name, peerAddresses, datastoreContext, SCHEMA_CONTEXT, LOCAL_MEMBER_NAME, EntityOwnerSelectionStrategyConfig.newBuilder().build());
}
@Override
@Test
public void testDelayedEntityOwnerSelection() throws Exception {
ShardTestKit kit = new ShardTestKit(getSystem());
- TestActorRef<EntityOwnershipShard> shard = actorFactory.createTestActor(newShardProps());
- shard.underlyingActor().addEntityOwnerSelectionStrategy(ENTITY_TYPE, LastCandidateSelectionStrategy.class, 500);
+ EntityOwnerSelectionStrategyConfig.Builder builder
+ = EntityOwnerSelectionStrategyConfig.newBuilder().addStrategy(ENTITY_TYPE, LastCandidateSelectionStrategy.class, 500);
+ TestActorRef<EntityOwnershipShard> shard = actorFactory.createTestActor(newShardProps(builder.build()));
kit.waitUntilLeader(shard);
Entity entity = new Entity(ENTITY_TYPE, ENTITY_ID1);