Search in sources :

Example 26 with MemberName

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

the class ShardedDataTreeActor method memberReachable.

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

Example 27 with MemberName

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

the class EntityOwnershipShard method onLeaderChanged.

@Override
protected void onLeaderChanged(final String oldLeader, final String newLeader) {
    boolean isLeader = isLeader();
    LOG.debug("{}: onLeaderChanged: oldLeader: {}, newLeader: {}, isLeader: {}", persistenceId(), oldLeader, newLeader, isLeader);
    if (isLeader) {
        // Re-initialize the downPeerMemberNames from the current akka Cluster state. The previous leader, if any,
        // is most likely down however it's possible we haven't received the PeerDown message yet.
        initializeDownPeerMemberNamesFromClusterState();
        // Clear all existing strategies so that they get re-created when we call createStrategy again
        // This allows the strategies to be re-initialized with existing statistics maintained by
        // EntityOwnershipStatistics
        strategyConfig.clearStrategies();
        // Re-assign owners for all members that are known to be down. In a cluster which has greater than
        // 3 nodes it is possible for some node beside the leader being down when the leadership transitions
        // it makes sense to use this event to re-assign owners for those downed nodes.
        Set<String> ownedBy = new HashSet<>(downPeerMemberNames.size() + 1);
        for (MemberName downPeerName : downPeerMemberNames) {
            ownedBy.add(downPeerName.getName());
        }
        // Also try to assign owners for entities that have no current owner. See explanation in onPeerUp.
        ownedBy.add("");
        selectNewOwnerForEntitiesOwnedBy(ownedBy);
    } else {
        // The leader changed - notify the coordinator to check if pending modifications need to be sent.
        // While onStateChanged also does this, this method handles the case where the shard hears from a
        // leader and stays in the follower state. In that case no behavior state change occurs.
        commitCoordinator.onStateChanged(this, isLeader);
    }
    super.onLeaderChanged(oldLeader, newLeader);
}
Also used : MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) HashSet(java.util.HashSet)

Example 28 with MemberName

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

the class EntityOwnershipShard method getViableCandidates.

private Collection<String> getViableCandidates(final Collection<String> candidates) {
    Map<MemberName, VotingState> memberToVotingState = new HashMap<>();
    getRaftActorContext().getPeers().forEach(peerInfo -> memberToVotingState.put(ShardIdentifier.fromShardIdString(peerInfo.getId()).getMemberName(), peerInfo.getVotingState()));
    Collection<String> viableCandidates = new ArrayList<>();
    for (String candidate : candidates) {
        MemberName memberName = MemberName.forName(candidate);
        if (memberToVotingState.get(memberName) != VotingState.NON_VOTING && !downPeerMemberNames.contains(memberName)) {
            viableCandidates.add(candidate);
        }
    }
    return viableCandidates;
}
Also used : HashMap(java.util.HashMap) VotingState(org.opendaylight.controller.cluster.raft.VotingState) ArrayList(java.util.ArrayList) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Example 29 with MemberName

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

the class DistributedEntityOwnershipService method start.

public static DistributedEntityOwnershipService start(final ActorContext context, final EntityOwnerSelectionStrategyConfig strategyConfig) {
    ActorRef shardManagerActor = context.getShardManager();
    Configuration configuration = context.getConfiguration();
    Collection<MemberName> entityOwnersMemberNames = configuration.getUniqueMemberNamesForAllShards();
    CreateShard createShard = new CreateShard(new ModuleShardConfiguration(EntityOwners.QNAME.getNamespace(), "entity-owners", ENTITY_OWNERSHIP_SHARD_NAME, ModuleShardStrategy.NAME, entityOwnersMemberNames), newShardBuilder(context, strategyConfig), null);
    Future<Object> createFuture = context.executeOperationAsync(shardManagerActor, createShard, MESSAGE_TIMEOUT);
    createFuture.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.error("Failed to create {} shard", ENTITY_OWNERSHIP_SHARD_NAME, failure);
            } else {
                LOG.info("Successfully created {} shard", ENTITY_OWNERSHIP_SHARD_NAME);
            }
        }
    }, context.getClientDispatcher());
    return new DistributedEntityOwnershipService(context);
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) ActorRef(akka.actor.ActorRef) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)

Example 30 with MemberName

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

the class DistributedEntityOwnershipService method getOwnershipState.

@Override
public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
    Preconditions.checkNotNull(forEntity, "forEntity cannot be null");
    DataTree dataTree = getLocalEntityOwnershipShardDataTree();
    if (dataTree == null) {
        return Optional.absent();
    }
    java.util.Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(entityPath(forEntity.getType(), forEntity.getIdentifier()));
    if (!entityNode.isPresent()) {
        return Optional.absent();
    }
    // Check if there are any candidates, if there are none we do not really have ownership state
    final MapEntryNode entity = (MapEntryNode) entityNode.get();
    final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID);
    final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
    if (!hasCandidates) {
        return Optional.absent();
    }
    MemberName localMemberName = context.getCurrentMemberName();
    java.util.Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID);
    String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null;
    boolean hasOwner = !Strings.isNullOrEmpty(owner);
    boolean isOwner = hasOwner && localMemberName.getName().equals(owner);
    return Optional.of(EntityOwnershipState.from(isOwner, hasOwner));
}
Also used : DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

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