use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManager method onSwitchShardBehavior.
private void onSwitchShardBehavior(final SwitchShardBehavior message) {
final ShardIdentifier identifier = message.getShardId();
if (identifier != null) {
final ShardInformation info = localShards.get(identifier.getShardName());
if (info == null) {
getSender().tell(new Status.Failure(new IllegalArgumentException("Shard " + identifier + " is not local")), getSelf());
return;
}
switchShardBehavior(info, new SwitchBehavior(message.getNewState(), message.getTerm()));
} else {
for (ShardInformation info : localShards.values()) {
switchShardBehavior(info, new SwitchBehavior(message.getNewState(), message.getTerm()));
}
}
getSender().tell(new Status.Success(null), getSelf());
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManager method onAddPrefixShardReplica.
private void onAddPrefixShardReplica(final AddPrefixShardReplica message) {
LOG.debug("{}: onAddPrefixShardReplica: {}", persistenceId(), message);
final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), ClusterUtils.getCleanShardName(message.getShardPrefix()));
final String shardName = shardId.getShardName();
// Create the localShard
if (schemaContext == null) {
String msg = String.format("No SchemaContext is available in order to create a local shard instance for %s", shardName);
LOG.debug("{}: {}", persistenceId(), msg);
getSender().tell(new Status.Failure(new IllegalStateException(msg)), getSelf());
return;
}
findPrimary(shardName, new AutoFindPrimaryFailureResponseHandler(getSender(), shardName, persistenceId(), getSelf()) {
@Override
public void onRemotePrimaryShardFound(final RemotePrimaryShardFound response) {
final RunnableMessage runnable = (RunnableMessage) () -> addPrefixShard(getShardName(), message.getShardPrefix(), response, getSender());
if (!isPreviousShardActorStopInProgress(getShardName(), runnable)) {
getSelf().tell(runnable, getTargetActor());
}
}
@Override
public void onLocalPrimaryFound(final LocalPrimaryShardFound message) {
sendLocalReplicaAlreadyExistsReply(getShardName(), getTargetActor());
}
});
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManager method addPrefixShard.
private void addPrefixShard(final String shardName, final YangInstanceIdentifier shardPrefix, final RemotePrimaryShardFound response, final ActorRef sender) {
if (isShardReplicaOperationInProgress(shardName, sender)) {
return;
}
shardReplicaOperationsInProgress.add(shardName);
final ShardInformation shardInfo;
final boolean removeShardOnFailure;
ShardInformation existingShardInfo = localShards.get(shardName);
if (existingShardInfo == null) {
removeShardOnFailure = true;
ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
final Builder builder = newShardDatastoreContextBuilder(shardName);
builder.storeRoot(shardPrefix).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
DatastoreContext datastoreContext = builder.build();
shardInfo = new ShardInformation(shardName, shardId, getPeerAddresses(shardName), datastoreContext, Shard.builder(), peerAddressResolver);
shardInfo.setActiveMember(false);
shardInfo.setSchemaContext(schemaContext);
localShards.put(shardName, shardInfo);
shardInfo.setActor(newShardActor(shardInfo));
} else {
removeShardOnFailure = false;
shardInfo = existingShardInfo;
}
execAddShard(shardName, shardInfo, response, removeShardOnFailure, sender);
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManager method createLocalShards.
/**
* Create shards that are local to the member on which the ShardManager runs.
*/
private void createLocalShards() {
MemberName memberName = this.cluster.getCurrentMemberName();
Collection<String> memberShardNames = this.configuration.getMemberShardNames(memberName);
Map<String, DatastoreSnapshot.ShardSnapshot> shardSnapshots = new HashMap<>();
if (restoreFromSnapshot != null) {
for (DatastoreSnapshot.ShardSnapshot snapshot : restoreFromSnapshot.getShardSnapshots()) {
shardSnapshots.put(snapshot.getName(), snapshot);
}
}
// null out to GC
restoreFromSnapshot = null;
for (String shardName : memberShardNames) {
ShardIdentifier shardId = getShardIdentifier(memberName, shardName);
LOG.debug("{}: Creating local shard: {}", persistenceId(), shardId);
Map<String, String> peerAddresses = getPeerAddresses(shardName);
localShards.put(shardName, new ShardInformation(shardName, shardId, peerAddresses, newShardDatastoreContext(shardName), Shard.builder().restoreFromSnapshot(shardSnapshots.get(shardName)), peerAddressResolver));
}
}
use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.
the class ShardManagerInfo method switchShardState.
@Override
public void switchShardState(final String shardId, final String newState, final long term) {
final ShardIdentifier identifier = ShardIdentifier.fromShardIdString(shardId);
LOG.info("switchShardState called shardName = {}, newState = {}, term = {}", shardId, newState, term);
requestSwitchShardState(identifier, newState, term);
}
Aggregations