Search in sources :

Example 16 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManager method memberReachable.

private void memberReachable(final ClusterEvent.ReachableMember message) {
    MemberName memberName = memberToName(message.member());
    LOG.info("Received ReachableMember: memberName {}, address: {}", memberName, message.member().address());
    addPeerAddress(memberName, message.member().address());
    markMemberAvailable(memberName);
}
Also used : MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Example 17 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName 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));
    }
}
Also used : HashMap(java.util.HashMap) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot)

Example 18 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManager method memberUnreachable.

private void memberUnreachable(final ClusterEvent.UnreachableMember message) {
    MemberName memberName = memberToName(message.member());
    LOG.info("Received UnreachableMember: memberName {}, address: {}", memberName, message.member().address());
    markMemberUnavailable(memberName);
}
Also used : MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Example 19 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManager method updateSchemaContext.

/**
 * Notifies all the local shards of a change in the schema context.
 *
 * @param message the message to send
 */
private void updateSchemaContext(final Object message) {
    schemaContext = ((UpdateSchemaContext) message).getSchemaContext();
    LOG.debug("Got updated SchemaContext: # of modules {}", schemaContext.getModules().size());
    for (ShardInformation info : localShards.values()) {
        info.setSchemaContext(schemaContext);
        if (info.getActor() == null) {
            LOG.debug("Creating Shard {}", info.getShardId());
            info.setActor(newShardActor(info));
            // Update peer address for every existing peer memeber to avoid missing sending
            // PeerAddressResolved and PeerUp to this shard while UpdateSchemaContext comes after MemberUp.
            String shardName = info.getShardName();
            for (MemberName memberName : peerAddressResolver.getPeerMembers()) {
                String peerId = getShardIdentifier(memberName, shardName).toString();
                String peerAddress = peerAddressResolver.getShardActorAddress(shardName, memberName);
                info.updatePeerAddress(peerId, peerAddress, getSelf());
                info.peerUp(memberName, peerId, getSelf());
                LOG.debug("{}: updated peer {} on member {} with address {} on shard {} whose actor address is {}", persistenceId(), peerId, memberName, peerAddress, info.getShardId(), info.getActor());
            }
        } else {
            info.getActor().tell(message, getSelf());
        }
    }
}
Also used : MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Example 20 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManager method applyShardManagerSnapshot.

private void applyShardManagerSnapshot(final ShardManagerSnapshot snapshot) {
    currentSnapshot = snapshot;
    LOG.debug("{}: onSnapshotOffer: {}", persistenceId(), currentSnapshot);
    final MemberName currentMember = cluster.getCurrentMemberName();
    Set<String> configuredShardList = new HashSet<>(configuration.getMemberShardNames(currentMember));
    for (String shard : currentSnapshot.getShardList()) {
        if (!configuredShardList.contains(shard)) {
            // add the current member as a replica for the shard
            LOG.debug("{}: adding shard {}", persistenceId(), shard);
            configuration.addMemberReplicaForShard(shard, currentMember);
        } else {
            configuredShardList.remove(shard);
        }
    }
    for (String shard : configuredShardList) {
        // remove the member as a replica for the shard
        LOG.debug("{}: removing shard {}", persistenceId(), shard);
        configuration.removeMemberReplicaForShard(shard, currentMember);
    }
}
Also used : MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) HashSet(java.util.HashSet)

Aggregations

MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)32 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 ActorRef (akka.actor.ActorRef)4 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)3 AddressFromURIString (akka.actor.AddressFromURIString)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 Before (org.junit.Before)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)2 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)2 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)2 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)2 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)2 ModuleShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy)2 ShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy)2 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)2 Address (akka.actor.Address)1