Search in sources :

Example 1 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class AdminDistributedSystemImpl method removeSystemMember.

/**
   * Removes a SystemMember from this system's list of known members. This method is called in
   * response to a member leaving the system. TODO: this method is a mess of defns
   *
   * @param internalId the unique id that specifies which member to remove
   * @return the system member that was removed; null if no match was found
   */
protected SystemMember removeSystemMember(InternalDistributedMember internalId) {
    if (internalId == null)
        return null;
    // this.logger.info("DEBUG: removeSystemMember: " + internalId, new RuntimeException("STACK"));
    boolean found = false;
    SystemMemberImpl member = null;
    synchronized (this.cacheServerSet) {
        SERVERS: for (Iterator iter = this.cacheServerSet.iterator(); iter.hasNext() && !found; ) {
            Future future = (Future) iter.next();
            if (future instanceof AdminFutureTask) {
                AdminFutureTask task = (AdminFutureTask) future;
                if (task.getMemberId().equals(internalId)) {
                    // this.logger.info("DEBUG: removeSystemMember cs cancelling: " + future);
                    future.cancel(true);
                } else {
                    // This is not the member we are looking for...
                    continue SERVERS;
                }
            }
            for (; ; ) {
                checkCancellation();
                boolean interrupted = Thread.interrupted();
                try {
                    member = (SystemMemberImpl) future.get();
                    // success
                    break;
                } catch (InterruptedException ex) {
                    interrupted = true;
                    // keep trying
                    continue;
                } catch (CancellationException ex) {
                    continue SERVERS;
                } catch (ExecutionException ex) {
                    handle(ex);
                    // Dead code
                    return null;
                } finally {
                    if (interrupted) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
            InternalDistributedMember cacheServerId = member.getInternalId();
            if (internalId.equals(cacheServerId)) {
                // found a match...
                iter.remove();
                found = true;
            }
        }
    // SERVERS
    }
    synchronized (this.applicationSet) {
        for (Iterator iter = this.applicationSet.iterator(); iter.hasNext() && !found; ) {
            Future future = (Future) iter.next();
            try {
                if (future instanceof AdminFutureTask) {
                    AdminFutureTask task = (AdminFutureTask) future;
                    if (task.getMemberId().equals(internalId)) {
                        // Only remove applications
                        iter.remove();
                        found = true;
                        if (future.isDone()) {
                            member = (SystemMemberImpl) future.get();
                        }
                        break;
                    } else {
                        // This is not the member we are looking for...
                        continue;
                    }
                }
                if (future.isDone()) {
                    member = (SystemMemberImpl) future.get();
                } else {
                    // this.logger.info("DEBUG: removeSystemMember as cancelling: " + future);
                    future.cancel(true);
                }
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
                checkCancellation();
                throw new RuntimeException(LocalizedStrings.AdminDistributedSystemImpl_INTERRUPTED.toLocalizedString(), ex);
            } catch (CancellationException ex) {
                continue;
            } catch (ExecutionException ex) {
                handle(ex);
                // Dead code
                return null;
            }
            InternalDistributedMember applicationId = member.getInternalId();
            if (internalId.equals(applicationId)) {
                // found a match...
                // Only remove applications
                iter.remove();
                found = true;
            }
        }
    }
    if (found) {
        try {
            if (member != null) {
                member.setGemFireVM(null);
            }
        } catch (AdminException ex) {
            logger.fatal(LocalizedMessage.create(LocalizedStrings.AdminDistributedSystem_UNEXPECTED_ADMINEXCEPTION), ex);
        }
        return member;
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Couldn't remove member {}", internalId);
        }
        return null;
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember)

Example 2 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class AdminDistributedSystemImpl method isSame.

/**
   * Returns whether or not a <code>SystemMember</code> corresponds to a <code>GemFireVM</code>.
   *
   * @param examineConfig Should we take the configuration of the member into consideration? In
   *        general, we want to consider the configuration when a member starts up. But when we are
   *        notified that it has shut down, we do not want to examine the configuration because that
   *        might involve contacting the member. Which, of course, cannot be done because it has
   *        shut down.
   */
private boolean isSame(SystemMemberImpl member, GemFireVM vm, boolean examineConfig) {
    if (vm.equals(member.getGemFireVM())) {
        return true;
    }
    InternalDistributedMember memberId = member.getInternalId();
    InternalDistributedMember vmId = vm.getId();
    if (vmId.equals(memberId)) {
        return true;
    }
    if ((member instanceof ManagedSystemMemberImpl) && examineConfig) {
        // We can't compare information about managers because the
        // member might have already gone away. Attempts to send it
        // messages (to get its product directory, for instance) will
        // time out.
        ManagedSystemMemberImpl entity = (ManagedSystemMemberImpl) member;
        // type of the internal admin object.
        if (entity instanceof CacheServer) {
            if (!(vm instanceof ApplicationVM)) {
                return false;
            }
            ApplicationVM app = (ApplicationVM) vm;
            if (!app.isDedicatedCacheServer()) {
                return false;
            }
        }
        ManagedEntityConfig conf = entity.getEntityConfig();
        InetAddress managedHost = InetAddressUtil.toInetAddress(conf.getHost());
        File managedWorkingDir = new File(conf.getWorkingDirectory());
        File managedProdDir = new File(conf.getProductDirectory());
        InetAddress vmHost = vm.getHost();
        File vmWorkingDir = vm.getWorkingDirectory();
        File vmProdDir = vm.getGeodeHomeDir();
        if (vmHost.equals(managedHost) && isSameFile(vmWorkingDir, managedWorkingDir) && isSameFile(vmProdDir, managedProdDir)) {
            return true;
        }
    }
    return false;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InetAddress(java.net.InetAddress) File(java.io.File)

Example 3 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class GemFireMemberStatus method initializePeers.

protected void initializePeers(DistributedSystem distributedSystem) {
    InternalDistributedSystem ids = (InternalDistributedSystem) distributedSystem;
    DM dm = ids.getDistributionManager();
    Set connections = dm.getOtherNormalDistributionManagerIds();
    Set connectionsIDs = new HashSet(connections.size());
    for (Iterator iter = connections.iterator(); iter.hasNext(); ) {
        InternalDistributedMember idm = (InternalDistributedMember) iter.next();
        connectionsIDs.add(idm.getId());
    }
    setConnectedPeers(connectionsIDs);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) DM(org.apache.geode.distributed.internal.DM) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) HashSet(java.util.HashSet)

Example 4 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class DistributionManager method getRoleCount.

/** Returns count of members filling the specified role */
public int getRoleCount(Role role) {
    int count = 0;
    Set mbrs = getDistributionManagerIds();
    for (Iterator mbrIter = mbrs.iterator(); mbrIter.hasNext(); ) {
        Set roles = ((InternalDistributedMember) mbrIter.next()).getRoles();
        for (Iterator rolesIter = roles.iterator(); rolesIter.hasNext(); ) {
            Role mbrRole = (Role) rolesIter.next();
            if (mbrRole.equals(role)) {
                count++;
                break;
            }
        }
    }
    return count;
}
Also used : Role(org.apache.geode.distributed.Role) Set(java.util.Set) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator)

Example 5 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class DistributionManager method getMembersInSameZone.

public Set<InternalDistributedMember> getMembersInSameZone(InternalDistributedMember targetMember) {
    Set<InternalDistributedMember> buddyMembers = new HashSet<InternalDistributedMember>();
    if (!redundancyZones.isEmpty()) {
        synchronized (redundancyZones) {
            String targetZone = redundancyZones.get(targetMember);
            for (Map.Entry<InternalDistributedMember, String> entry : redundancyZones.entrySet()) {
                if (entry.getValue().equals(targetZone)) {
                    buddyMembers.add(entry.getKey());
                }
            }
        }
    } else {
        buddyMembers.add(targetMember);
        Set targetAddrs = getEquivalents(targetMember.getInetAddress());
        for (Iterator i = getDistributionManagerIds().iterator(); i.hasNext(); ) {
            InternalDistributedMember o = (InternalDistributedMember) i.next();
            if (SetUtils.intersectsWith(targetAddrs, getEquivalents(o.getInetAddress()))) {
                buddyMembers.add(o);
            }
        }
    }
    return buddyMembers;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet)

Aggregations

InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)516 Test (org.junit.Test)162 HashSet (java.util.HashSet)124 Set (java.util.Set)77 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)63 NetView (org.apache.geode.distributed.internal.membership.NetView)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)56 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 ArrayList (java.util.ArrayList)54 DistributedMember (org.apache.geode.distributed.DistributedMember)49 UnitTest (org.apache.geode.test.junit.categories.UnitTest)49 HashMap (java.util.HashMap)46 IOException (java.io.IOException)36 Iterator (java.util.Iterator)34 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)32 Map (java.util.Map)29 CancelException (org.apache.geode.CancelException)29 DM (org.apache.geode.distributed.internal.DM)29