use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class ConfigurationImplTest method testRemoveMemberReplicaForShard.
@Test
public void testRemoveMemberReplicaForShard() {
configuration.removeMemberReplicaForShard("default", MEMBER_2);
String shardName = configuration.getShardNameForModule("default");
assertEquals("ModuleShardName", "default", shardName);
ShardStrategy shardStrategy = configuration.getStrategyForModule("default");
assertNull("ModuleStrategy", shardStrategy);
Collection<MemberName> members = configuration.getMembersFromShardName("default");
assertEquals("Members", ImmutableSortedSet.of(MEMBER_1, MEMBER_3), ImmutableSortedSet.copyOf(members));
configuration.removeMemberReplicaForShard("non-existent", MEMBER_2);
Set<String> shardNames = configuration.getAllShardNames();
assertEquals("ShardNames", ImmutableSortedSet.of("people-1", "cars-1", "test-1", "default"), ImmutableSortedSet.copyOf(shardNames));
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class DistributedEntityOwnershipServiceTest method setUp.
@Before
public void setUp() {
DatastoreContext datastoreContext = DatastoreContext.newBuilder().dataStoreName(dataStoreName).shardInitializationTimeout(10, TimeUnit.SECONDS).build();
Configuration configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()) {
@Override
public Collection<MemberName> getUniqueMemberNamesForAllShards() {
return Sets.newHashSet(MemberName.forName("member-1"));
}
};
DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class);
Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
dataStore = new DistributedDataStore(getSystem(), new MockClusterWrapper(), configuration, mockContextFactory, null);
dataStore.onGlobalContextUpdated(SchemaContextHelper.entityOwners());
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class ActorBehaviorTest method setUp.
@Before
public void setUp() throws Exception {
initialBehavior = createInitialBehaviorMock();
system = ActorSystem.apply("system1");
final ActorRef storeRef = system.registerExtension(Persistence.lookup()).snapshotStoreFor(null);
probe = new TestProbe(system);
storeRef.tell(probe.ref(), ActorRef.noSender());
final MemberName name = MemberName.forName("member-1");
id = FrontendIdentifier.create(name, FrontendType.forName("type-1"));
mockedActor = system.actorOf(MockedActor.props(id, initialBehavior));
// handle initial actor recovery
saveRequest = handleRecovery(null);
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class ClusterAdminRpcService method removeAllShardReplicas.
@Override
public Future<RpcResult<RemoveAllShardReplicasOutput>> removeAllShardReplicas(RemoveAllShardReplicasInput input) {
LOG.info("Removing replicas for all shards");
final String memberName = input.getMemberName();
if (Strings.isNullOrEmpty(memberName)) {
return newFailedRpcResultFuture("A valid member name must be specified");
}
final List<Entry<ListenableFuture<Success>, ShardResultBuilder>> shardResultData = new ArrayList<>();
Function<String, Object> messageSupplier = shardName -> new RemoveShardReplica(shardName, MemberName.forName(memberName));
sendMessageToManagerForConfiguredShards(DataStoreType.Config, shardResultData, messageSupplier);
sendMessageToManagerForConfiguredShards(DataStoreType.Operational, shardResultData, messageSupplier);
return waitForShardResults(shardResultData, shardResults -> new RemoveAllShardReplicasOutputBuilder().setShardResult(shardResults).build(), " Failed to remove replica");
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class ShardManagerTest method testPerShardDatastoreContext.
@Test
public void testPerShardDatastoreContext() throws Exception {
LOG.info("testPerShardDatastoreContext starting");
final DatastoreContextFactory mockFactory = newDatastoreContextFactory(datastoreContextBuilder.shardElectionTimeoutFactor(5).build());
Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(6).build()).when(mockFactory).getShardDatastoreContext("default");
Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(7).build()).when(mockFactory).getShardDatastoreContext("topology");
final MockConfiguration mockConfig = new MockConfiguration() {
@Override
public Collection<String> getMemberShardNames(final MemberName memberName) {
return Arrays.asList("default", "topology");
}
@Override
public Collection<MemberName> getMembersFromShardName(final String shardName) {
return members("member-1");
}
};
final ActorRef defaultShardActor = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("default"));
final ActorRef topologyShardActor = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("topology"));
final Map<String, Entry<ActorRef, DatastoreContext>> shardInfoMap = Collections.synchronizedMap(new HashMap<String, Entry<ActorRef, DatastoreContext>>());
shardInfoMap.put("default", new AbstractMap.SimpleEntry<>(defaultShardActor, null));
shardInfoMap.put("topology", new AbstractMap.SimpleEntry<>(topologyShardActor, null));
final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
final CountDownLatch newShardActorLatch = new CountDownLatch(2);
class LocalShardManager extends ShardManager {
LocalShardManager(final AbstractShardManagerCreator<?> creator) {
super(creator);
}
@Override
protected ActorRef newShardActor(final ShardInformation info) {
Entry<ActorRef, DatastoreContext> entry = shardInfoMap.get(info.getShardName());
ActorRef ref = null;
if (entry != null) {
ref = entry.getKey();
entry.setValue(info.getDatastoreContext());
}
newShardActorLatch.countDown();
return ref;
}
}
final Creator<ShardManager> creator = new Creator<ShardManager>() {
private static final long serialVersionUID = 1L;
@Override
public ShardManager create() throws Exception {
return new LocalShardManager(new GenericCreator<>(LocalShardManager.class).datastoreContextFactory(mockFactory).primaryShardInfoCache(primaryShardInfoCache).configuration(mockConfig));
}
};
TestKit kit = new TestKit(getSystem());
final ActorRef shardManager = actorFactory.createActor(Props.create(new DelegatingShardManagerCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), kit.getRef());
assertEquals("Shard actors created", true, newShardActorLatch.await(5, TimeUnit.SECONDS));
assertEquals("getShardElectionTimeoutFactor", 6, shardInfoMap.get("default").getValue().getShardElectionTimeoutFactor());
assertEquals("getShardElectionTimeoutFactor", 7, shardInfoMap.get("topology").getValue().getShardElectionTimeoutFactor());
DatastoreContextFactory newMockFactory = newDatastoreContextFactory(datastoreContextBuilder.shardElectionTimeoutFactor(5).build());
Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(66).build()).when(newMockFactory).getShardDatastoreContext("default");
Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(77).build()).when(newMockFactory).getShardDatastoreContext("topology");
shardManager.tell(newMockFactory, kit.getRef());
DatastoreContext newContext = MessageCollectorActor.expectFirstMatching(defaultShardActor, DatastoreContext.class);
assertEquals("getShardElectionTimeoutFactor", 66, newContext.getShardElectionTimeoutFactor());
newContext = MessageCollectorActor.expectFirstMatching(topologyShardActor, DatastoreContext.class);
assertEquals("getShardElectionTimeoutFactor", 77, newContext.getShardElectionTimeoutFactor());
LOG.info("testPerShardDatastoreContext ending");
}
Aggregations