use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManagerTest method testServerRemovedShardActorNotRunning.
@Test
public void testServerRemovedShardActorNotRunning() throws Exception {
LOG.info("testServerRemovedShardActorNotRunning starting");
new TestKit(getSystem()) {
{
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).put("people", Arrays.asList("member-1", "member-2")).build());
TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.underlyingActor().waitForRecoveryComplete();
shardManager.tell(new FindLocalShard("people", false), getRef());
expectMsgClass(duration("5 seconds"), NotInitializedException.class);
shardManager.tell(new FindLocalShard("default", false), getRef());
expectMsgClass(duration("5 seconds"), NotInitializedException.class);
// Removed the default shard replica from member-1
ShardIdentifier.Builder builder = new ShardIdentifier.Builder();
ShardIdentifier shardId = builder.shardName("default").memberName(MEMBER_1).type(shardMrgIDSuffix).build();
shardManager.tell(new ServerRemoved(shardId.toString()), getRef());
shardManager.underlyingActor().verifySnapshotPersisted(Sets.newHashSet("people"));
}
};
LOG.info("testServerRemovedShardActorNotRunning ending");
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManager method onActorInitialized.
private void onActorInitialized(final Object message) {
final ActorRef sender = getSender();
if (sender == null) {
// why is a non-actor sending this message? Just ignore.
return;
}
String actorName = sender.path().name();
// find shard name from actor name; actor name is stringified shardId
final ShardIdentifier shardId;
try {
shardId = ShardIdentifier.fromShardIdString(actorName);
} catch (IllegalArgumentException e) {
LOG.debug("{}: ignoring actor {}", actorName, e);
return;
}
markShardAsInitialized(shardId.getShardName());
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManager method doCreateShard.
private void doCreateShard(final CreateShard createShard) {
final ModuleShardConfiguration moduleShardConfig = createShard.getModuleShardConfig();
final String shardName = moduleShardConfig.getShardName();
configuration.addModuleShardConfiguration(moduleShardConfig);
DatastoreContext shardDatastoreContext = createShard.getDatastoreContext();
if (shardDatastoreContext == null) {
shardDatastoreContext = newShardDatastoreContext(shardName);
} else {
shardDatastoreContext = DatastoreContext.newBuilderFrom(shardDatastoreContext).shardPeerAddressResolver(peerAddressResolver).build();
}
ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
boolean shardWasInRecoveredSnapshot = currentSnapshot != null && currentSnapshot.getShardList().contains(shardName);
Map<String, String> peerAddresses;
boolean isActiveMember;
if (shardWasInRecoveredSnapshot || configuration.getMembersFromShardName(shardName).contains(cluster.getCurrentMemberName())) {
peerAddresses = getPeerAddresses(shardName);
isActiveMember = true;
} else {
// The local member is not in the static shard member configuration and the shard did not
// previously exist (ie !shardWasInRecoveredSnapshot). In this case we'll create
// the shard with no peers and with elections disabled so it stays as follower. A
// subsequent AddServer request will be needed to make it an active member.
isActiveMember = false;
peerAddresses = Collections.emptyMap();
shardDatastoreContext = DatastoreContext.newBuilderFrom(shardDatastoreContext).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName()).build();
}
LOG.debug("{} doCreateShard: shardId: {}, memberNames: {}, peerAddresses: {}, isActiveMember: {}", persistenceId(), shardId, moduleShardConfig.getShardMemberNames(), peerAddresses, isActiveMember);
ShardInformation info = new ShardInformation(shardName, shardId, peerAddresses, shardDatastoreContext, createShard.getShardBuilder(), peerAddressResolver);
info.setActiveMember(isActiveMember);
localShards.put(info.getShardName(), info);
if (schemaContext != null) {
info.setSchemaContext(schemaContext);
info.setActor(newShardActor(info));
}
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier 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);
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManager method getPeerAddresses.
private Map<String, String> getPeerAddresses(final String shardName, final Collection<MemberName> members) {
Map<String, String> peerAddresses = new HashMap<>();
MemberName currentMemberName = this.cluster.getCurrentMemberName();
for (MemberName memberName : members) {
if (!currentMemberName.equals(memberName)) {
ShardIdentifier shardId = getShardIdentifier(memberName, shardName);
String address = peerAddressResolver.getShardActorAddress(shardName, memberName);
peerAddresses.put(shardId.toString(), address);
}
}
return peerAddresses;
}
Aggregations