Search in sources :

Example 46 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class ClientMetadataService method groupByServerToBuckets.

/**
   * This function should make a map of server to buckets it is hosting. If for some bucket servers
   * are not available due to mismatch in metadata it should fill up a random server for it.
   */
private HashMap<ServerLocation, HashSet<Integer>> groupByServerToBuckets(ClientPartitionAdvisor prAdvisor, Set<Integer> bucketSet, boolean primaryOnly) {
    if (primaryOnly) {
        HashMap<ServerLocation, HashSet<Integer>> serverToBucketsMap = new HashMap<ServerLocation, HashSet<Integer>>();
        for (Integer bucketId : bucketSet) {
            ServerLocation server = prAdvisor.advisePrimaryServerLocation(bucketId);
            if (server == null) {
                // will cause us to use the non-single hop path.
                return null;
            }
            HashSet<Integer> buckets = serverToBucketsMap.get(server);
            if (buckets == null) {
                // faster if this was an ArrayList
                buckets = new HashSet<Integer>();
                serverToBucketsMap.put(server, buckets);
            }
            buckets.add(bucketId);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("ClientMetadataService: The server to bucket map is : {}", serverToBucketsMap);
        }
        return serverToBucketsMap;
    } else {
        return pruneNodes(prAdvisor, bucketSet);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 47 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class CacheServerLoadMessage method fromData.

@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    super.fromData(in);
    load = new ServerLoad();
    InternalDataSerializer.invokeFromData(load, in);
    location = new ServerLocation();
    InternalDataSerializer.invokeFromData(location, in);
    this.clientIds = DataSerializer.readArrayList(in);
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) ServerLocation(org.apache.geode.distributed.internal.ServerLocation)

Example 48 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class InternalClientMembership method getConnectedServers.

/**
   * Returns a map of servers to count of pools connected to that server. The map entry key is a
   * String representation of the server,
   * 
   * @return map of servers to count of pools using that server
   */
public static Map getConnectedServers() {
    // KEY:server (String), VALUE:List of active endpoints
    final Map map = new HashMap();
    // returns an unmodifiable set
    Map /* <String,Pool> */
    poolMap = PoolManager.getAll();
    Iterator pools = poolMap.values().iterator();
    while (pools.hasNext()) {
        PoolImpl pi = (PoolImpl) pools.next();
        Map /* <ServerLocation,Endpoint> */
        eps = pi.getEndpointMap();
        Iterator it = eps.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            ServerLocation loc = (ServerLocation) entry.getKey();
            org.apache.geode.cache.client.internal.Endpoint ep = (org.apache.geode.cache.client.internal.Endpoint) entry.getValue();
            String server = loc.getHostName() + "[" + loc.getPort() + "]";
            Integer count = (Integer) map.get(server);
            if (count == null) {
                map.put(server, Integer.valueOf(1));
            } else {
                map.put(server, Integer.valueOf(count.intValue() + 1));
            }
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 49 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class CacheServerImpl method start.

@Override
public synchronized void start() throws IOException {
    Assert.assertTrue(this.cache != null);
    this.serialNumber = createSerialNumber();
    if (DynamicRegionFactory.get().isOpen()) {
        // from servers to clients instead of invalidates.
        if (!this.notifyBySubscription) {
            logger.info(LocalizedMessage.create(LocalizedStrings.CacheServerImpl_FORCING_NOTIFYBYSUBSCRIPTION_TO_SUPPORT_DYNAMIC_REGIONS));
            this.notifyBySubscription = true;
        }
    }
    this.advisor = CacheServerAdvisor.createCacheServerAdvisor(this);
    this.loadMonitor = new LoadMonitor(loadProbe, maxConnections, loadPollInterval, FORCE_LOAD_UPDATE_FREQUENCY, advisor);
    List overflowAttributesList = new LinkedList();
    ClientSubscriptionConfig csc = this.getClientSubscriptionConfig();
    overflowAttributesList.add(0, csc.getEvictionPolicy());
    overflowAttributesList.add(1, valueOf(csc.getCapacity()));
    overflowAttributesList.add(2, valueOf(this.port));
    String diskStoreName = csc.getDiskStoreName();
    if (diskStoreName != null) {
        overflowAttributesList.add(3, diskStoreName);
        // indicator to use diskstore
        overflowAttributesList.add(4, true);
    } else {
        overflowAttributesList.add(3, csc.getOverflowDirectory());
        overflowAttributesList.add(4, false);
    }
    this.acceptor = new AcceptorImpl(getPort(), getBindAddress(), getNotifyBySubscription(), getSocketBufferSize(), getMaximumTimeBetweenPings(), this.cache, getMaxConnections(), getMaxThreads(), getMaximumMessageCount(), getMessageTimeToLive(), this.loadMonitor, overflowAttributesList, this.isGatewayReceiver, this.gatewayTransportFilters, this.tcpNoDelay);
    this.acceptor.start();
    this.advisor.handshake();
    this.loadMonitor.start(new ServerLocation(getExternalAddress(), getPort()), acceptor.getStats());
    // TODO : Need to provide facility to enable/disable client health monitoring.
    // Creating ClientHealthMonitoring region.
    // Force initialization on current cache
    ClientHealthMonitoringRegion.getInstance(this.cache);
    this.cache.getLoggerI18n().config(LocalizedStrings.CacheServerImpl_CACHESERVER_CONFIGURATION___0, getConfig());
    /*
     * If the stopped bridge server is restarted, we'll need to re-register the client membership
     * listener. If the listener is already registered it won't be registered as would the case when
     * start() is invoked for the first time.
     */
    ClientMembershipListener[] membershipListeners = ClientMembership.getClientMembershipListeners();
    boolean membershipListenerRegistered = false;
    for (ClientMembershipListener membershipListener : membershipListeners) {
        // just checking by reference as the listener instance is final
        if (listener == membershipListener) {
            membershipListenerRegistered = true;
            break;
        }
    }
    if (!membershipListenerRegistered) {
        ClientMembership.registerClientMembershipListener(listener);
    }
    if (!isGatewayReceiver) {
        InternalDistributedSystem system = this.cache.getInternalDistributedSystem();
        system.handleResourceEvent(ResourceEvent.CACHE_SERVER_START, this);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LoadMonitor(org.apache.geode.cache.server.internal.LoadMonitor) LinkedList(java.util.LinkedList)

Example 50 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class Shipment method verifyMetadata.

public static void verifyMetadata(Map<Integer, List<BucketServerLocation66>> clientMap) {
    final PartitionedRegion pr = (PartitionedRegion) region;
    ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
    assertEquals(clientMap.size(), serverMap.size());
    assertTrue(clientMap.keySet().containsAll(serverMap.keySet()));
    for (Map.Entry<Integer, List<BucketServerLocation66>> entry : clientMap.entrySet()) {
        int bucketId = entry.getKey();
        List<BucketServerLocation66> list = entry.getValue();
        BucketServerLocation66 primaryBSL = null;
        int primaryCnt = 0;
        for (BucketServerLocation66 bsl : list) {
            if (bsl.isPrimary()) {
                primaryBSL = bsl;
                primaryCnt++;
            }
        }
        assertTrue(primaryCnt == 1);
        Set<ServerBucketProfile> set = serverMap.get(bucketId);
        assertEquals(list.size(), set.size());
        primaryCnt = 0;
        for (ServerBucketProfile bp : set) {
            ServerLocation sl = (ServerLocation) bp.bucketServerLocations.toArray()[0];
            assertTrue(list.contains(sl));
            // should be only one primary
            if (bp.isPrimary) {
                primaryCnt++;
                assertTrue(primaryBSL.equals(sl));
            }
        }
        assertTrue(primaryCnt == 1);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

ServerLocation (org.apache.geode.distributed.internal.ServerLocation)95 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 List (java.util.List)18 HashMap (java.util.HashMap)17 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)17 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)13 Map (java.util.Map)12 Iterator (java.util.Iterator)10 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)9 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Set (java.util.Set)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 LinkedHashSet (java.util.LinkedHashSet)7 Host (org.apache.geode.test.dunit.Host)7 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5