Search in sources :

Example 1 with DatastoreContext

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));
    }
}
Also used : DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder)

Example 2 with DatastoreContext

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));
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) SaveSnapshotSuccess(akka.persistence.SaveSnapshotSuccess) DeleteSnapshotsSuccess(akka.persistence.DeleteSnapshotsSuccess) AlreadyExistsException(org.opendaylight.controller.cluster.datastore.exceptions.AlreadyExistsException) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TimeoutException(java.util.concurrent.TimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) ServerChangeReply(org.opendaylight.controller.cluster.raft.messages.ServerChangeReply) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 3 with DatastoreContext

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));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 4 with DatastoreContext

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);
}
Also used : DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)

Example 5 with DatastoreContext

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));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Aggregations

DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)15 Timeout (akka.util.Timeout)6 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)6 ActorRef (akka.actor.ActorRef)5 TestActorRef (akka.testkit.TestActorRef)5 Test (org.junit.Test)5 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)5 ClusterWrapper (org.opendaylight.controller.cluster.datastore.ClusterWrapper)4 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)3 TestKit (akka.testkit.javadsl.TestKit)3 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)3 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)3 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)3 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)3 Before (org.junit.Before)2 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 Builder (org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder)2 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)2