use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.
the class ShardManager method doCreatePrefixShard.
private void doCreatePrefixShard(final PrefixShardConfiguration config, final ShardIdentifier shardId, final String shardName) {
configuration.addPrefixShardConfiguration(config);
final Builder builder = newShardDatastoreContextBuilder(shardName);
builder.logicalStoreType(config.getPrefix().getDatastoreType()).storeRoot(config.getPrefix().getRootIdentifier());
DatastoreContext shardDatastoreContext = builder.build();
final Map<String, String> peerAddresses = getPeerAddresses(shardName);
final boolean isActiveMember = true;
LOG.debug("{} doCreatePrefixShard: shardId: {}, memberNames: {}, peerAddresses: {}, isActiveMember: {}", persistenceId(), shardId, config.getShardMemberNames(), peerAddresses, isActiveMember);
final ShardInformation info = new ShardInformation(shardName, shardId, peerAddresses, shardDatastoreContext, Shard.builder(), 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.DatastoreContext in project controller by opendaylight.
the class ShardManager method changeShardMembersVotingStatus.
private void changeShardMembersVotingStatus(final ChangeServersVotingStatus changeServersVotingStatus, final String shardName, final ActorRef shardActorRef, final ActorRef sender) {
if (isShardReplicaOperationInProgress(shardName, sender)) {
return;
}
shardReplicaOperationsInProgress.add(shardName);
DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
LOG.debug("{}: Sending ChangeServersVotingStatus message {} to local shard {}", persistenceId(), changeServersVotingStatus, shardActorRef.path());
Timeout timeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration().$times(2));
Future<Object> futureObj = ask(shardActorRef, changeServersVotingStatus, timeout);
futureObj.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
shardReplicaOperationsInProgress.remove(shardName);
if (failure != null) {
String msg = String.format("ChangeServersVotingStatus request to local shard %s failed", shardActorRef.path());
LOG.debug("{}: {}", persistenceId(), msg, failure);
sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
} else {
LOG.debug("{}: Received {} from local shard {}", persistenceId(), response, shardActorRef.path());
ServerChangeReply replyMsg = (ServerChangeReply) response;
if (replyMsg.getStatus() == ServerChangeStatus.OK) {
LOG.debug("{}: ChangeServersVotingStatus succeeded for shard {}", persistenceId(), shardName);
sender.tell(new Status.Success(null), getSelf());
} else if (replyMsg.getStatus() == ServerChangeStatus.INVALID_REQUEST) {
sender.tell(new Status.Failure(new IllegalArgumentException(String.format("The requested voting state change for shard %s is invalid. At least one member " + "must be voting", shardId.getShardName()))), getSelf());
} else {
LOG.warn("{}: ChangeServersVotingStatus failed for shard {} with status {}", persistenceId(), shardName, replyMsg.getStatus());
Exception error = getServerChangeException(ChangeServersVotingStatus.class, replyMsg.getStatus(), shardActorRef.path().toString(), shardId);
sender.tell(new Status.Failure(error), getSelf());
}
}
}
}, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.
the class ShardManager method removePrefixShardReplica.
private void removePrefixShardReplica(final RemovePrefixShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
if (isShardReplicaOperationInProgress(shardName, sender)) {
return;
}
shardReplicaOperationsInProgress.add(shardName);
final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
// inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
futureObj.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
shardReplicaOperationsInProgress.remove(shardName);
String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
LOG.debug("{}: {}", persistenceId(), msg, failure);
// FAILURE
sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
} else {
// SUCCESS
self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
}
}
}, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.
the class ShardManager method addShard.
private void addShard(final String shardName, 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);
DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName()).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.DatastoreContext in project controller by opendaylight.
the class ShardManager method removeShardReplica.
private void removeShardReplica(final RemoveShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
if (isShardReplicaOperationInProgress(shardName, sender)) {
return;
}
shardReplicaOperationsInProgress.add(shardName);
final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
// inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
futureObj.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
shardReplicaOperationsInProgress.remove(shardName);
String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
LOG.debug("{}: {}", persistenceId(), msg, failure);
// FAILURE
sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
} else {
// SUCCESS
self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
}
}
}, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Aggregations