use of org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration in project controller by opendaylight.
the class ShardedDataTreeActor method onPrefixShardCreated.
private void onPrefixShardCreated(final PrefixShardCreated message) {
LOG.debug("Member: {}, Received PrefixShardCreated: {}", clusterWrapper.getCurrentMemberName(), message);
final PrefixShardConfiguration config = message.getConfiguration();
shardingService.resolveShardAdditions(Collections.singleton(config.getPrefix()));
}
use of org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testAddRemovePrefixShardReplica.
@Test
public void testAddRemovePrefixShardReplica() throws Exception {
String name = "testAddPrefixShardReplica";
String moduleShardsConfig = "module-shards-default.conf";
final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
member1.waitForMembersUp("member-2", "member-3");
replicaNode2.kit().waitForMembersUp("member-1", "member-3");
replicaNode3.kit().waitForMembersUp("member-1", "member-2");
final ActorRef shardManager1 = member1.configDataStore().getActorContext().getShardManager();
shardManager1.tell(new PrefixShardCreated(new PrefixShardConfiguration(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH), "prefix", Collections.singleton(MEMBER_1))), ActorRef.noSender());
member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
final InstanceIdentifier<Cars> identifier = InstanceIdentifier.create(Cars.class);
final BindingNormalizedNodeSerializer serializer = Mockito.mock(BindingNormalizedNodeSerializer.class);
Mockito.doReturn(CarsModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(identifier);
addPrefixShardReplica(replicaNode2, identifier, serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1");
addPrefixShardReplica(replicaNode3, identifier, serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1", "member-2");
verifyRaftPeersPresent(member1.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-2", "member-3");
removePrefixShardReplica(member1, identifier, "member-3", serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-2");
verifyNoShardPresent(replicaNode3.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
verifyRaftPeersPresent(replicaNode2.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1");
removePrefixShardReplica(member1, identifier, "member-2", serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
verifyNoShardPresent(replicaNode2.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
}
use of org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testGetShardRole.
@Test
public void testGetShardRole() throws Exception {
String name = "testGetShardRole";
String moduleShardsConfig = "module-shards-default-member-1.conf";
final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).build();
member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), "default");
final RpcResult<GetShardRoleOutput> successResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "default");
verifySuccessfulRpcResult(successResult);
assertEquals("Leader", successResult.getResult().getRole());
final RpcResult<GetShardRoleOutput> failedResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "cars");
verifyFailedRpcResult(failedResult);
final ActorRef shardManager1 = member1.configDataStore().getActorContext().getShardManager();
shardManager1.tell(new PrefixShardCreated(new PrefixShardConfiguration(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH), "prefix", Collections.singleton(MEMBER_1))), ActorRef.noSender());
member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
final InstanceIdentifier<Cars> identifier = InstanceIdentifier.create(Cars.class);
final BindingNormalizedNodeSerializer serializer = Mockito.mock(BindingNormalizedNodeSerializer.class);
Mockito.doReturn(CarsModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(identifier);
final RpcResult<GetPrefixShardRoleOutput> prefixSuccessResult = getPrefixShardRole(member1, identifier, serializer);
verifySuccessfulRpcResult(prefixSuccessResult);
assertEquals("Leader", prefixSuccessResult.getResult().getRole());
final InstanceIdentifier<People> peopleId = InstanceIdentifier.create(People.class);
Mockito.doReturn(PeopleModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(peopleId);
final RpcResult<GetPrefixShardRoleOutput> prefixFail = getPrefixShardRole(member1, peopleId, serializer);
verifyFailedRpcResult(prefixFail);
}
use of org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration in project controller by opendaylight.
the class ShardManager method onPrefixShardCreated.
private void onPrefixShardCreated(final PrefixShardCreated message) {
LOG.debug("{}: onPrefixShardCreated: {}", persistenceId(), message);
final PrefixShardConfiguration config = message.getConfiguration();
final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), ClusterUtils.getCleanShardName(config.getPrefix().getRootIdentifier()));
final String shardName = shardId.getShardName();
if (isPreviousShardActorStopInProgress(shardName, message)) {
return;
}
if (localShards.containsKey(shardName)) {
LOG.debug("{}: Received create for an already existing shard {}", persistenceId(), shardName);
final PrefixShardConfiguration existing = configuration.getAllPrefixShardConfigurations().get(config.getPrefix());
if (existing != null && existing.equals(config)) {
// we don't have to do nothing here
return;
}
}
doCreatePrefixShard(config, shardId, shardName);
}
Aggregations